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 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 and a vector of predictors , the logistic regression model assumes where is the log–odds. Exponentiating a coefficient yields an odds ratio: represents the multiplicative change in the odds of the outcome associated with a one–unit increase in , 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
for Smoking and
for Age. The odds ratio for smoking is
,
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
,
meaning each additional year of age increases the odds of CHD by about
5%.
Interpretation
Effect measures. Report odds ratios with confidence intervals to convey the magnitude and precision of associations. Avoid presenting only p-values.
Probability vs odds. A large odds ratio does not necessarily imply a large absolute risk difference; interpret predicted probabilities to judge clinical relevance.
Reference group. Clearly define the reference category for categorical variables (here, non-smokers and younger age).
Model adequacy. Check for influential observations and assess the linearity of continuous predictors on the logit scale (e.g., via splines or transformations).
Exercises
Exercises
Using a publicly available heart disease dataset (e.g., the
UCI heart diseasedata), 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.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.
Explain why using linear regression for a binary outcome can produce predicted probabilities outside the 0–1 range. Provide a numerical example.
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.