Chapter 10 · Regression models

How do you model a yes/no outcome with several factors?

Adjusted odds ratios, model fit, discrimination and calibration, matched and multinomial models.

Read first: Correlation and regression, Risk and survival

The problem first

You are a second-year Anaesthesiology resident. Your thesis followed 400 patients after major abdominal surgery, and 71 developed a postoperative pulmonary complication. You entered age, smoking, ASA grade and serum albumin into a logistic regression.

SPSS gave Exp(B) values of 1.05 for age, 2.45 for smoking, 2.81 for ASA III–IV and 0.94 for albumin, with a Hosmer–Lemeshow p of 0.58. You wrote that age had almost no effect and that the model fitted well. Your guide reads those two sentences and asks two questions.

“1.05 per what? And which of your numbers shows that the predicted risks are correct?”

Start here

Why can't a straight line model a yes/no outcome?

Each patient's outcome is 0 or 1, and what you want to predict is the probability of 1. A straight line has no upper or lower limit, so at extreme values of the predictor it predicts probabilities below 0 or above 1.

01probability of complication2030405060708090age (years)straight line: below 0 before age 31and above 1logistic curve
Made-up teaching data: 40 patients, 17 with a complication. The least-squares line predicts a probability of −0.11 at age 25 and 1.15 at age 90, which are impossible values. The logistic curve predicts 0.02 and 0.98 and stays between 0 and 1.

Logistic regression changes the scale of the outcome in two steps. The probability p becomes the odds, p ÷ (1 − p), which runs from 0 to infinity. The odds become the log-odds, ln[p ÷ (1 − p)], which has no upper or lower limit. A straight line is allowed on that scale. The log-odds is called the logit.

probabilityfrom 0 to 10.010.100.250.500.750.900.99oddsfrom 0 to infinity0.010.110.3313999log-oddsno limits−4.60−2.20−1.1001.102.204.60
The same seven risks on three scales. A probability of 0.5 is odds of 1 and log-odds of 0. Log-odds are symmetric: a risk of 10% is −2.20 and a risk of 90% is +2.20. Equal steps on the log-odds scale multiply the odds by the same amount.

ln[p ÷ (1 − p)] = b₀ + b₁x₁ + b₂x₂ + … + bₖxₖ

p = 1 ÷ [1 + e−(b₀ + b₁x₁ + … + bₖxₖ)]

b₀
intercept: the log-odds when every predictor is 0
bᵢ
change in log-odds for a 1-unit rise in xᵢ, with the other predictors held constant
ebᵢ
odds ratio for a 1-unit rise in xᵢ, adjusted for the other predictors

The coefficients are estimated by maximum likelihood: the software finds the values that make the observed pattern of 0s and 1s most probable. The S-curve and the odds ratio from a single predictor are introduced in the correlation and regression chapter.

Interactive

Move the intercept and the coefficient and watch the S-curve, the risks and the odds ratio

The odds ratio for a given change in age is the same at every age. The change in risk is not.

Try this: keep the coefficient at 0.05 and compare two 10-year steps. The odds ratio is 1.65 for both, but the risk rises by 4.3 percentage points from age 40 to 50 and by 10.9 points from 70 to 80.

Teaching model, made-up numbers: log-odds of a postoperative complication = a + b × (age − 60). a is the log-odds at age 60 and b is the change in log-odds for each extra year.

-1.5 (risk 18.2%)

Moves the whole curve up or down

0.050

Makes the curve steeper or flatter

On the log-odds scale the model is a straight line

1.051odds ratio per year (eb)
1.65odds ratio per 10 years (e10b)

Predicted risk: 7.6% at 40, 18.2% at 60, 37.8% at 80. From 40 to 50 the risk changes by 4.3 percentage points. From 70 to 80 it changes by 10.9 points. Both steps multiply the odds by 1.65.

0%25%50%75%100%2030405060708090age (years)+4.3+10.9

Reading the output

What does each coefficient mean when there are several predictors?

Each coefficient is the change in log-odds for a 1-unit rise in that predictor while the other predictors stay the same. Its exponential, e to the power b, is the adjusted odds ratio.

Reference patientodds 0.037, risk 3.6%Age 70 instead of 45× 3.32 → 11.0%Current smoker× 2.45 → 23.2%ASA III–IV× 2.81 → 45.9%Albumin 30, not 42 g/L× 2.11 → 64.1%-3-2-101log-odds of complication
Teaching model from the worked example below. A 45-year-old non-smoker, ASA I–II, with albumin 42 g/L has log-odds −3.29 (risk 3.6%). Each difference adds its coefficient to the log-odds, which multiplies the odds: age 70 instead of 45 (× 3.32), current smoker (× 2.45), ASA III–IV (× 2.81), albumin 30 instead of 42 g/L (× 2.11). The odds rise 48.1-fold, from 0.037 to 1.78, and the risk from 3.6% to 64.1%.

Per unit: choose a unit that means something

The age odds ratio of 1.049 is per year. For a 10-year difference, multiply the coefficient by 10 before taking the exponential: e10 × 0.0480 = 1.62 (95% CI 1.27 to 2.07). The albumin odds ratio of 0.940 is per g/L. For albumin 5 g/L lower: e−5 × −0.0621 = 1.36 (1.03 to 1.82). Scale the confidence limits the same way: ek × (b ± 1.96 × SE) for a change of k units.

Per category: every comparison is against a reference

A predictor with k categories enters the model as k − 1 indicator (dummy) variables. Each coefficient compares one category with the reference category, not with the average patient.

ASA gradeASA II indicatorASA III indicatorASA IV indicatorOdds ratio compares
I (reference)000—
II100II against I
III010III against I
IV001IV against I

Choose a reference category that has enough patients, because every comparison uses it. Changing the reference changes every odds ratio. Entering an ordered category as one score (I = 1, II = 2, III = 3, IV = 4) assumes the same odds ratio for every one-grade step.

Adjusted and unadjusted odds ratios

