Guides  /  logistic regression

Logistic regression: a complete guide

Logistic regression predicts a yes-or-no outcome, and almost everything confusing about it comes down to one thing: the coefficients are on a log-odds scale nobody thinks in. This guide explains why that scale is necessary, how to convert coefficients into something interpretable, what the assumptions actually are, and how to report the model so a reader can follow it.

Hafiz Ahmad Tariq Written and reviewed by Hafiz Ahmad Tariq, Senior Biostatistician
Updated 17 August 202620 min read
What is logistic regression?

Logistic regression is a statistical model that predicts a binary outcome — such as pass or fail, readmitted or not — from one or more predictor variables. Instead of predicting the outcome directly, it models the probability of the outcome occurring, transformed onto a log-odds scale so the relationship can be expressed as a linear equation. Coefficients are exponentiated to give odds ratios, which describe how the odds of the outcome change per unit of the predictor.

Definition

What logistic regression does

Logistic regression predicts the probability of a binary outcome from one or more predictors. The outcome is a yes or no: passed or failed, readmitted or not, purchased or did not.

The crucial move is that the model does not predict the outcome. It predicts the probability of the outcome, and it does so in a way that guarantees the prediction stays between 0 and 1 — which, as it turns out, ordinary regression cannot do.

1.0 0.5 0.0 linear fit — predicts p > 1 and p < 0 logistic curve — bounded in [0, 1] Every observed outcome is either 0 or 1. The curve models the PROBABILITY of a 1, not the outcome itself. predictor
Observed outcomes are all 0 or 1. The logistic curve models the probability of a 1 and is bounded; a straight line is not, and predicts impossible values at the extremes.
Linear regressionLogistic regression
OutcomeContinuousBinary
PredictsThe value itselfThe probability of the outcome
Equation is linear inThe outcomeThe log odds
Coefficient meansChange in outcome per unitChange in log odds per unit
Reported asb, sometimes standardisedexp(b), an odds ratio
It is still a regression

Everything you know about regression carries over: you can include multiple predictors, control for covariates, test interactions and compare nested models. Only the link between predictors and outcome changes.

Rationale

Why not just use linear regression?

Fitting a straight line to a 0/1 outcome is technically possible and produces three specific problems, each fatal on its own.

Impossible predictions — a line extends indefinitely, so it will predict probabilities above 1 and below 0 for extreme predictor values
Non-constant variance — the variance of a binary outcome is p(1−p), which depends on p, so the homoscedasticity assumption fails by construction
Non-normal residuals — with only two possible outcomes the residuals cannot be normally distributed at any given predictor value

The relationship is also genuinely non-linear in a substantive sense. Moving from a 50% to a 60% chance is a very different change from moving from 95% to 99%, even though both are a 10-point and a 4-point shift respectively. The logistic curve is steep in the middle and flat at the ends, which matches how probabilities actually behave: they are hardest to shift when they are already near certainty.

The linear probability model has defenders

In economics you will see linear regression applied to binary outcomes deliberately, with robust standard errors, because the coefficients read directly as percentage-point changes. It is a defensible choice in some settings. In health, psychology and education, logistic regression is the expectation, and departing from it needs justifying.

The scale

Odds, log odds and the logit

This is the section worth reading twice, because every interpretive difficulty in logistic regression traces back to it.

probability 0 to 1 odds 0 to ∞ log odds (logit) −∞ to +∞ p/(1−p) ln The model is linear on the RIGHT-HAND scale. That is the whole trick. Coefficients come out as log odds — exponentiate to get an odds ratio you can interpret. exp(b) = odds ratio   —   b = 0.99 → OR = 2.70
Probability is bounded at both ends; odds are bounded at zero; log odds are unbounded. Only the last of these can be modelled with a straight line.

Probability and odds are not the same thing

ProbabilityOddsLog odds
0.100.11 (1 to 9)−2.20
0.250.33 (1 to 3)−1.10
0.501.00 (evens)0.00
0.753.00 (3 to 1)1.10
0.909.00 (9 to 1)2.20

