Answer
Logistic vs linear regression: when should you use which?
The short answer
Use linear regression when the outcome is a continuous number, such as weight or income, and logistic regression when it is binary, such as bought or did not buy. Logistic regression models the probability of the event, keeps predictions between 0 and 1, and gives coefficients that become odds ratios. A straight line fitted to a 0/1 outcome can predict impossible probabilities and assumes the effect is the same everywhere.
The outcome decides
The choice between logistic and linear regression depends on what you are predicting, not on your predictors. Both can use any mix of continuous and categorical predictors, and both are fitted and read in similar ways. What differs is the outcome they are built for.
- Linear regression models the mean of a continuous outcome as a straight-line function of the predictors: blood pressure, test score, sales in dollars. A coefficient is the change in the outcome, in its own units, for a one-unit change in the predictor.
- Logistic regression models the probability of a binary outcome: passed or failed, churned or stayed, bought or did not buy. It fits a straight line on the log-odds scale, log(p/(1 - p)), and the logistic curve turns that into a probability between 0 and 1.
- Logistic coefficients are changes in the log-odds. Exponentiated, each one is an odds ratio: the factor by which the odds of the event are multiplied for a one-unit increase in the predictor.
- Other outcomes need other models: counts call for Poisson or negative binomial regression, ordered categories for ordinal logistic regression, and three or more unordered categories for multinomial logistic regression.
What goes wrong with a straight line for a 0/1 outcome
Nothing stops you running ordinary least squares on an outcome coded 0 and 1. The result is called a linear probability model, and its fitted values are read as probabilities. It has known problems:
- Impossible predictions. A straight line keeps rising, so for extreme predictor values it predicts probabilities below 0 or above 1.
- A constant effect. The line says one more unit of the predictor always adds the same number of percentage points. Real probabilities usually change slowly near 0 and 1 and quickly in between, which is the S-shape logistic regression builds in.
- Wrong standard errors. The variance of a 0/1 outcome is p(1 - p), which changes with the predictors, so the constant-variance assumption fails by construction. Ordinary standard errors and p values are then unreliable; robust (heteroskedasticity-consistent) standard errors are needed.
- Residuals that cannot be normal. For any given predictor value, a residual can take only two values.
The linear probability model is not useless. When fitted probabilities stay roughly between .2 and .8, its slope is easy to read as a change in percentage points and is often close to the average effect from a logistic model, which is why some fields, especially economics, use it with robust standard errors. For predicting individual probabilities, or when the outcome is rare or near-certain for some people, logistic regression is the safer choice.
Side by side in R and Python
The example simulates 300 customers, their number of website visits last month (0 to 20) and whether they bought something, with the true probability following a logistic curve. It fits a linear probability model and a logistic regression to the same data. The Python tab uses scikit-learn; setting C=np.inf removes its default penalty so the estimates are plain maximum likelihood, which matches R's glm() to several decimal places on identical data. Standard errors are computed by hand because scikit-learn does not report them.
R
set.seed(808)
n <- 300
visits <- round(runif(n, 0, 20)) # website visits last month
buy <- rbinom(n, 1, plogis(-4 + 0.4 * visits)) # yes/no outcome; true model is logistic
lpm <- lm(buy ~ visits) # linear regression (linear probability model)
logit <- glm(buy ~ visits, family = binomial) # logistic regression
round(rbind(linear = coef(lpm), logistic = coef(logit)), 3)
# The straight line runs past 0 and 1 at the extremes
round(range(fitted(lpm)), 3)
sum(fitted(lpm) < 0 | fitted(lpm) > 1) # people with an impossible "probability"
# Predicted probability of buying at 0, 5, 10, 15 and 20 visits
new <- data.frame(visits = c(0, 5, 10, 15, 20))
round(rbind(linear = predict(lpm, new),
logistic = predict(logit, new, type = "response")), 3)
# Logistic slope as an odds ratio per extra visit, with a Wald 95% CI
b <- coef(summary(logit))["visits", ]
round(c(b[1:3], OR = exp(b[[1]]),
lower = exp(b[[1]] - 1.96 * b[[2]]), upper = exp(b[[1]] + 1.96 * b[[2]])), 3)
format.pval(b[[4]], digits = 3)
# Average change in probability per visit: logistic vs the linear slope
round(c(logistic_AME = mean(dlogis(predict(logit))) * coef(logit)[["visits"]],
linear_slope = coef(lpm)[["visits"]]), 4)
Python
import numpy as np
from scipy import stats
from scipy.special import expit
from sklearn.linear_model import LinearRegression, LogisticRegression
rng = np.random.default_rng(808)
n = 300
visits = np.round(rng.uniform(0, 20, n)) # website visits last month
buy = rng.binomial(1, expit(-4 + 0.4 * visits)) # yes/no outcome; true model is logistic
X = visits.reshape(-1, 1)
lpm = LinearRegression().fit(X, buy) # linear regression (linear probability model)
# C=np.inf switches off sklearn's default penalty, so this is plain maximum likelihood, as in R's glm()
logit = LogisticRegression(C=np.inf, tol=1e-10, max_iter=1000).fit(X, buy)
b_lin = np.array([lpm.intercept_, lpm.coef_[0]])
b_log = np.array([logit.intercept_[0], logit.coef_[0, 0]])
print("linear ", np.round(b_lin, 3), "\nlogistic", np.round(b_log, 3))
# The straight line runs past 0 and 1 at the extremes
fit_lin = lpm.predict(X)
print("range of linear fitted values", np.round([fit_lin.min(), fit_lin.max()], 3))
print("impossible 'probabilities':", int(np.sum((fit_lin < 0) | (fit_lin > 1))))
# Predicted probability of buying at 0, 5, 10, 15 and 20 visits
new = np.array([[0], [5], [10], [15], [20]])
print("linear ", np.round(lpm.predict(new), 3))
print("logistic", np.round(logit.predict_proba(new)[:, 1], 3))
# Logistic slope as an odds ratio per extra visit, with a Wald 95% CI
Xd = np.column_stack([np.ones(n), visits])
p = expit(Xd @ b_log)
se = np.sqrt(np.diag(np.linalg.inv(Xd.T @ (Xd * (p * (1 - p))[:, None]))))
z = b_log[1] / se[1]
print("b", round(b_log[1], 3), "SE", round(se[1], 3), "z", round(z, 3), "p", 2 * stats.norm.sf(abs(z)))
print("OR", round(np.exp(b_log[1]), 3), "CI", np.round(np.exp(b_log[1] + np.array([-1.96, 1.96]) * se[1]), 3))
# Average change in probability per visit: logistic vs the linear slope
print("logistic AME", round(np.mean(p * (1 - p)) * b_log[1], 4), " linear slope", round(b_lin[1], 4))
The figures below come from one seeded run of the R code. Python's random numbers differ from R's, so its figures differ slightly (for example 60 impossible predictions instead of 71, and an odds ratio of 1.437 instead of 1.570), but the pattern is the same.
- Impossible probabilities. The linear model's fitted values run from -0.132 to 1.105, and 71 of the 300 customers get a value outside 0 to 1. The logistic predictions range from .009 at 0 visits to .987 at 20 visits.
- Constant vs changing effects. The linear slope says every visit adds 0.062 to the probability of buying. The logistic model says the effect depends on where you start: the predicted probability moves only from .009 to .083 between 0 and 5 visits, but from .083 to .463 between 5 and 10.
- Odds ratio. The logistic slope is b = 0.451 (SE = 0.049, z = 9.225), so each extra visit multiplies the odds of buying by 1.570, 95% CI [1.427, 1.728].
- Average effect. Averaged over the 300 customers, the logistic model implies that one more visit raises the probability of buying by 0.0473, compared with the linear slope of 0.0619. Here the outcome is close to 0 or 1 for many customers, so the two summaries disagree more than they would in the middle of the curve.
Related choices people ask about
- Logistic regression or a chi-square test? A chi-square test checks whether two categorical variables are associated. Logistic regression can do the same, and also handles continuous predictors, several predictors at once and adjustment for confounders, with odds ratios and confidence intervals. With one binary predictor the two usually give very similar p values.
- Logistic regression or a support vector machine? Both can separate two classes. Logistic regression gives probabilities and interpretable coefficients; a standard SVM gives class labels from a decision boundary and needs an extra calibration step to give probabilities. SVMs with nonlinear kernels can fit more complex boundaries, at the cost of interpretability.
- Logit or probit? Both handle binary outcomes and give almost the same predictions; logit is usually preferred because its coefficients become odds ratios. See the page on logit vs probit for details.
- Odds ratio or relative risk? An odds ratio from logistic regression is not a risk ratio. With a common outcome it lies further from 1, so do not describe it as times as likely.
How to report logistic regression in APA style (7th edition)
Name the model, how the outcome was coded and how the confidence intervals were computed in the method section. Using the logistic model above:
"A binary logistic regression showed that the number of website visits predicted purchasing, b = 0.45, SE = 0.05, z = 9.23, p < .001. Each additional visit was associated with 1.57 times higher odds of buying, OR = 1.57, 95% CI [1.43, 1.73]."
For a linear regression, report b, SE, t and p for each predictor, plus R² and the overall F test. In a table of logistic results, give each predictor's b, SE, p and odds ratio with its 95% CI, and list the sample size and the number of events in a note. Predicted probabilities at a few meaningful predictor values help readers see the size of the effect.
Related tools and guides
- APA 7 formatter for regression
- Which statistical test should I use?
- Logit vs probit: which should you use?
- How do you interpret regression output in R?
- Logistic regression (Wikipedia)
- Linear probability model (Wikipedia)
More answered questions
- What is propensity score matching, and when should you use it?
- Why is accuracy a poor way to judge a classification model?
- What is AUC? The area under the ROC curve, explained
Working with your own data?
General answers only go so far. Send us your situation and we'll reply by email within two business days.
Ask your questionDrafted with AI assistance and reviewed by Nedim Yel, PhD, research methodologist at DASS. This is general information, not advice for your specific data or study. When the results matter, check your approach with a qualified statistician.