In the teaching data, albumin alone gives an odds ratio of 0.956 per g/L (95% CI 0.906 to 1.008). Adjusted for age, smoking and ASA grade it is 0.940 (0.888 to 0.995). An adjusted odds ratio compares patients who have the same values of the other predictors. STROBE item 16a asks for both. Without an interaction term the model also assumes that effects multiply: smoking multiplies the odds by 2.45 whatever the ASA grade. An interaction term (smoking × ASA) tests that assumption.

Measurements as predictors

How should age, albumin or BMI enter the model?

Entered as it is, a measurement is assumed to have a straight-line relation with the log-odds: each extra unit adds the same amount at every level. This assumption is called linearity in the logit, and it needs checking.

Age: close to a straight lineBMI: a U shape-2.5-1.5-0.5406080age (years)-2-101203040BMI (kg/m²)log-oddsstraight line missesboth ends
Left, teaching data: log-odds of a complication in five age bands lie close to the straight line from a model with age alone. Adding age² changes −2 log-likelihood by 0.48 (p = 0.49), so a straight line is adequate. Right, made-up data from 2,000 patients in which risk is highest at low and at high BMI. A straight line misses the U shape. Adding BMI² improves the fit by 210.6 (p < 0.001), and the dashed curve follows the points.

Ways to check linearity

  1. Group the measurement into four or more categories, fit them as indicators, and plot the log-odds (or coefficients) against the category midpoints.
  2. Add a squared term (x²) or ln x and compare the models with a likelihood ratio test.
  3. Fit a flexible shape with restricted cubic splines or fractional polynomials. The BLISS study in this chapter considered fractional polynomials for each continuous predictor.

Cutting a measurement into “high” and “low” throws away the differences within each group and assumes that every patient on one side of the cut-off has the same risk. If you do categorise, report the category boundaries (STROBE item 16b).

Model fit

Is the model as a whole any use?

The likelihood is the probability of the observed outcomes under the model. Software reports −2 log-likelihood (−2LL), also called the deviance: the lower it is, the closer the model fits the data.

No predictors374.07+ age360.80+ smoking350.74+ ASA III–IV338.38+ albumin333.77320330340350360370380−2 log-likelihood (axis starts at 320)fall 40.3, 4 df
Teaching data. With no predictors, −2LL is 374.07. Adding age, smoking, ASA grade and albumin brings it down to 333.77. The fall, 40.29 on 4 degrees of freedom (one for each added coefficient), is the likelihood ratio χ², also called the model χ² or omnibus test: p < 0.001.

The likelihood ratio test

LR χ² = (−2LL of the smaller model) − (−2LL of the larger model), df = number of added parameters

The same test compares any two nested models. Removing albumin from the teaching model raises −2LL by 4.61 on 1 degree of freedom (p = 0.032). The Wald test on a single coefficient, (b ÷ SE)², usually agrees. For smoking it is (0.8954 ÷ 0.2803)² = 10.20.

Pseudo-R²

McFadden R² = 1 − ln L₁ ÷ ln L₀

Cox & Snell R² = 1 − (L₀ ÷ L₁)2/n   Nagelkerke R² = Cox & Snell R² ÷ [1 − L₀2/n]

L₀
likelihood of the model with no predictors
L₁
likelihood of the fitted model
n
number of patients

For the teaching model McFadden R² = 0.108, Cox & Snell R² = 0.096 and Nagelkerke R² = 0.158: three versions give three different numbers for one model. None of them is the proportion of variance explained, as R² is in linear regression. In the same data the C statistic is 0.720. Use pseudo-R² to compare models fitted to the same patients.

Akaike information criterion

AIC = −2LL + 2 × number of parameters. For the teaching model 333.77 + 2 × 5 = 343.77. Adding predictors one at a time gives AIC 364.80, 356.74, 346.38 and 343.77. A lower AIC means a better balance between fit and number of parameters, for models fitted to the same data.

Model fit

What does the Hosmer–Lemeshow test tell you, and what does it miss?

It sorts patients by predicted risk, splits them into groups (usually 10), and compares the observed and expected numbers of events in each group with a χ² statistic on g − 2 degrees of freedom.

Risk groupPatientsObserved eventsExpected events
14031.53
24042.53
34023.35
44034.32
54065.16
64056.37
74178.06
839109.38
940911.99
10402218.31

Teaching model: χ² = 6.58 on 8 degrees of freedom, p = 0.58. The expected events in a group are the sum of the predicted risks of its patients, and the non-events are compared in the same way.

Its limitations

  • A p above 0.05 does not show that the risks are right. It shows only that the test did not detect a difference. Van Calster and colleagues (2019) point out that it groups patients artificially, gives a p-value that says nothing about the type or size of miscalibration, and has low power. They recommend against using it to assess calibration.
  • The result depends on the number of groups. The same teaching model gives p = 0.34 with 5 groups, 0.30 with 8, 0.58 with 10, 0.08 with 12 and 0.40 with 15.
  • The result depends on the sample size. In the interactive element below, the same small miscalibration gives p = 0.57 with 250 patients and p < 0.001 with 5,000.

Report a calibration plot with the calibration slope and calibration-in-the-large instead.

Interactive

Change the sample size and the number of groups and watch the Hosmer–Lemeshow p-value

The model's miscalibration is identical at every setting. Only the sample size and the grouping change.

Try this: keep 10 groups and move the sample size from 250 to 5000 patients. The miscalibration is the same at every size, but the p-value falls. Then keep the sample size fixed and change only the number of groups.

Made-up teaching data. The model's predicted risks are slightly too close together: at a predicted risk of 50% the true risk is 57%.

500

100, 250, 500, 1000, 2500 or 5000

10

10 is the usual choice (deciles of risk)

Sample 1
p = 0.441Hosmer-Lemeshow χ² = 7.92, df 8

With 500 patients the test does not reject good fit (p 0.441), although the model is miscalibrated. The same patients with 5 to 15 groups give p-values from 0.112 to 0.597.