odds = p / (1 − p) and logit = ln(odds). Note the symmetry in the final column: log odds are centred on zero and symmetric around it, which is exactly the property a linear model needs.

The model itself is therefore:

ln(p / (1−p)) = b₀ + b₁x₁ + b₂x₂ + …

Why coefficients need exponentiating

The b values come out as changes in log odds, which nobody has an intuition for. Exponentiating converts them to odds ratios: exp(b). A coefficient of 0.99 becomes an odds ratio of 2.70, meaning the odds of the outcome are 2.7 times higher per unit increase in the predictor.

Worked example

Worked example: interpreting a model

A study predicts whether students pass a statistics module from weekly study hours and whether they attended a support workshop. The model returns:

PredictorbSEWaldpexp(b)95% CI for OR
Intercept−2.800.6121.07<.0010.06
Study hours0.420.1114.58<.0011.52[1.23, 1.89]
Workshop (yes)0.990.348.48.0042.69[1.38, 5.24]

Reading each row

Study hours: exp(0.42) = 1.52. Each additional hour of weekly study multiplies the odds of passing by 1.52 — a 52% increase in the odds. The interval [1.23, 1.89] excludes 1, so the effect is significant.

Workshop: exp(0.99) = 2.69. Students who attended the workshop had odds of passing about 2.7 times those of students who did not, holding study hours constant.

Intercept: exp(−2.80) = 0.06, the odds of passing for a student with zero study hours who did not attend. That converts to a probability of 0.06 / 1.06 = 0.057, or about 6%.

Turning the model into a prediction

For a student studying 6 hours per week who attended the workshop:

logit = −2.80 + (0.42 × 6) + (0.99 × 1) = −2.80 + 2.52 + 0.99 = 0.71

odds = e⁰·⁷¹ = 2.034, so p = 2.034 / 3.034 = 0.670 — about a 67% chance of passing.

The intercept is often meaningless as stated

Here it describes a student who studies zero hours, which may not exist in your data. Centring continuous predictors on their mean makes the intercept interpretable as the outcome for an average case, and is worth doing routinely.

Interpretation

Reading coefficients and odds ratios

exp(b)DirectionMeaning
> 1Increases the odds1.52 = 52% higher odds per unit
= 1No effectThe predictor tells you nothing
< 1Decreases the odds0.65 = 35% lower odds per unit

There is a second scale worth knowing about, because reviewers in some fields ask for it. Marginal effects express the model's output as a change in probability rather than in odds, evaluated either at the average case or averaged across every case in the sample. The advantage is immediate interpretability — “attending the workshop raised the probability of passing by 18 percentage points” is a sentence anyone can read. The cost is that the number depends on where in the distribution you evaluate it, because the logistic curve is steep in the middle and flat at the ends. The same predictor can shift the probability by 20 points for a borderline student and by 2 for one already almost certain to pass. Report marginal effects when the audience is non-technical, and always say at what values they were computed.

The mistake almost everyone makes

An odds ratio of 2.7 does not mean the outcome is 2.7 times more likely. It means the odds are 2.7 times higher, and odds and probability diverge sharply once the outcome is common.

Baseline probabilityOR = 2.0 givesRisk ratio
0.050.0951.90 — close to the OR
0.200.3331.67
0.500.6671.33 — far from the OR
0.800.8891.11 — nothing like the OR

When the outcome is rare, the odds ratio approximates the risk ratio well and the loose phrasing does little harm. When it is common, the odds ratio substantially overstates the relative risk, and treating them as interchangeable exaggerates your finding.

Always give the confidence interval

An odds ratio without an interval is uninterpretable. Note that the interval is computed on the log-odds scale and then exponentiated, which is why it is asymmetric around the point estimate — [1.38, 5.24] around 2.69, not equal distances either side. That asymmetry is correct, not an error.

Get the odds ratio with its interval

Our odds ratio calculator computes the OR and its 95% confidence interval alongside the risk ratio, so you can report whichever your design calls for.

Use the calculator

Assumptions

