Book contents

REGRESSION MODELLING FOR HEALTH PRACTITIONERS · CHAPTER 3

Multiple Linear Regression

When more than one predictor influences a continuous outcome,multiple linear regression is used. This chapter extends the simple linear regression model to accommodate several predictors, discusses model interpretation and variable selection, and demonstrates how to fit multivariable models using R, Python and Julia.

Model Specification

In multiple linear regression, the outcome yy is expressed as a linear combination of pp predictors x1,…,xpx_1,\dots,x_p plus an error term:

yi=β0+β1xi1+β2xi2+…+βpxip+εi,i=1,…,n.y_i = \beta_0 + \beta_1 x_{i1} + \beta_2 x_{i2} + \dots + \beta_p x_{ip} + \varepsilon_i,\quad i=1,\dots,n.

The coefficients βj\beta_j represent the expected change in yy for a one–unit increase in xjx_j while holding all other predictors constant. This allows researchers to distinguish the effects of different variables on the outcome. Fitting the model by least squares produces estimates β̂0,…,β̂p\hat{\beta}_0,\dots,\hat{\beta}_p and an estimated variance σ̂2\hat{\sigma}^2.

Interactions and Nonlinear Terms

Sometimes the effect of one predictor depends on the value of another. An interaction term between xjx_j and xkx_k adds a product βjkxjxk\beta_{jk}\,x_j x_k to the model. Nonlinear relationships can be modelled by including polynomial terms (e.g., x2x^2) or spline functions—see Chapter [chap:smoothing_and_gam] for details.

Worked Example: Blood Pressure with Multiple Predictors

Consider an extension of the weight–blood pressure example from Chapter [chap:02_simple_linear_regression]. Suppose we collect additional predictors: age (years) and sex (0 = female, 1 = male). Our model becomes

SBP=β0+β1weight+β2age+β3sex+ε.\text{SBP} = \beta_0 + \beta_1\,\text{weight} + \beta_2\,\text{age} + \beta_3\,\text{sex} + \varepsilon.

R
# Example dataset (expand as needed)
df <- data.frame(
  weight = c(60,65,68,70,72,75,78,80,82,85),
  age    = c(45,48,50,52,54,57,60,62,64,66),
  sex    = c(0,1,0,1,0,1,0,1,0,1),
  sbp    = c(120,122,124,125,127,130,132,135,137,140)
)

# Fit multiple regression
model <- lm(sbp ~ weight + age + sex, data = df)
summary(model)

# Interpret coefficients: exponentiate if needed
Python
import pandas as pd
import statsmodels.formula.api as smf

df = pd.DataFrame({
    'weight': [60,65,68,70,72,75,78,80,82,85],
    'age':    [45,48,50,52,54,57,60,62,64,66],
    'sex':    [0,1,0,1,0,1,0,1,0,1],
    'sbp':    [120,122,124,125,127,130,132,135,137,140]
})

model = smf.ols('sbp ~ weight + age + sex', data=df).fit()
print(model.summary())
Julia
using DataFrames, GLM

df = DataFrame(weight=[60,65,68,70,72,75,78,80,82,85],
               age=[45,48,50,52,54,57,60,62,64,66],
               sex=[0,1,0,1,0,1,0,1,0,1],
               sbp=[120,122,124,125,127,130,132,135,137,140])

model = lm(@formula(sbp ~ weight + age + sex), df)
coeftable(model)

The regression output includes estimates and standard errors for each coefficient. For example, a positive coefficient for sex suggests that males have higher blood pressure on average than females when weight and age are held constant.

Model Building and Variable Selection

Choosing which variables to include in a regression model is a common challenge. The goal may be to understand causal relationships, in which case variables are selected based on prior knowledge and directed acyclic graphs (see Chapter [chap:reporting_and_interpretation]). Alternatively, when prediction is the goal, automated selection methods such as forward, backward or stepwise selection can be used, but they should be combined with cross–validation to avoid overfitting. Penalised regression techniques, such as the lasso and ridge (Chapter [chap:regularisation_and_selection]), provide principled ways to shrink coefficients and perform variable selection simultaneously.

Interpretation

In a multiple regression model, each coefficient represents the expected change in the outcome per unit change in its predictor while keeping all other predictors fixed. This ability to adjust for other variables allows us to distinguish the independent effect of each predictor. Confidence intervals and p‑values for each coefficient help assess whether the association is statistically significant. However, statistical significance does not imply clinical importance—examine the magnitude and direction of effects and consider the clinical context.

Exercises

Exercises

  1. Using a publicly available dataset of your choice (e.g., the built‐in mtcars dataset in R or Python), fit a multiple regression model predicting a continuous outcome (e.g., fuel consumption) from at least three predictors. Interpret each coefficient.

  2. Consider the blood pressure example above and add an interaction between weight and sex. Fit the model and interpret the interaction term. When might interactions be important in clinical research?

  3. Explore multicollinearity by computing variance inflation factors (VIFs) for the predictors. How does high multicollinearity affect the estimates and their standard errors?

  4. Simulate a dataset where two predictors are highly correlated (e.g., height and weight) and fit a multiple regression. Compare the individual p‑values to those from a regression with only one predictor.

Code examples use illustrative datasets. Supply data with the named columns to run them.