5 groups: 0.112 · 6 groups: 0.412 · 7 groups: 0.174 · 8 groups: 0.225 · 9 groups: 0.420 · 10 groups: 0.441 · 11 groups: 0.511 · 12 groups: 0.159 · 13 groups: 0.440 · 14 groups: 0.597 · 15 groups: 0.533

0%0%20%20%40%40%60%60%80%80%predicted risk (group mean)observed riskdashed line: predicted = observedeach dot: about 50 patientsχ² = 7.92, df 8p = 0.441

Model performance

Does the model separate patients, and are its risks correct?

These are two different questions. Discrimination asks whether patients who have the event get higher predicted risks than patients who do not. Calibration asks whether a predicted risk of 20% means that about 20 in 100 such patients have the event.

DiscriminationCalibration0%20%40%60%80%predicted risk71 with complication329 withoutC = 0.7200%0%20%20%40%40%60%60%predicted (observed on the vertical axis)
Teaching model. Left: predicted risks of the 71 patients with a complication (red, above the line) and the 329 without (black, below), as percentages of each group. The two groups overlap. The C statistic is the proportion of the 23,359 pairs of one patient with and one without a complication in which the patient with the complication had the higher predicted risk: 0.720. Right: calibration plot in 10 risk groups. The points lie around the dashed diagonal. Calibration measured in the patients used to build a model is optimistic, so it has to be checked again in other patients.

Discrimination: the C statistic

The C statistic equals the area under the ROC curve of the predicted risks. 0.5 means the model ranks patients no better than chance; 1 means every patient with the event has a higher predicted risk than every patient without. The teaching model has C = 0.72 (95% CI 0.65 to 0.79). Diagnostic test ROC curves are explained in the diagnostic tests chapter.

Calibration: plot, intercept and slope

  • Calibration plot: observed risk against predicted risk, in groups or as a smoothed curve. Points on the diagonal mean agreement.
  • Calibration-in-the-large: whether predicted risks are too high or too low on average. The ideal value is 0. A negative value means the model predicts too many events.
  • Calibration slope: the spread of the predicted risks. The ideal value is 1. A slope below 1 means the predicted risks are too extreme: too low for low-risk patients and too high for high-risk patients.
  • Expected ÷ observed events: the ideal value is 1.
FeatureDiscriminationCalibration
QuestionDoes the model rank patients in the right order?Are the predicted risks the right size?
MeasuresC statistic (area under the ROC curve)Calibration plot, calibration-in-the-large, calibration slope, expected ÷ observed
Ideal value1 (0.5 = no better than chance)Points on the diagonal, intercept 0, slope 1, ratio 1
Adding the same amount to every predicted log-oddsDoes not change itChanges it
Matters most forRanking patients, for example for screeningTelling a patient a risk, using a risk threshold to decide treatment
Common reporting errorReporting only the C statisticReporting only a Hosmer–Lemeshow p-value

Interactive

Shift and spread the predicted risks and watch the C statistic stay the same while the calibration plot moves

A model built where the outcome was more common predicts too high a risk for every patient. It still ranks the patients in the same order.

Try this: move "Shift" to +1.0. Every patient's predicted risk rises, the calibration points fall below the diagonal, and the C statistic does not change, because the order of the patients stays the same.

Made-up teaching cohort of 600 patients. The model starts with the correct risk for every patient. The sliders change its predictions.

0.0 (odds × 1.00)

A model built where the outcome was more or less common

1.0

Above 1: predictions too extreme, as in an overfitted model

Cohort 1
0.766C statistic (discrimination)
1.01calibration slope (ideal 1)
-0.02calibration-in-the-large (ideal 0)

Mean predicted risk 22.5% against an observed rate of 22.2%: expected ÷ observed = 1.02. The points lie close to the diagonal: the predicted risks match the observed risks.

0%0%25%25%50%50%75%75%100%100%predicted risk (mean of group)observed riskdashed line: predicted = observedeach dot: 60 patientsC = 0.766slope = 1.01E/O = 1.02

Sample size

How many events do you need, and what if one predictor predicts perfectly?

Rules of thumb for logistic regression count events, not patients: the number in the smaller outcome group. The teaching data have 400 patients but 71 events, which is 17.8 events for each of the 4 predictor coefficients.

Events per variable

Peduzzi and colleagues (1996) simulated logistic models and found that with fewer than 10 events per variable the coefficients were biased in both directions and the confidence limits did not have the proper coverage. With 10 or more no major problems occurred. van Smeden and colleagues (2016) concluded that the evidence behind such rules is weak: the problems also depend on other factors, such as the total sample size, and on a few data sets in which the outcome is perfectly predicted (separation). Count every coefficient you considered, including each indicator variable and any squared term. The BLISS authors, for example, planned for about 10 events per candidate predictor.

Separation

Marker presentMarker absent5 of 5 with complicationodds 5 ÷ 0: no finite value5 of 35: odds 5 ÷ 30 = 0.17Maximum likelihood:no finite odds ratioFirth's penalised likelihood:OR 61.0
Made-up data: all 5 patients with a rare marker had the complication, against 5 of the 35 without it. The odds with the marker are 5 ÷ 0, so maximum likelihood has no finite estimate. In Python's statsmodels the coefficient stopped at 25.9 (an odds ratio of about 1.7 × 10¹¹). Firth's penalised likelihood gives a finite odds ratio of 61.0.

Separation occurs when a predictor, or a combination of predictors, perfectly separates patients with and without the outcome in the sample. Heinze and Schemper (2002) showed that Firth's penalised likelihood gives finite estimates in this situation, and that penalised likelihood ratio tests and profile penalised likelihood confidence intervals are often preferable to Wald tests. Warning signs are an odds ratio in the hundreds or thousands, a huge standard error, or a category with no events.

Matched case-control studies

What if each case was matched to a control?

Matching makes each case and its controls a set. Ordinary logistic regression ignores the sets. Conditional logistic regression compares each case only with its own controls.