Assumptions, and what to check

Logistic regression drops the normality and homoscedasticity requirements of linear regression, but it does not drop everything.

AssumptionHow to checkIf violated
Binary outcomeInspect the variableUse multinomial or ordinal logistic regression
Independent observationsStudy designUse a mixed-effects or GEE model
Linearity in the logitBox-Tidwell test, or plot by quantileAdd a quadratic term or categorise the predictor
No severe multicollinearityVIF above about 5–10Drop or combine predictors
No complete separationHuge coefficients and enormous SEsUse penalised (Firth) logistic regression
Adequate events per variableCount the rarer outcomeReduce predictors or collect more data

Multicollinearity behaves the same way it does in linear regression and produces the same symptom: coefficients that swing wildly when a predictor is added or removed, with inflated standard errors. The model as a whole may still predict well — collinearity damages the individual coefficients rather than the overall fit — so if prediction is your goal it may not matter much. If your question is which predictor matters, it matters a great deal.

Complete separation

If a predictor perfectly divides the outcome — everyone above a certain score passed, everyone below failed — the maximum likelihood estimate does not exist. The software will return a coefficient of implausible size with a standard error in the hundreds, and may or may not warn you. This is not a strong finding; it is a failure to converge. Firth's penalised likelihood is the standard remedy.

Linearity applies to the logit, not the outcome

You are not checking whether the predictor relates linearly to the 0/1 outcome — it cannot. You are checking whether it relates linearly to the log odds. A predictor whose effect accelerates at high values will violate this, and the fix is usually a transformation or a quadratic term.

Fit

Model fit and classification

MeasureWhat it tells youNote
Omnibus / likelihood ratio testDoes the model beat the intercept alone?Report this first
−2 log likelihoodModel devianceOnly useful for comparing nested models
Nagelkerke R²Pseudo variance explainedNot a real R²; do not over-interpret
Hosmer-LemeshowCalibration of predicted vs observedSensitive to sample size; unreliable when large
AUC / c-statisticDiscrimination between outcomes0.5 is chance, 0.7 acceptable, 0.8 good
Classification tableAccuracy at a chosen cut-offMisleading with imbalanced outcomes

Why accuracy can be a trap

If 95% of your sample passes, a model predicting “pass” for everyone is 95% accurate and completely useless. Report sensitivity and specificity separately, and prefer the AUC, which assesses discrimination across every possible cut-off rather than one arbitrary threshold.

Get sensitivity, specificity and the rest computed

Our sensitivity and specificity calculator returns the full set of classification measures with confidence intervals from a 2×2 table.

Use the calculator

Sample size

Sample size and the events-per-variable rule

Logistic regression is more demanding of sample size than linear regression, and what matters is not the total N but the number of cases in the less common outcome category.

The traditional guidance is at least 10 events per predictor variable. With 5 predictors you need at least 50 cases in the smaller outcome group — not 50 participants overall.

PredictorsMinimum events (EPV 10)Total N if 20% event rate
220100
440200
660300
10100500

More recent work suggests the rule of 10 is too crude — sometimes conservative, sometimes badly optimistic depending on the event rate and the predictor distributions. Treat it as a floor rather than a target, and where the model matters, run a proper sample size calculation.

What happens when you ignore it

Too few events per variable produces coefficients biased away from the null, standard errors that are too small, and a model that will not replicate. It is one of the most common reasons a promising prediction model fails on new data.

Settle the sample size before you collect data

Send your design and expected event rate. A named statistician calculates the sample you need for the model you intend to fit, while it is still possible to act on the answer.

See sample size and power

Pitfalls

Seven mistakes that cost marks

1. Reading an odds ratio as a risk ratio

“2.7 times more likely” is wrong unless the outcome is rare. Say “the odds were 2.7 times higher”.

2. Reporting b instead of exp(b)

Raw coefficients are log odds and are not interpretable. Exponentiate them.

3. Omitting the confidence interval

An odds ratio alone gives no sense of precision. Always report the interval.

4. Treating Nagelkerke R² as variance explained

