Logistic regression models the relationship between one or more predictors and a binary outcome, an outcome with two categories such as alive or dead, relapsed or not, responded or not. Instead of predicting the outcome directly, it predicts the log odds of the outcome and converts each predictor's effect into an odds ratio. That is why logistic regression is the default tool whenever the thing you are trying to explain is a yes-or-no event rather than a measured quantity.
When the outcome is binary, ordinary linear regression breaks in concrete ways: it can predict probabilities below zero and above one, and its assumptions about the residuals are violated because a two-value outcome cannot be normally distributed around a line. Logistic regression solves this with the logit link, which transforms a probability bounded between zero and one into a log-odds scale that runs from minus to plus infinity. The model is linear on that log-odds scale, which keeps predictions inside the valid probability range and gives the coefficients a clean interpretation. Choosing logistic over linear is therefore not a stylistic preference; it follows directly from the type of outcome variable you have.
Reading the output: coefficients and odds ratios
A logistic regression coefficient is on the log-odds scale, which is hard to interpret directly, so you exponentiate it to get an odds ratio. The rule of thumb is simple:
- An odds ratio of 1 means the predictor has no association with the outcome.
- An odds ratio above 1 means higher values of the predictor increase the odds of the outcome.
- An odds ratio below 1 means higher values decrease the odds.
For a binary predictor, the odds ratio compares the two groups; for a continuous predictor, it gives the change in odds for a one-unit increase. When you want to sanity-check a model's odds ratio against a simple two-by-two table, our odds ratio calculator gives the unadjusted value and its confidence interval, which is a useful baseline before you trust the adjusted estimate.
A persistent source of error is treating the odds ratio as if it were a relative risk. The two diverge as the outcome becomes common: an odds ratio of 2 can correspond to a much smaller increase in actual risk when the outcome is frequent. For rare outcomes the two are close, which is why case-control studies can use the odds ratio as a stand-in for risk, but for common outcomes the gap is real and reporting an odds ratio as though it were a risk overstates the effect. If your audience needs an interpretable risk, our explainer on risk ratios shows when each measure is appropriate.
Most analyses move from univariable models, one predictor at a time, to a multivariable logistic regression that includes several predictors together. The multivariable model is what lets you report the effect of an exposure adjusted for confounders, the central goal of most observational analysis. Building it well means deciding in advance which variables to include based on subject knowledge rather than letting an automated stepwise procedure churn through the data, which inflates false findings. A common planning rule is to allow roughly ten outcome events per predictor so the model is not overfit.
Logistic regression has fewer assumptions than linear regression, but the ones it has are easy to violate:
- Independence of observations. Clustered or repeated data need a model that accounts for the clustering, not a plain logistic regression.
- Linearity in the logit. Continuous predictors are assumed to have a linear relationship with the log odds; if they do not, the predictor may need transformation or a spline.
- No extreme multicollinearity. Predictors that are near-duplicates inflate standard errors and destabilize the coefficients.
- Adequate events per variable. Too few outcome events for the number of predictors produces unstable, overfit estimates.
Checking these is part of the analysis, not an optional extra, and skipping them is how a published odds ratio turns out to be an artifact.
When the outcome has more than two categories, multinomial logistic regression generalizes the model; when the categories are ordered, ordinal logistic regression uses that ordering. When the outcome is a count rather than a binary event, you move to Poisson or negative binomial models instead. Recognizing which member of the family fits your outcome is the same kind of design decision as converting between effect sizes when you pool results: the right tool is dictated by the data, and using the wrong one quietly biases everything downstream.
The model written out, and how it is fitted
Behind the odds ratios sits a compact equation. Logistic regression models the log odds of the outcome as a linear function of the predictors:
logit(p) = ln( p / (1 - p) ) = b0 + b1*x1 + b2*x2 + ... + bk*xk
Rearranging for the probability gives the logistic (sigmoid) function, which is what forces every prediction back inside the zero-to-one range:
p = 1 / ( 1 + exp( -(b0 + b1*x1 + ... + bk*xk) ) )
Unlike linear regression, there is no closed-form solution for these coefficients. They are estimated by maximum likelihood, which searches for the values that make the observed pattern of ones and zeros most probable. Software finds them iteratively, almost always through a Newton-Raphson routine that statisticians call iteratively reweighted least squares, repeating until the estimates stop moving. When you read that a model "failed to converge", this is the loop that did not settle, and the cause is usually sparse data or separation, not a coding mistake.
Two quantities from that fit do most of the inferential work. The deviance measures how far the fitted model sits from a perfect fit, and the difference in deviance between two nested models is a likelihood-ratio test of whether the extra predictors earn their place. For a single coefficient the software shows a Wald test by default, but the likelihood-ratio test is more trustworthy in small samples and when an odds ratio is large, so prefer it whenever the two disagree.
If a predictor splits the outcome perfectly, or almost perfectly, for instance every patient above a threshold had the event and none below it did, maximum likelihood has no finite answer and the coefficient is pushed toward plus or minus infinity. This is complete or quasi-complete separation, and it surfaces as an enormous odds ratio with a standard error larger still, or a warning that fitted probabilities of zero or one occurred. The fix is not to delete the offending variable. The standard remedy is Firth's penalized likelihood, which adds a small bias-reducing penalty (the Jeffreys prior) and returns finite, well-behaved estimates; for very sparse tables, exact logistic regression is the alternative.
library(logistf) # Firth's bias-reduced logistic regression
fit <- logistf(event ~ exposure + age + sex, data = d)
summary(fit) # finite estimates with profile-penalized intervals
Why the adjusted and unadjusted odds ratio differ even without confounding
Researchers expect an odds ratio to move when a confounder is added and to stay put when an irrelevant variable is added. The odds ratio breaks that expectation, because it is non-collapsible: adjusting for a genuine predictor of the outcome changes the odds ratio even when that predictor is unrelated to the exposure and so confounds nothing. The conditional (adjusted) odds ratio is pulled away from the marginal (population-average) odds ratio purely by the mathematics of the odds scale. This has two consequences. First, you cannot read a shift in the odds ratio between models as evidence of confounding the way you can with a risk ratio or risk difference, both of which are collapsible. Second, if the quantity you care about is the population-average effect, report an average marginal effect or a marginal odds ratio obtained by g-computation rather than the raw coefficient. Stating plainly whether your odds ratio is conditional or marginal is the kind of precision a methods reviewer looks for.
Judging the model: discrimination and calibration, not just p-values
A model with significant coefficients can still predict badly. Two distinct properties decide whether it is any good. Discrimination is how well the model separates those who had the event from those who did not, summarised by the concordance statistic, which equals the area under the receiver operating characteristic curve: 0.5 is a coin toss and values toward 1.0 are better. Calibration is whether the predicted probabilities match observed frequencies, for example whether events actually occur about 30 percent of the time among people the model assigned a risk of 0.3. Inspect calibration with a calibration plot and the calibration slope and intercept; the once-standard Hosmer-Lemeshow test is now discouraged, because its verdict depends on an arbitrary number of groups and it has weak power. For a model built to predict rather than to explain, validate it on data it has not seen, or internally by bootstrapping to estimate optimism, and report it against the TRIPOD reporting guideline.
The familiar rule of roughly ten outcome events per predictor is a rough floor, not a guarantee. Simulation work by van Smeden and colleagues shows that the events-per-variable count alone does not determine whether estimates are stable: the number of candidate predictors, the outcome fraction, and the strength of the real effects all matter, and a well-calibrated model sometimes needs more. When events are scarce relative to predictors, do not force a large model. Penalized estimation shrinks coefficients toward zero and trades a little bias for much lower variance: ridge regression (an L2 penalty) keeps every predictor, the least absolute shrinkage and selection operator (a penalty that can set coefficients to exactly zero) performs selection, and Firth's penalty doubles as a small-sample correction. For matched case-control designs, use conditional logistic regression so the matching is respected; for clustered or repeated outcomes, use a mixed-effects logistic model or generalized estimating equations with cluster-robust standard errors rather than a plain fit that wrongly treats correlated observations as independent.
# Multivariable logistic regression with continuous and binary predictors
fit <- glm(event ~ age + sex + biomarker, data = d, family = binomial)
# Odds ratios with profile-likelihood confidence intervals
exp(cbind(OR = coef(fit), confint(fit)))
# Likelihood-ratio test for the whole model
anova(fit, test = 'LRT')
# Check linearity in the logit for a continuous predictor using a spline
library(splines)
fit_spline <- glm(event ~ ns(age, 3) + sex + biomarker, data = d, family = binomial)
anova(fit, fit_spline, test = 'LRT') # significant means the straight line is too simple
# Discrimination: area under the ROC curve
library(pROC)
auc(d$event, predict(fit, type = 'response'))
Logistic regression is approachable enough to run with a few clicks and subtle enough to get wrong in ways reviewers catch: an unchecked linearity assumption, an overfit model, an odds ratio reported as a risk. If your analysis has to survive statistical review, having a biostatistician build and validate the model is usually faster than fixing it after a reviewer flags it. A professional statistical analysis service can handle the modeling and validation end to end.