REGRESSION MODELLING FOR HEALTH PRACTITIONERS · CHAPTER 10
Regularisation and Variable Selection
Why regularise?
In regression modelling, including too many predictors can lead to overfitting, inflated variance and poor generalisation. Conversely, omitting important variables can bias estimates. Variable selection aims to find a parsimonious model that balances bias and variance. Classical approaches such as stepwise selection use p–values or information criteria (AIC/BIC) to add or remove variables. Information criteria penalise model complexity: AIC balances goodness of fit and complexity, while BIC imposes a stronger penalty and is more conservative. Cross–validation evaluates out–of–sample predictive performance and is widely used in machine learning. However, stepwise selection can produce unstable models. Regularisation methods such as ridge and lasso regression shrink coefficients towards zero to prevent overfitting and perform automatic variable selection.
Ridge regression
Ridge regression adds an penalty to the least–squares criterion, minimising where controls the amount of shrinkage. Ridge regression does not set coefficients exactly to zero but can improve prediction when predictors are highly correlated.
Lasso and elastic net
The lasso adds an penalty: The penalty encourages sparsity: coefficients can be exactly zero, performing variable selection. The elastic net combines and penalties and is useful when predictors are highly correlated. Selecting the penalty parameter (and mixing parameter for elastic net) is typically done via cross–validation.
Information criteria and cross–validation
The Akaike information criterion (AIC) is defined as , where is the number of parameters and the maximised likelihood. Lower AIC indicates a better trade–off between fit and complexity. The Bayesian information criterion (BIC) uses and penalises large models more strongly. Cross–validation partitions the data into training and validation sets, fits the model on the training data and evaluates predictive error on the validation set. –fold cross–validation repeats this process across partitions and averages the error. Model selection should consider the study goal: prediction vs inference. Penalised methods typically prioritise prediction, whereas AIC/BIC may be preferred for inferential models.
Worked example: lasso for predicting body mass index
Assume a dataset with 20 lifestyle and demographic predictors of body mass index (BMI) among adults. We apply lasso regression to select a subset of predictors.
Worked example
R (glmnet)
library(glmnet)
# X: matrix of predictors, y: vector of BMI
set.seed(123)
cv_fit <- cv.glmnet(X, y, alpha = 1) # alpha=1 for lasso
best_lambda <- cv_fit$lambda.min
lasso_fit <- glmnet(X, y, alpha = 1, lambda = best_lambda)
coef(lasso_fit)
Python (scikit-learn)
from sklearn.linear_model import LassoCV
lasso_cv = LassoCV(cv=10).fit(X, y)
print("Best alpha:", lasso_cv.alpha_)
print("Coefficients:", lasso_cv.coef_)
Julia
using GLMNet
cv = glmnetcv(X, y, alpha = 1) # cross-validated lasso
best_lambda = cv.lambda_min
fit_lasso = glmnet(X, y, alpha = 1, lambda = best_lambda)
coef(fit_lasso)
Coefficients shrunk exactly to zero are predictors that contribute little to explaining BMI given the others. Compare the lasso model with a full multiple regression in terms of predictive accuracy (e.g., via cross–validation) and interpretability.
Interpretation
Penalty selection. Use cross–validation to choose the penalty parameter. A stronger penalty yields sparser models but may increase bias.
Interpretability vs prediction. Penalised models may sacrifice interpretability for predictive performance. Choose the approach appropriate for your study aims.
Information criteria. When models are nested, AIC and BIC provide quick comparisons. BIC favours simpler models and may be more appropriate for causal inference.
Caveats. Regularisation does not correct for confounding; include known confounders regardless of their statistical significance.
Exercises
Exercises
Simulate a dataset with 10 predictors, only 3 of which truly affect the outcome. Fit a lasso model using cross–validation and identify the selected predictors. Compare with stepwise selection based on AIC.
Implement ridge regression on the same dataset and compare coefficient shrinkage with lasso. Discuss scenarios where ridge is preferable.
For a real dataset with many correlated predictors (e.g., gene expression data), apply elastic net regression and tune both the mixing parameter and penalty via cross–validation.
Read about AIC and BIC. Using the Poisson example in Chapter 6, compare models with and without interaction terms via AIC and BIC. Which model is preferred?
Code examples use illustrative datasets. Supply data with the named columns to run them.