Control exposed?yesnoCase exposed?yesno15 pairsboth exposed25 pairsonly the case exposed10 pairsonly the control exposed10 pairsneither exposedconditional OR = 25 ÷ 10 = 2.50
Made-up teaching data: 60 cases of hospital-acquired diarrhoea, each matched to one control of the same age and ward. Exposure: an antibiotic in the previous month. In 15 pairs both were exposed and in 10 neither, so these pairs say nothing about the exposure. In 25 pairs only the case was exposed and in 10 only the control. Conditional OR = 25 ÷ 10 = 2.50 (95% CI 1.20 to 5.21). Ordinary logistic regression on the same 120 people, ignoring the pairs, gives 2.80 (1.33 to 5.88).

Each matched set has its own baseline odds. Conditional logistic regression removes those set-specific intercepts from the likelihood, so it estimates only the coefficients of the exposures. For 1:1 pairs and a single binary exposure, its odds ratio is the number of pairs in which only the case was exposed divided by the number in which only the control was exposed.

FeatureConditional logistic regressionOrdinary (unconditional) logistic regression
DesignIndividually matched case-control study, 1:1 or 1:mUnmatched studies, and studies with frequency matching
Which patients inform the odds ratioOnly matched sets in which case and controls differ in exposureAll patients
Matching variablesCannot be estimated, because they are the same within each setCan be entered as predictors
Teaching dataOR 2.50 (1.20 to 5.21)OR 2.80 (1.33 to 5.88)
SoftwareR: survival::clogit(). SPSS: Cox Regression with the matched set as strataR: glm(family = binomial). SPSS: Binary Logistic

Outcomes with more than two categories

What if the outcome has three or more categories?

Unordered categories, such as stroke type or discharge destination, need multinomial logistic regression. Ordered categories, such as pain grade or the modified Rankin scale, can use ordinal logistic regression, usually the proportional odds model.

none · mild · moderate · severe (percent of patients)Drug A30402010Drug B15353020Cut-point odds ratios, B vs A:mild or worse vs none 2.43 · moderate or worse vsnone or mild 2.33 · severe vs the rest 2.25Proportional odds model: one OR 2.35 (95% CI 1.41 to 3.94)Multinomial model, each grade vs none:mild 1.75 · moderate 3.00 · severe 4.00
Made-up teaching data: pain grade 24 hours after surgery in 100 patients given each analgesic. The multinomial model compares each grade with no pain: odds ratios for drug B against drug A of 1.75 (mild), 3.00 (moderate) and 4.00 (severe). The ordinal model cuts the scale at each step and assumes one common odds ratio for being in a worse grade: 2.35 (95% CI 1.41 to 3.94, p = 0.001). The separate cut-point odds ratios, 2.43, 2.33 and 2.25, are close to each other, so the proportional odds assumption is reasonable here.

The proportional odds model assumes that a predictor has the same odds ratio at every cut-point of the scale. SPSS's Ordinal Regression offers a test of parallel lines for this assumption. When the odds ratios clearly differ, use a multinomial model. A multinomial model estimates a separate set of coefficients for each non-reference category, so it needs more events than an ordinal model.

FeatureMultinomial logistic regressionOrdinal logistic regression (proportional odds)
OutcomeThree or more categories without an orderThree or more ordered categories
Odds ratios per predictorOne for each category against the reference category (k − 1)One: the odds of a worse category against a better one
Main assumptionThe odds ratio of any two categories does not depend on the other categories (stated in the SPSS manual)The same odds ratio at every cut-point
Teaching data, drug B vs A1.75, 3.00 and 4.00 against no pain2.35
SPSSAnalyze > Regression > Multinomial Logistic RegressionAnalyze > Regression > Ordinal
Rnnet::multinom()MASS::polr()

Odds ratio or risk ratio

When does the odds ratio overstate the risk ratio?

Logistic regression gives odds ratios. When the outcome is rare, the odds ratio is close to the risk ratio. When the outcome is common, the odds ratio is further from 1 than the risk ratio.

11.522.530%10%20%30%40%50%risk in the unexposed grouprisk ratioOR 3OR 21.981.542.941.88
Risk ratio corresponding to an odds ratio of 2 or 3 at different risks in the unexposed group: RR = OR ÷ (1 − p₀ + OR × p₀). At a baseline risk of 1%, an odds ratio of 2 is a risk ratio of 1.98. At 30% it is 1.54.

McNutt and colleagues (2003) wrote that the adjusted odds ratio approximates the adjusted relative risk when the incidence is below 10%, and that for more common outcomes the odds ratio always overstates the relative risk. They described the incorrect application of a proposed method for converting an adjusted odds ratio into an adjusted relative risk, and alternative methods. In cohort studies and trials with a common outcome, estimate the risk ratio directly. Zou (2004) proposed Poisson regression with robust standard errors for this, the “modified Poisson” approach, described in the count models chapter. In a case-control study the odds ratio is the measure available. The basic 2 × 2 comparison is in the risk and survival chapter.

Decide

Which logistic model fits your study?

Answer the questions in order. Each answer links to its section.

What kind of outcome do you have?

Which model: all possible answers
  • Binary logistic regression: Check linearity of continuous predictors, events per parameter, discrimination and calibration.
  • Firth penalised logistic regression: Gives finite estimates when maximum likelihood fails because of separation.
  • Conditional logistic regression: Compares each case with its own matched controls. Matching variables cannot be estimated.
  • Modified Poisson or log-binomial regression: Estimates the risk ratio directly. Logistic odds ratios are further from 1 when the outcome is common.
  • Ordinal (proportional odds) logistic regression: One odds ratio per predictor for being in a worse category.
  • Multinomial logistic regression: A separate odds ratio for each category against the reference category. Needs more events.
  • Cox regression: Hazard ratios for time-to-event data with censoring.
  • Poisson or negative binomial regression: Incidence rate ratios for counts, with an offset for follow-up time.

The formula

Worked example: reading a logistic regression table

