Logistic Regression

Statistics
Introduced by
David Roxbee Cox
Year
1958
Type
Method
Family
classification-prediction

What does it do?

Logistic regression models the probability of a binary outcome (for example, disease present or absent, success or failure) as a function of continuous and categorical predictors.

Its origin is usually traced to David Roxbee Cox's 1958 analysis of binary sequences, which applies a logistic transformation so that predicted probabilities stay within the [0,1] interval. It is widely used in epidemiology, medicine, and the social sciences to estimate adjusted associations, quantify odds ratios, and predict the probability of an outcome for individuals.

The intuition behind the method

Ordinary linear regression predicts unbounded continuous values, so applying it to a 0/1 outcome can produce impossible predictions such as a probability of 1.5. Logistic regression avoids this by modelling the log-odds (logit) of the outcome as a linear function of the predictors: logit(p) = ln[p/(1−p)] = β₀ + β₁X₁ + β₂X₂ + ... The logistic transformation maps any linear predictor back to a probability between 0 and 1. Each coefficient therefore describes a change in log-odds, which is most often reported after exponentiation as an odds ratio.

History

David Roxbee Cox's 1958 paper on the regression analysis of binary sequences introduced the logistic model for binary outcomes as an extension of regression methods. Later developments include penalized logistic regression (ridge and lasso, Tibshirani, 1996), its place within generalized linear models (McCullagh & Nelder, 1989), and multinomial and ordinal extensions (Agresti, 2015).

When to use it

Choose logistic regression when the outcome is binary and the goal is either to estimate adjusted associations, typically as odds ratios, or to predict the probability of the outcome for individuals. Typical uses include diagnostic or prognostic prediction from clinical findings, adjusted epidemiological association studies, and yes/no survey responses. Do not use it for a continuous outcome, for which linear regression is appropriate, or for an outcome with more than two unordered categories, which calls for multinomial regression. For time-to-event data, use Cox regression, and for clustered observations (for example, patients within hospitals), use a multilevel logistic model rather than the single-level model.

Limitations and considerations

  • Highly correlated predictors inflate standard errors and make individual coefficients unstable, so variance inflation factors are commonly examined.
  • The model assumes that the log-odds are linear in each predictor; nonlinear associations are missed unless they are modelled explicitly.
  • When the outcome is rare, maximum likelihood estimates can be biased and confidence intervals can become very wide, which motivates penalized estimation or alternative sampling designs.
  • Odds ratios are not collapsible, so an adjusted OR can differ in magnitude from a crude OR even when no confounding is present, and it should not be read as a risk ratio when the outcome is common.
  • Classification performance depends on the chosen probability cutoff, and the cutoff that maximizes sensitivity will generally reduce specificity.
  • The model assumes independent observations; clustered data, such as patients within hospitals, violate this assumption, and a multilevel logistic model is then needed.

Source conditions do not replace independent scientific review or validation by an analysis engine.

Strengths

  • The model estimates the probability of the outcome directly, which supports risk stratification and threshold-based decisions.
  • Because the outcome is assumed to follow a binomial distribution conditional on the predictors, no normality assumption is needed for the residuals, which is a key difference from linear regression.
  • The exponentiated coefficient exp(β) is a constant multiplicative effect on the odds across the range of the predictor on the logit scale, which makes odds ratios straightforward to report.
  • Continuous and categorical predictors, interaction terms, and nonlinear terms such as polynomials or splines can be included in the linear predictor.
  • Because the output is a probability, the classification cutoff can be chosen to suit the relative costs of false positives and false negatives in a given application.

Applications

  • Clinical risk prediction, such as estimating 30-day readmission risk or sepsis likelihood, to guide resource allocation and early intervention.
  • Diagnostic accuracy studies, in which the probability of disease is modelled from clinical findings, laboratory values, or imaging results, and the resulting classifier's sensitivity and specificity are evaluated.
  • Treatment response modelling, estimating the probability of success for a medication or surgical procedure to inform treatment selection.
  • Epidemiological association studies, estimating odds of disease associated with exposures such as smoking, diet, or occupational hazards while adjusting for demographic and other confounders.
  • Manufacturing quality control, predicting the probability of a product defect from process parameters to guide adjustments that reduce failures.

How it works

How it works

1

Define the outcome as a binary variable coded 0/1 and collect the predictors. The number of outcome events should be adequate for the number of predictors being estimated. Maximum likelihood estimates tend to be unstable unless sample sizes are fairly large, and this matters most when one outcome group is small, for example with a 95% vs 5% split between groups, or when the probability of the outcome is around 10% or less. No single events-per-predictor rule is universally adequate, so check the required sample size with simulation or a power analysis, and be cautious when events are few. Code categorical predictors with k−1 dummy variables for k categories, and check that observations are independent, because the standard model does not account for clustering. Bivariate plots or cross-tabulations of each predictor against the outcome help guide model specification before fitting.

2

