LearnLogistic Regression
Advanced11 min readSource-backed

Logistic Regression

Predict binary outcomes and estimate odds ratios using logistic regression — the standard method for clinical prediction models and risk factor analysis.

You'll learn

How to predict a binary outcome and correctly interpret odds ratios.

Use this when

Your outcome is binary — disease vs no disease, survived vs not.

Why Not Use Linear Regression for Binary Outcomes?

When your outcome is binary (yes/no, dead/alive, diabetic/non-diabetic), linear regression produces invalid predictions: values can fall outside 0–1 and residuals violate normality. Logistic regression solves this by modeling the probability of the outcome using a logistic (sigmoid) function.

log[ P(Y=1) / P(Y=0) ] = β₀ + β₁X₁ + β₂X₂ + ...

The left side is the log-odds (logit) of the outcome. The model always produces probabilities between 0 and 1.

Odds Ratios (OR)

In logistic regression, we interpret coefficients as odds ratios by exponentiating them: OR = e^β.

  • OR = 1.0: No association
  • OR > 1.0: The predictor increases the odds of the outcome (risk factor)
  • OR < 1.0: The predictor decreases the odds of the outcome (protective factor)
  • OR = 2.5: The odds of the outcome are 2.5× higher for each one-unit increase in X (or for exposed vs. unexposed)
  • Always report with 95% CI: if the CI excludes 1.0, the OR is statistically significant

Odds ratios are NOT the same as risk ratios (relative risk). When the outcome is common (prevalence > 10%), ORs overestimate the relative risk and should not be interpreted as risk ratios.

Model Fit and Discrimination

  • Hosmer-Lemeshow test: Formal test of calibration — are predicted probabilities close to observed? p > 0.05 suggests good calibration.
  • Nagelkerke R²: Pseudo-R² for logistic regression. Does not have the same interpretation as linear R².
  • C-statistic (AUC): Area under the ROC curve. Measures discrimination (ability to distinguish cases from non-cases). C = 0.5 (no better than chance), C = 0.7 (acceptable), C = 0.8 (excellent), C > 0.9 (outstanding).
  • Classification table: Shows sensitivity and specificity at a chosen cutoff.

Sample Size Requirements

Logistic regression requires a minimum of 10 events per predictor variable (EPV rule). If your outcome occurs in 5% of subjects, you need at least 200 subjects per predictor.

Example: You want to build a model with 5 predictors, and your event rate is 20% (20 events per 100 subjects). You need at least 5 × 10 / 0.20 = 250 subjects.

Read next

Scatter Plots and Linear Regression

Explore how scatter plots reveal relationships between variables, how to fit a regression line, and how to interpret the slope, intercept, and R² in plain language.

Intermediate9 min read
Read next