Made-up teaching data: the 400 patients from the thesis at the top of this chapter, 71 with a postoperative pulmonary complication. Fitted in Python with statsmodels.

PredictorBSEWaldpOR = Exp(B)95% CI
Age (per year)0.04800.012514.74< 0.0011.0491.024 to 1.075
Current smoker (vs non-smoker)0.8950.28010.200.0012.4481.414 to 4.241
ASA III–IV (vs I–II)1.0330.28213.37< 0.0012.8091.615 to 4.886
Albumin (per g/L)−0.06210.02924.530.0330.9400.888 to 0.995
Constant−2.8481.2285.380.020
  1. B is the change in log-odds. Smoking adds 0.895 to the log-odds of a complication, with age, ASA grade and albumin unchanged.
  2. Odds ratio = eB = e0.895 = 2.45: smokers have 2.45 times the odds of a complication.
  3. 95% CI = eB ± 1.96 × SE = e0.8954 ± 1.96 × 0.2803 = e0.346 to e1.444 = 1.41 to 4.24.
  4. Wald χ² = (B ÷ SE)² = (0.8954 ÷ 0.2803)² = 10.20 on 1 df, p = 0.001.
  5. Units: 1.049 per year of age is 1.62 per 10 years. 0.940 per g/L of albumin is 1.36 for albumin 5 g/L lower.
  6. Predicted risk for a 70-year-old smoker, ASA III–IV, albumin 30 g/L: log-odds = −2.848 + 0.0480 × 70 + 0.895 + 1.033 − 0.0621 × 30 = 0.577. Odds = e0.577 = 1.78. Risk = 1.78 ÷ 2.78 = 64%.
  7. Whole model: −2LL 374.07 → 333.77, likelihood ratio χ² 40.29 on 4 df, p < 0.001. Nagelkerke R² 0.158.
  8. Performance: C statistic 0.72 (95% CI 0.65 to 0.79, Hanley and McNeil method). Hosmer–Lemeshow p = 0.58, which does not establish calibration.
  9. Events per variable: 71 ÷ 4 = 17.8.

In a real paper

Logistic regression in two published prediction models

Open-access paper · CC BY

Jordan RE, Keene SJ, Franssen FME, Fitzmaurice D, Adderley NJ, Dickens AP, et al. Prognostic score for predicting respiratory admissions among patients with chronic obstructive pulmonary disease in primary care: development and validation in population cohorts (Birmingham Lung Improvement Studies (BLISS)). BMJ. 2026;392:e084521.

The study: A prognostic score for respiratory hospital admission within two years in patients with COPD in primary care. It was developed by multivariable logistic regression from 23 candidate predictors in 1894 patients, corrected for overfitting after bootstrapping, and validated in 1749 patients (ECLIPSE) and 27 340 patients (CPRD). A score that gives individual risks has to be calibrated as well as discriminating.