Coefficients are estimated by maximum likelihood, not ordinary least squares, choosing the β values that make the observed 0/1 data most probable. Software reports the coefficients on the logit scale, the odds ratios OR = exp(β), standard errors and z-statistics (z = β/SE), and confidence intervals for each OR, typically exp(β ± 1.96 × SE) for 95% intervals. Overall fit is commonly assessed with the Hosmer-Lemeshow test, which compares observed and predicted outcome counts across risk groups. A p-value above 0.05 means the test found no evidence of miscalibration; it does not confirm that the model fits, because the test has limited power and its result depends on how the groups are formed. Overall discrimination is assessed with the area under the ROC curve (AUC), where 0.5 corresponds to chance-level discrimination. Calibration plots by risk group, together with the AUC and the residual and influence checks described below, give a fuller picture of fit.

3

An odds ratio gives the multiplicative change in the odds of the outcome for a one-unit increase in a predictor, holding the other predictors constant; an OR of 1 indicates no association. If the confidence interval excludes 1, the association is conventionally called statistically significant. The predicted probability for an individual is 1 / [1 + exp(−(β₀ + β₁X₁ + ...))]. ROC curves plot sensitivity against 1 − specificity across cutoffs and help select a classification threshold. Nested models can be compared with a likelihood ratio test, where −2 × (log-likelihood of reduced − log-likelihood of full) is referred to a χ² distribution with degrees of freedom equal to the number of removed parameters. Residuals and influence measures (including Pregibon influence) are used to look for outliers and misspecification.

Common pitfalls

  • Odds ratios from logistic regression are adjusted associations. Unmeasured confounding and reverse causation can still explain them, so causal wording needs separate justification from study design.
  • On imbalanced data, overall accuracy can be high for a model that predicts the majority class for everyone; AUC, sensitivity, specificity, and positive predictive value give a fuller picture.
  • Reporting p-values without odds ratios and their confidence intervals hides the size and precision of the association.
  • A significant Hosmer-Lemeshow test or unusual residual patterns signal misspecification, such as a missing nonlinear term or interaction, and should be investigated rather than ignored.
  • Fitting many predictors relative to the number of outcome events produces overfitted models with optimistic performance estimates; cross-validation or external validation is needed to check performance.
  • Dichotomizing a continuous predictor (for example, at a single age cutoff) discards information and tends to produce unstable estimates; keeping the continuous form or using restricted cubic splines is usually preferable.
  • Complete or quasi-complete separation, where a predictor or combination of predictors perfectly or nearly perfectly predicts the outcome, prevents maximum likelihood from converging and produces infinite or very large coefficients and standard errors. Check software convergence warnings and cross-tabulations of predictors against the outcome, and consider penalized estimation or collapsing categories.

Frequently asked questions

How do I interpret an odds ratio of 2.5 with a 95% CI of [1.8, 3.5]?

An OR of 2.5 means that the odds of the outcome are 2.5 times higher for a one-unit increase in that predictor, or for the indexed category compared with the reference category if the predictor is categorical, after adjusting for the other predictors. The 95% confidence interval [1.8, 3.5] indicates the range of values compatible with the data at that confidence level. Because the interval excludes 1, the association is conventionally called statistically significant. Whether a 2.5-fold difference in odds matters clinically or practically depends on the baseline risk of the outcome and the context, and an OR should not be read as a relative risk when the outcome is common.

What does the Hosmer-Lemeshow test tell me, and when should I worry about a low p-value?

The Hosmer-Lemeshow test compares observed outcome counts with predicted counts across groups of individuals ordered by predicted risk. A p-value above 0.05 means the test found no evidence of miscalibration; it does not confirm that the model fits, because the test has limited power and its result depends on how the groups are formed. A p-value below 0.05 suggests that the model misfits in some risk groups, which may point to a missing nonlinear term, an interaction, or influential observations. Inspecting a calibration plot by risk group, alongside discrimination and residual checks, is usually more informative than the test alone, particularly in large samples where small departures can become statistically detectable.

How do I choose a probability cutoff for classifying individuals as at-risk or not?

The choice depends on the clinical or policy context and on the relative costs of false positives and false negatives. The ROC curve plots sensitivity against 1 − specificity across all possible cutoffs. The default cutoff of 0.5 is not necessarily appropriate. When missing true cases is more costly, a lower cutoff that favours sensitivity is usually chosen; when unnecessary interventions are costly, a higher cutoff that favours specificity is preferred. The Youden index (sensitivity + specificity − 1) is one summary criterion, and positive and negative predictive values in the target population should also be considered.

How does logistic regression differ from linear regression for a binary outcome?

Linear regression can predict values outside the 0 to 1 range, and its residuals cannot be normally distributed because the outcome takes only two values. Its residual variance also changes with the mean, since for a binary outcome the variance is p(1 − p), so the usual constant-variance assumption fails. Logistic regression models the probability through the logit link, assumes a binomial conditional distribution, and estimates coefficients by maximum likelihood. Linear probability models are sometimes used in practice, especially for approximate effect estimates, but when they are used, standard errors should be robust to heteroscedasticity and predictions outside [0, 1] must be handled.

Related methods

Sources

  1. Cox, D. R. (1958). The regression analysis of binary sequences. Journal of the Royal Statistical Society, Series B, 20(2), 215–242.

    Open DOI reference
  2. Hosmer, D. W., Lemeshow, S., & Sturdivant, R. X. (2013). Applied Logistic Regression (3rd ed.). John Wiley & Sons.

    Open DOI reference