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.
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.
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.
Moves the whole curve up or down
Makes the curve steeper or flatter
On the log-odds scale the model is a straight line
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.
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.
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 grade | ASA II indicator | ASA III indicator | ASA IV indicator | Odds ratio compares |
|---|---|---|---|---|
| I (reference) | 0 | 0 | 0 | — |
| II | 1 | 0 | 0 | II against I |
| III | 0 | 1 | 0 | III against I |
| IV | 0 | 0 | 1 | IV 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.
Ways to check linearity
- Group the measurement into four or more categories, fit them as indicators, and plot the log-odds (or coefficients) against the category midpoints.
- Add a squared term (x²) or ln x and compare the models with a likelihood ratio test.
- 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.
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 group | Patients | Observed events | Expected events |
|---|---|---|---|
| 1 | 40 | 3 | 1.53 |
| 2 | 40 | 4 | 2.53 |
| 3 | 40 | 2 | 3.35 |
| 4 | 40 | 3 | 4.32 |
| 5 | 40 | 6 | 5.16 |
| 6 | 40 | 5 | 6.37 |
| 7 | 41 | 7 | 8.06 |
| 8 | 39 | 10 | 9.38 |
| 9 | 40 | 9 | 11.99 |
| 10 | 40 | 22 | 18.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%.
100, 250, 500, 1000, 2500 or 5000
10 is the usual choice (deciles of risk)
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
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.
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.
| Feature | Discrimination | Calibration |
|---|---|---|
| Question | Does the model rank patients in the right order? | Are the predicted risks the right size? |
| Measures | C statistic (area under the ROC curve) | Calibration plot, calibration-in-the-large, calibration slope, expected ÷ observed |
| Ideal value | 1 (0.5 = no better than chance) | Points on the diagonal, intercept 0, slope 1, ratio 1 |
| Adding the same amount to every predicted log-odds | Does not change it | Changes it |
| Matters most for | Ranking patients, for example for screening | Telling a patient a risk, using a risk threshold to decide treatment |
| Common reporting error | Reporting only the C statistic | Reporting 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.
A model built where the outcome was more or less common
Above 1: predictions too extreme, as in an overfitted model
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.
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
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.
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.
| Feature | Conditional logistic regression | Ordinary (unconditional) logistic regression |
|---|---|---|
| Design | Individually matched case-control study, 1:1 or 1:m | Unmatched studies, and studies with frequency matching |
| Which patients inform the odds ratio | Only matched sets in which case and controls differ in exposure | All patients |
| Matching variables | Cannot be estimated, because they are the same within each set | Can be entered as predictors |
| Teaching data | OR 2.50 (1.20 to 5.21) | OR 2.80 (1.33 to 5.88) |
| Software | R: survival::clogit(). SPSS: Cox Regression with the matched set as strata | R: 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.
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.
| Feature | Multinomial logistic regression | Ordinal logistic regression (proportional odds) |
|---|---|---|
| Outcome | Three or more categories without an order | Three or more ordered categories |
| Odds ratios per predictor | One for each category against the reference category (k − 1) | One: the odds of a worse category against a better one |
| Main assumption | The 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 A | 1.75, 3.00 and 4.00 against no pain | 2.35 |
| SPSS | Analyze > Regression > Multinomial Logistic Regression | Analyze > Regression > Ordinal |
| R | nnet::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.
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.
| Predictor | B | SE | Wald | p | OR = Exp(B) | 95% CI |
|---|---|---|---|---|---|---|
| Age (per year) | 0.0480 | 0.0125 | 14.74 | < 0.001 | 1.049 | 1.024 to 1.075 |
| Current smoker (vs non-smoker) | 0.895 | 0.280 | 10.20 | 0.001 | 2.448 | 1.414 to 4.241 |
| ASA III–IV (vs I–II) | 1.033 | 0.282 | 13.37 | < 0.001 | 2.809 | 1.615 to 4.886 |
| Albumin (per g/L) | −0.0621 | 0.0292 | 4.53 | 0.033 | 0.940 | 0.888 to 0.995 |
| Constant | −2.848 | 1.228 | 5.38 | 0.020 |
- 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.
- Odds ratio = eB = e0.895 = 2.45: smokers have 2.45 times the odds of a complication.
- 95% CI = eB ± 1.96 × SE = e0.8954 ± 1.96 × 0.2803 = e0.346 to e1.444 = 1.41 to 4.24.
- Wald χ² = (B ÷ SE)² = (0.8954 ÷ 0.2803)² = 10.20 on 1 df, p = 0.001.
- 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.
- 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%.
- Whole model: −2LL 374.07 → 333.77, likelihood ratio χ² 40.29 on 4 df, p < 0.001. Nagelkerke R² 0.158.
- 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.
- Events per variable: 71 ÷ 4 = 17.8.
In a real paper
Logistic regression in two published prediction models
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.
doi:10.1136/bmj-2025-084521 · PMID 41786356 · Free full text (PMC12961586)
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.
“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.”
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.
| Reported | Value | What it means |
|---|---|---|
| C statistic, development (optimism adjusted) | 0.73 (0.70 to 0.77) | Discrimination after correction for overfitting by bootstrapping |
| C statistic, ECLIPSE | 0.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, ECLIPSE | 0.92 (0.79 to 1.05) | Predicted risks slightly too spread out |
| Uniform shrinkage factor | 0.873 | Every coefficient was multiplied by 0.873 to correct for overfitting |
| OR, respiratory admission in previous 12 months | 3.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 |
- 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.
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.
doi:10.1016/j.eclinm.2023.101977 · PMID 37152361 · Free full text (PMC10154953)
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.
“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).”
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.
| Reported | Value | What it means |
|---|---|---|
| Adjusted OR, large infarct | 40.90 (20.20–82.80) | A binary predictor with a very large odds ratio and a wide interval |
| Adjusted OR, NIHSS score | 1.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, recanalisation | 0.36 (0.17–0.75) | Below 1: lower odds of malignant oedema |
| Intercept | −6.208 | Log-odds when every predictor is 0, needed to calculate a risk |
| AUC, derivation cohort | 0.94 (0.92–0.95) | Discrimination in the patients used to build the model |
| Hosmer–Lemeshow test | χ² = 6.38, df = 8, p = 0.60 | No evidence of lack of fit, which is not proof of good calibration |
- 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
- 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.
- 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.
- For the C statistic, save the predicted probabilities (Save), then use Analyze > Classify > ROC Curve.
- Unordered outcome: Analyze > Regression > Multinomial Logistic Regression. Ordered outcome: Analyze > Regression > Ordinal, which offers a Test of parallel lines.
- 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
- Analyses → Regression → 2 Outcomes (binomial). For more categories: N Outcomes (multinomial) or Ordinal Outcomes.
- Move the outcome to Dependent Variable, measurements to Covariates and categorical predictors to Factors. Set reference levels under Reference levels.
- 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.
An anastomotic leak score built in a tertiary centre is applied in a district hospital where leaks are less common.
Discrimination may hold while calibration fails: the score can predict too many leaks. Check a calibration plot in the new hospital before using its risks.
Risk factors for amputation in diabetic foot ulcer: 25 amputations, 12 candidate predictors.
About 2 events per candidate predictor. Reduce the candidate list from clinical knowledge before analysis, and consider Firth's method if a category has no events.
Factors associated with caesarean delivery in a hospital where 35% of women have a caesarean section.
The outcome is common, so an odds ratio of 2 is a much smaller risk ratio. Report odds ratios as odds ratios, or estimate risk ratios directly.
A case-control study of late-onset neonatal sepsis, each case matched to two controls of the same gestational age.
Use conditional logistic regression with the matched set as the stratum. Gestational age cannot then be estimated as a risk factor.
Outcome at 90 days on the modified Rankin scale (0 to 6) after two treatments for stroke.
Ordinal logistic regression uses the whole scale and gives one common odds ratio. Check that the odds ratios at each cut-point are similar.
Reason for stopping an antipsychotic: side effects, lack of effect, or non-adherence, with the drug as the predictor.
Unordered categories need multinomial logistic regression, with one odds ratio for each reason against a reference reason.
A survey of hypertension awareness, present in 40% of adults, compared across education groups.
With a prevalence this high the prevalence odds ratio is further from 1 than the prevalence ratio. Say which one you report.
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
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.
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.
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.
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.
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
- 1944
Joseph Berkson
Published "Application of the logistic function to bio-assay" in the Journal of the American Statistical Association.
- 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.
- 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.
- 1979
Ross Prentice and Ronald Pyke
Published "Logistic disease incidence models and case-control studies" in Biometrika.
- 1980
David Hosmer and Stanley Lemeshow
Published "Goodness of fit tests for the multiple logistic regression model".
- 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.
- 1996
Peter Peduzzi and colleagues
Simulated logistic models and found biased coefficients and incorrect confidence limits with fewer than 10 events per variable.
- 2002
Georg Heinze and Michael Schemper
Showed that Firth's penalised likelihood gives finite estimates when separation makes maximum likelihood estimates diverge.
- 2016
Maarten van Smeden and colleagues
Concluded that the evidence supporting events-per-variable rules for binary logistic regression is weak.
- 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.
- 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
“Depending on the type of model, describe how predictors were handled in the analyses (functional form, rescaling, transformation, or any standardisation)”.
“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”.
“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”.
“Report model performance estimates with confidence intervals, including for any key subgroups (eg, sociodemographic). Consider plots to aid presentation”.
“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”
The chance of something happening, as in "the odds are against it".
A ratio: the probability of an event divided by the probability of no event. A risk of 20% is odds of 0.25.
“Calibration”
Adjusting an instrument, such as a weighing scale, so that it reads correctly.
Agreement between the risks a model predicts and the risks observed in patients.
“Logistic”
Logistics: transport, supplies, organising.
The model in which the log-odds of an outcome is a linear combination of predictors.
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- 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.
- Why not linear regression: a straight line can predict probabilities below 0 or above 1, and the outcome is not normally distributed.
- 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.
- 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 χ².
- 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.
- 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.
- 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.
- Uses: adjusted odds ratios for risk factors in cohort, cross-sectional and case-control studies, and prediction scores for individual risk.
- 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.
- 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.
- 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.
- ×1Logistic regression
Further reading