Book contents

REGRESSION MODELLING FOR HEALTH PRACTITIONERS · CHAPTER 5

Logistic Regression

Why use logistic regression?

Many health research questions involve a binary outcome, such as survival vs death, disease present vs absent, or treatment success vs failure. Linear regression is unsuitable for binary outcomes because it can predict values outside the (0,1)(0,1) interval and assumes normally distributed residuals. Logistic regression provides a solution by modelling the logit (log–odds) of the outcome as a linear function of predictors. It allows you to estimate the effect of one or more explanatory variables on the probability of an event while controlling for confounders. As noted in the biostatistics literature, logistic regression works similarly to linear regression except that the response variable is binomial and the model estimates odds ratios; it can handle multiple continuous and categorical predictors and avoids confounding by analysing all variables together.

Model specification

For a binary outcome Y∈{0,1}Y \in \{0,1\} and a vector of predictors 𝐱\mathbf{x}, the logistic regression model assumes logit(Pr(Y=1∣𝐱))=β0+β1x1+β2x2+⋯+βpxp,\operatorname{logit}\bigl(\Pr(Y=1\mid\mathbf{x})\bigr) = \beta_0 + \beta_1 x_1 + \beta_2 x_2 + \cdots + \beta_p x_p, where logit(p)=log{p/(1−p)}\operatorname{logit}(p) = \log\{p/(1-p)\} is the log–odds. Exponentiating a coefficient yields an odds ratio: exp(βj)\exp(\beta_j) represents the multiplicative change in the odds of the outcome associated with a one–unit increase in xjx_j, holding other variables constant. Continuous variables can be used directly; categorical variables require dummy coding. Standard logistic regression assumes independent observations and a correctly specified linear predictor. Extensions can relax these assumptions (e.g., mixed-effects logistic models).

Worked example

Consider a cohort study investigating whether smoking and age are associated with the presence of coronary heart disease (CHD). The binary outcome is CHD (1 = disease, 0 = no disease); predictors are Smoking (1 if current smoker, 0 if not) and Age (continuous in years). We fit a logistic regression to estimate the effect of smoking while controlling for age.

Worked example

R

# Assume df has columns: CHD (0/1), Smoking (0/1), Age
fit <- glm(CHD ~ Smoking + Age, data = df, family = binomial)
summary(fit)
exp(coef(fit))            # odds ratios
confint(fit)              # Wald CIs for log-odds
exp(confint(fit))         # CIs for odds ratios

Python (statsmodels)

import pandas as pd
import statsmodels.api as sm

# df: DataFrame with columns 'CHD', 'Smoking', 'Age'
X = sm.add_constant(df[['Smoking', 'Age']])
y = df['CHD']
model = sm.Logit(y, X)
result = model.fit()
print(result.summary())
print(np.exp(result.params))         # odds ratios
print(np.exp(result.conf_int()))     # CIs for odds ratios

Julia

using DataFrames, GLM

# df: DataFrame with CHD, Smoking, Age
fm = @formula(CHD ~ Smoking + Age)
fit = glm(fm, df, Binomial(), LogitLink())
coeftable(fit)
exp.(coef(fit))            # odds ratios
confint(fit)               # confidence intervals for coefficients

Suppose the fitted model yields β̂1=1.20\hat\beta_1 = 1.20 for Smoking and β̂2=0.05\hat\beta_2 = 0.05 for Age. The odds ratio for smoking is e1.20≈3.32e^{1.20} \approx 3.32, indicating that smokers have 3.3 times the odds of CHD compared with non-smokers after adjusting for age. The odds ratio for age is e0.05≈1.05e^{0.05} \approx 1.05, meaning each additional year of age increases the odds of CHD by about 5%.

Interpretation

Exercises

Exercises

  1. Using a publicly available heart disease dataset (e.g., the UCI heart disease data), fit a logistic regression model for the presence of CHD with predictors gender, age, systolic blood pressure, and cholesterol. Estimate odds ratios and 95% confidence intervals. Interpret the effect of cholesterol.

  2. Simulate a dataset in your preferred language (R/Python/Julia) where the probability of disease increases with age and smoking. Fit a logistic regression model and compare the estimated coefficients with the known values used in the simulation.

  3. Explain why using linear regression for a binary outcome can produce predicted probabilities outside the 0–1 range. Provide a numerical example.

  4. Discuss how to assess goodness-of-fit for logistic models (e.g., Hosmer–Lemeshow test, calibration plots) and apply one of these methods to your dataset.

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