What the authors wrote
“The calibration-in-the-large (−0.15 (95% CI −0.32 to 0.02) and calibration slope (0.92 (0.79 to 1.05)) (fig 2) are close to their ideal values of 0 and 1, again with slightly lower values owing to the slight overestimation at high predictions.”
In plain words

Calibration-in-the-large of −0.15 means that in the ECLIPSE cohort the predicted risks were on average slightly higher than the observed risks; 0 is ideal. A calibration slope of 0.92 means the predicted risks were slightly too spread out; 1 is ideal. Both confidence intervals include the ideal value. The authors attribute the small departures to overestimation in patients with the highest predicted risks.

ReportedValueWhat it means
C statistic, development (optimism adjusted)0.73 (0.70 to 0.77)Discrimination after correction for overfitting by bootstrapping
C statistic, ECLIPSE0.73 (0.71 to 0.76)The same discrimination in a separate cohort
Calibration-in-the-large, ECLIPSE−0.15 (−0.32 to 0.02)Average predicted risk slightly above observed
Calibration slope, ECLIPSE0.92 (0.79 to 1.05)Predicted risks slightly too spread out
Uniform shrinkage factor0.873Every coefficient was multiplied by 0.873 to correct for overfitting
OR, respiratory admission in previous 12 months3.63 (2.42 to 5.45)A binary predictor, after shrinkage
OR, age (per year increase)1.03 (1.01 to 1.04)A continuous predictor: per 1-year difference
Check these when you read it
  • Were continuous predictors checked for a non-linear relation? The authors considered fractional polynomials.
  • Is calibration shown with a plot and with a slope and calibration-in-the-large, not only a C statistic?
  • Were there enough events for the number of candidate predictors? They planned for about 10 events per candidate variable.
  • Was performance measured in patients who were not used to build the model?
  • Is the full equation given so that a reader can calculate a risk (TRIPOD+AI item 22)? It is in the footnote of table 3.
Open-access paper · CC BY-NC-ND

Wu S, Wang Y, Yuan R, Guo F, Yang D, Li Z, et al. Predicting the emergence of malignant brain oedema in acute ischaemic stroke: a prospective multicentre study with development and validation of predictive modelling. EClinicalMedicine. 2023;59:101977.

The study: A prospective multicentre cohort of adults with acute ischaemic stroke admitted to nine tertiary hospitals in China. A logistic model for malignant brain oedema was derived in 1627 patients and validated in 556. It reports adjusted odds ratios for binary and continuous predictors, and assessed calibration with the Hosmer–Lemeshow test.

What the authors wrote
“The model had good discrimination (AUC 0.94, 95% CI 0.92–0.95; Fig. 1A) and calibration (Hosmer–Lemeshow test χ² = 6.38, df = 8, p = 0.60; Fig. 1B), with better overall classification than the model with only large infarct and NIHSS (NRI 0.81, 0.67–0.95, p < 0.001).”
In plain words

AUC 0.94: in 94% of pairs of one patient with and one without malignant oedema, the model gave the higher risk to the patient with oedema, in the patients used to build it. Hosmer–Lemeshow χ² 6.38 on 8 degrees of freedom (10 groups − 2), p = 0.60: the test did not detect a difference between observed and expected events. That is not evidence that the predicted risks are accurate. NRI (net reclassification index) 0.81: the seven-variable model classified patients better than a model with only large infarct and NIHSS score.

ReportedValueWhat it means
Adjusted OR, large infarct40.90 (20.20–82.80)A binary predictor with a very large odds ratio and a wide interval
Adjusted OR, NIHSS score1.09 (1.06–1.12)A continuous score, β 0.086. The table does not state the unit. If it is per point, 10 points would be e^(10 × 0.086) = 2.36
Adjusted OR, recanalisation0.36 (0.17–0.75)Below 1: lower odds of malignant oedema
Intercept−6.208Log-odds when every predictor is 0, needed to calculate a risk
AUC, derivation cohort0.94 (0.92–0.95)Discrimination in the patients used to build the model
Hosmer–Lemeshow testχ² = 6.38, df = 8, p = 0.60No evidence of lack of fit, which is not proof of good calibration
Check these when you read it
  • For a very large odds ratio such as 40.90, look at the number of patients and events behind it and at the width of its interval.
  • Is the unit of each continuous predictor stated? Table 2 gives NIHSS as a continuous variable without a unit.
  • Calibration rested on the Hosmer–Lemeshow test and a decile plot. Look for a calibration slope and calibration-in-the-large as well.
  • In the validation cohort, is discrimination reported for the full range of predicted risks, or only at the chosen threshold of 0.14?
  • The sample size was planned on at least 10 events per variable: count the candidate variables screened, not only the seven retained.

How to run it

Running logistic regression in SPSS, R and jamovi

Menu paths below are from the IBM SPSS Statistics 27 manuals. Function names and arguments are from the CRAN reference manuals.

SPSS

  1. Analyze > Regression > Binary Logistic. Move the outcome to Dependent and the predictors to Covariates. Use Categorical to declare categorical predictors and choose the reference category.
  2. In Options, tick CI for exp(B). Hosmer-Lemeshow goodness-of-fit is also offered there. The output gives the omnibus test of model coefficients, −2 log-likelihood, Cox & Snell and Nagelkerke R², and B, SE, Wald and Exp(B) for each predictor.
  3. For the C statistic, save the predicted probabilities (Save), then use Analyze > Classify > ROC Curve.
  4. Unordered outcome: Analyze > Regression > Multinomial Logistic Regression. Ordered outcome: Analyze > Regression > Ordinal, which offers a Test of parallel lines.
  5. Matched sets: an IBM support note describes conditional logistic regression through Analyze > Survival > Cox Regression: code the time variable 1 for cases and 2 for controls, define the event as the case status, and put the matched-set identifier in Strata. The note advises this for 1:1 and 1:n matching.

R

fit <- glm(ppc ~ age + smoker + asa34 + albumin, family = binomial, data = d)
summary(fit)                         # B, SE, z (Wald) and p for each coefficient
exp(coef(fit))                       # odds ratios
exp(confint(fit))                    # 95% CIs by profile likelihood (confint.default() gives Wald CIs)
anova(fit, test = "Chisq")           # likelihood ratio tests
ResourceSelection::hoslem.test(fit$y, fitted(fit), g = 10)
pROC::auc(pROC::roc(d$ppc, fitted(fit)))
rms::val.prob(fitted(fit), d$ppc)    # calibration plot and measures

survival::clogit(case ~ antibiotic + strata(pair), data = m)   # matched sets
MASS::polr(pain ~ drug, data = p, Hess = TRUE)                # proportional odds
nnet::multinom(pain ~ drug, data = p)                          # unordered categories
logistf::logistf(ppc ~ marker, data = s)                       # Firth's penalised likelihood

jamovi

  1. Analyses → Regression → 2 Outcomes (binomial). For more categories: N Outcomes (multinomial) or Ordinal Outcomes.
  2. Move the outcome to Dependent Variable, measurements to Covariates and categorical predictors to Factors. Set reference levels under Reference levels.
  3. Under Model Coefficients, tick Odds ratio and its confidence interval. Under Model Fit, tick Deviance, AIC, Overall Model Test and the pseudo-R² values. Prediction gives the classification table. The underlying jmv function, logRegBin(), also has auc and rocPlot options.

How to report it

What to write in the thesis and the paper

State how the model was built before giving its results, and give odds ratios with their units, reference categories and confidence intervals.

Methods

  • The outcome, how many patients had it, and why logistic regression was used.
  • How predictors were chosen (before the analysis, from clinical knowledge), how many were considered, and the events per candidate variable.
  • How categorical predictors were coded (reference categories) and how continuous predictors were handled (TRIPOD+AI item 12b).
  • Measures of model performance: discrimination, calibration, and how they were validated (TRIPOD+AI item 12e). Software and version.

Results

  • Unadjusted and adjusted odds ratios with 95% confidence intervals (STROBE item 16a), with the unit for each measurement.
  • For a prediction model: the full equation including the intercept (TRIPOD+AI item 22), and performance with confidence intervals (item 23a).

A worked sentence using this chapter's teaching numbers

Of 400 patients, 71 (17.8%) developed a postoperative pulmonary complication. In multivariable logistic regression, older age (adjusted odds ratio 1.62 per 10 years, 95% CI 1.27 to 2.07), current smoking (2.45, 1.41 to 4.24), ASA grade III–IV compared with I–II (2.81, 1.62 to 4.89) and lower serum albumin (1.36 per 5 g/L lower, 1.03 to 1.82) were associated with higher odds of complication (likelihood ratio χ² 40.29, 4 df, p < 0.001). The model had a C statistic of 0.72 (95% CI 0.65 to 0.79) in the development data. Its calibration has not been assessed in other patients.

By specialty

Logistic regression problems by specialty

A thesis of 400 patients after major abdominal surgery, 71 with a postoperative pulmonary complication, with age, smoking, ASA grade and albumin as predictors.

Give the unit for every odds ratio: 1.049 per year is 1.62 per 10 years. With 71 events, prespecify a small number of predictors.

Common myths

Common mistaken beliefs

  • Myth: An odds ratio of 1.05 for age is too small to matter.

    It is per year. In the teaching model 1.049 per year is 1.62 per 10 years. Always read the unit.

  • Myth: A Hosmer–Lemeshow p above 0.05 proves the model is well calibrated.

    It only fails to detect miscalibration. The teaching model gives p from 0.08 to 0.58 depending on the number of groups, and Van Calster and colleagues (2019) recommend against the test.

  • Myth: A high C statistic means the predicted risks are correct.

    The C statistic measures ranking only. Adding the same amount to every predicted log-odds leaves it unchanged while every risk is wrong.

  • Myth: The odds ratio can be read as a relative risk.

    Only when the outcome is rare. At a baseline risk of 30%, an odds ratio of 2 is a risk ratio of 1.54.

  • Myth: Nagelkerke R² of 0.16 means the model explains 16% of the variation.

    Pseudo-R² values are not proportions of explained variance, and different versions give different values for the same model: 0.108, 0.096 and 0.158 here.

  • Myth: Matched case-control data can be analysed with ordinary logistic regression.

    Use conditional logistic regression. In the teaching pairs the conditional odds ratio is 2.50 and the unconditional 2.80.

Why this matters to you

Five consequences of getting logistic regression wrong

  1. Protocol sent back

    A plan to "enter all significant variables into logistic regression" gives no events per variable, no list of candidate predictors and no way of handling continuous predictors.

  2. A wrong conclusion in the thesis

    Writing that age has "no effect" because its odds ratio per year is 1.05, or reporting an odds ratio of 2.45 for a common outcome as a 2.45-fold risk.

  3. Questions you cannot answer at the viva

    "How do you know your predicted risks are right?" needs a calibration plot, slope and intercept, not a Hosmer–Lemeshow p-value.

  4. Misreading papers

    Accepting an odds ratio in the thousands from sparse data, or a prediction model reported with only a C statistic in the patients used to build it.

  5. Harm to patients

    A risk score that overestimates risk in a new hospital can lead to unnecessary treatment; one that underestimates risk can withhold it.

History

History of logistic regression

  1. 1944

    Joseph Berkson

    Published "Application of the logistic function to bio-assay" in the Journal of the American Statistical Association.

  2. 1958

    D. R. Cox

    Published "The regression analysis of binary sequences": tests and estimates for a sequence of 0s and 1s in which the chance of a 1 depends on one or more independent variables.

  3. 1972

    John Nelder and Robert Wedderburn

    Published "Generalized linear models", showing that one fitting method, iterative weighted linear regression, gives maximum likelihood estimates for normal, binomial, Poisson and gamma outcomes.

  4. 1979

    Ross Prentice and Ronald Pyke

    Published "Logistic disease incidence models and case-control studies" in Biometrika.

  5. 1980

    David Hosmer and Stanley Lemeshow

    Published "Goodness of fit tests for the multiple logistic regression model".

  6. 1980

    Peter McCullagh

    Published "Regression models for ordinal data", in which the proportional odds and proportional hazards models were described as likely to be the most useful in practice.

  7. 1996

    Peter Peduzzi and colleagues

    Simulated logistic models and found biased coefficients and incorrect confidence limits with fewer than 10 events per variable.

  8. 2002

    Georg Heinze and Michael Schemper

    Showed that Firth's penalised likelihood gives finite estimates when separation makes maximum likelihood estimates diverge.

  9. 2016

    Maarten van Smeden and colleagues

    Concluded that the evidence supporting events-per-variable rules for binary logistic regression is weak.

  10. 2019

    Ben Van Calster and colleagues

    Described calibration as "the Achilles heel of predictive analytics" and recommended against the Hosmer–Lemeshow test for assessing calibration.

  11. 2024

    Gary Collins and colleagues

    Published TRIPOD+AI, a 27-item checklist for reporting prediction models built with regression or machine learning, superseding TRIPOD 2015.

Guidelines

Logistic regression in reporting guidelines

TRIPOD+AI (2024), item 12b

“Depending on the type of model, describe how predictors were handled in the analyses (functional form, rescaling, transformation, or any standardisation)”.

TRIPOD+AI (2024), item 12e

“Specify all measures and plots used (and their rationale) to evaluate model performance (eg, discrimination, calibration, clinical utility) and, if relevant, to compare multiple models”.

TRIPOD+AI (2024), item 22

“Provide details of the full prediction model (eg, formula, code, object, application programming interface) to allow predictions in new individuals and to enable third party evaluation and implementation”.

TRIPOD+AI (2024), item 23a

“Report model performance estimates with confidence intervals, including for any key subgroups (eg, sociodemographic). Consider plots to aid presentation”.

STROBE (2007), item 16a

“Give unadjusted estimates and, if applicable, confounder-adjusted estimates and their precision (e.g., 95% confidence intervals). Make clear which confounders were adjusted for and why they were included.”

Reading a paper

Six checks on any logistic regression

  • Are the number of events and the number of candidate predictors both given?
  • Is the unit of every continuous predictor and the reference category of every categorical predictor stated?
  • Was the shape of the relation checked for continuous predictors, or were they cut into categories without reason?
  • Are unadjusted and adjusted odds ratios given with confidence intervals, and is a very large odds ratio explained?
  • For a prediction model, are both discrimination and calibration reported, in patients not used to build the model?
  • If the outcome is common, are odds ratios described as odds ratios? If cases were matched, was a conditional analysis used?

Why is it called that?

Word surgery

“Odds”

In everyday speech

The chance of something happening, as in "the odds are against it".

In research

A ratio: the probability of an event divided by the probability of no event. A risk of 20% is odds of 0.25.

“Calibration”

In everyday speech

Adjusting an instrument, such as a weighing scale, so that it reads correctly.

In research

Agreement between the risks a model predicts and the risks observed in patients.

“Logistic”

In everyday speech

Logistics: transport, supplies, organising.

In research

The model in which the log-odds of an outcome is a linear combination of predictors.

Memory trick

Coefficients add on the log-odds scale and multiply on the odds scale. For k units, multiply the coefficient by k, then take e to that power.

Logistic

Greek logistikos: "skilled in calculating", from logistes, "a calculator"

Logistic regression models the log-odds of an outcome. Its S-shaped curve is the logistic function.

Odds

first found in wagering, 1590s, probably from "odd"

Probability of the event ÷ probability of no event. The odds ratio compares two odds.

Regression

Latin regressio: "a going back, a return"

A model of how an outcome changes with predictors. Logistic regression is regression for a yes/no outcome.

Discrimination

Latin discriminare: "to divide, separate"

How well a model separates patients with the outcome from patients without it, measured by the C statistic.

Calibration

"act or process of calibrating", recorded from 1854

How closely predicted risks agree with observed risks.

Exam answers

Model answer outlines

Logistic regression

DM Neurology 2009
  1. Definition: a regression model for a binary outcome (yes/no) with one or more predictors, which may be continuous or categorical. It models the log-odds (logit) of the outcome: ln[p ÷ (1 − p)] = b₀ + b₁x₁ + … + bₖxₖ, so predicted probabilities stay between 0 and 1.
  2. Why not linear regression: a straight line can predict probabilities below 0 or above 1, and the outcome is not normally distributed.
  3. Interpretation: eb is the odds ratio for a 1-unit rise in the predictor, adjusted for the others. State the unit (per year, per 10 years) and the reference category. OR > 1 higher odds, OR < 1 lower odds. 95% CI = eb ± 1.96 SE.
  4. Estimation and tests: maximum likelihood. Wald test for each coefficient, (b ÷ SE)². Likelihood ratio test for the whole model or nested models: difference in −2 log-likelihood on χ².
  5. Assumptions: independent observations, linear relation of continuous predictors with the log-odds, no severe multicollinearity, enough events (about 10 per variable as a rough guide, with weak evidence behind it), no separation.
  6. Model fit and performance: pseudo-R² (McFadden, Cox & Snell, Nagelkerke), AIC, discrimination by the C statistic (area under the ROC curve), calibration by plot, slope and calibration-in-the-large. The Hosmer–Lemeshow test (10 groups, df 8) has low power and depends on grouping.
  7. Types: binary logistic regression. Multinomial for unordered categories. Ordinal (proportional odds) for ordered categories. Conditional for matched case-control studies. Firth's penalised likelihood for sparse data or separation.
  8. Uses: adjusted odds ratios for risk factors in cohort, cross-sectional and case-control studies, and prediction scores for individual risk.
  9. Limitations: odds ratios overstate risk ratios when the outcome is common. Results depend on how predictors were chosen and coded. A model must be validated in new patients.
  10. Example: 400 surgical patients, 71 complications. Smoking OR 2.45 (1.41 to 4.24), age OR 1.62 per 10 years, likelihood ratio χ² 40.29 (4 df), C statistic 0.72. Neurology example: ordinal logistic regression of the 90-day modified Rankin scale after stroke.
  11. Reporting: STROBE item 16a for adjusted and unadjusted estimates, and TRIPOD+AI for prediction models (full equation, discrimination and calibration with confidence intervals).

The one thing to remember

An odds ratio from logistic regression means nothing without its unit and its reference category, and a prediction model is not validated until its predicted risks have been compared with outcomes in other patients.

All worked examples use made-up numbers for teaching. Models were fitted in Python 3 with statsmodels 0.14.5, SciPy 1.15.3 and scikit-learn 1.7.2.

Sources: Jordan RE et al. BMJ 2026;392:e084521 (doi:10.1136/bmj-2025-084521, PMID 41786356). Wu S et al. EClinicalMedicine 2023;59:101977 (doi:10.1016/j.eclinm.2023.101977, PMID 37152361). Berkson J. J Am Stat Assoc 1944;39(227):357–65 (doi:10.1080/01621459.1944.10500699). Cox DR. J R Stat Soc Series B 1958;20(2):215–32 (doi:10.1111/j.2517-6161.1958.tb00292.x). Nelder JA, Wedderburn RWM. J R Stat Soc Series A 1972;135(3):370 (doi:10.2307/2344614). Prentice RL, Pyke R. Biometrika 1979;66(3):403–11 (doi:10.1093/biomet/66.3.403). Hosmer DW, Lemeshow S. Commun Stat Theory Methods 1980;9(10):1043–69 (doi:10.1080/03610928008827941). McCullagh P. J R Stat Soc Series B 1980;42(2):109–27 (doi:10.1111/j.2517-6161.1980.tb01109.x). Peduzzi P et al. J Clin Epidemiol 1996;49(12):1373–9 (PMID 8970487). Heinze G, Schemper M. Stat Med 2002;21(16):2409–19 (PMID 12210625). McNutt LA et al. Am J Epidemiol 2003;157(10):940–3 (PMID 12746247). Zou G. Am J Epidemiol 2004;159(7):702–6 (PMID 15033648). van Smeden M et al. BMC Med Res Methodol 2016;16:163 (PMID 27881078). Van Calster B et al. BMC Med 2019;17:230 (PMID 31842878). Collins GS et al. TRIPOD+AI statement. BMJ 2024;385:e078378 (PMID 38626948). von Elm E et al. STROBE statement. PLoS Med 2007;4(10):e296 (PMID 17941714). IBM SPSS Statistics 27 Regression, Base and Advanced Statistics manuals, and IBM support note swg21477360. CRAN reference manuals: stats (R documentation), ResourceSelection, pROC, rms, survival, MASS, nnet, logistf, jmv. jamovi documentation.

Past papers

TNMGRMU questions on logistic regression in depth

Questions from MD, MS, DM, MCh and Ph.D. papers that this chapter helps you answer. Tap a sitting to open the university's own question paper.

  1. ×1Logistic regressionDM Neurology · Aug 2009

Further reading

Related Stateazy articles