It is a pseudo-R² on a different scale from the linear-model version and is not comparable to it.

5. Ignoring complete separation

Enormous coefficients with enormous standard errors mean the model did not converge, not that you found a powerful predictor.

6. Too many predictors for the number of events

Check events per variable before fitting, not after.

7. Reporting overall accuracy on imbalanced data

Give sensitivity, specificity and the AUC instead.

reporting">

Reporting

Reporting logistic regression in APA style

ElementHow to write it
Model testχ²(2, N = 210) = 38.42, p < .001
A predictorb = 0.42, SE = 0.11, Wald = 14.58, p < .001, OR = 1.52, 95% CI [1.23, 1.89]
Model fitNagelkerke R² = .24
DiscriminationAUC = .78, 95% CI [.71, .85]
Report the omnibus test before individual predictors
Give b, SE, OR and the interval for every predictor
State the reference category for each categorical predictor
Say how many events there were, not just total N
Report a fit measure and a discrimination measure
Note any convergence problems or remedial steps such as Firth's correction
A sentence that earns marks

“A binary logistic regression predicting pass/fail from weekly study hours and workshop attendance was significant, χ²(2, N = 210) = 38.42, p < .001, Nagelkerke R² = .24. Each additional study hour was associated with 52% higher odds of passing (OR = 1.52, 95% CI [1.23, 1.89]), and workshop attendance with 2.69 times the odds (95% CI [1.38, 5.24]). Of 210 students, 84 failed, giving 42 events per predictor.”

Have your model built and interpreted

Send your dataset and research question. A named statistician fits the model, checks separation and collinearity, and returns annotated output with the odds ratios interpreted in plain language.

See statistical consultancy

Answers

Frequently asked questions

What is logistic regression used for?

Predicting a binary outcome — pass or fail, readmitted or not, converted or not — from one or more predictor variables. It models the probability of the outcome rather than the outcome itself, which keeps predictions between 0 and 1 and allows several predictors to be assessed simultaneously.

Why can't I use linear regression for a yes/no outcome?

Because a straight line is unbounded and will predict probabilities above 1 and below 0. The variance of a binary outcome also depends on the probability itself, so the constant-variance assumption fails by construction, and residuals cannot be normally distributed when only two outcomes exist.

What is the difference between an odds ratio and a risk ratio?

The risk ratio compares probabilities; the odds ratio compares odds. They are close when the outcome is rare and diverge sharply when it is common. An odds ratio of 2.0 with a baseline probability of 0.5 corresponds to a risk ratio of only 1.33, so describing an OR as 'times more likely' overstates the effect.

How do I interpret a logistic regression coefficient?

Exponentiate it. The raw coefficient b is a change in log odds, which has no intuitive meaning; exp(b) is an odds ratio. An exp(b) of 1.52 means each one-unit increase in the predictor multiplies the odds of the outcome by 1.52, a 52% increase in the odds.

What sample size do I need for logistic regression?

What matters is the number of cases in the less common outcome category, not the total. The traditional rule is at least 10 such events per predictor, so a model with 5 predictors needs at least 50 events. Treat that as a floor; recent work shows it can be optimistic depending on the event rate.

What is complete separation?

When a predictor perfectly divides the outcome, so that everyone above some value has one result and everyone below the other. The maximum likelihood estimate then does not exist, and software returns implausibly large coefficients with enormous standard errors. Firth's penalised logistic regression is the usual fix.

What is a good Nagelkerke R squared?

There is no accepted threshold, and it should not be read as variance explained in the way a linear-model R squared is. Values in logistic regression are typically much lower than researchers expect. Discrimination measures such as the AUC are usually more informative for judging whether a model is useful.

Can logistic regression handle more than two outcome categories?

Not in its binary form. Use multinomial logistic regression for unordered categories such as choice of course, and ordinal logistic regression for ordered ones such as low, medium and high. Both extend the same underlying logic.

Send the data. Get a fixed quote.

Attach your dataset or just describe the project. A named statistician replies with a price and a deadline, usually within one working day.