Logistic regression: how to calculate and interpret probabilities and odds ratios
Learn how a logit model turns predictors into binary-outcome probabilities, why an odds ratio is not a probability multiplier, and how to request predicted probabilities in R.
Logistic regression estimates the probability of a two-category outcome—such as whether a customer buys or leaves—from explanatory variables. Instead of fitting a straight line directly to probability, it transforms probability into odds and log-odds, then models log-odds as a linear expression of the predictors. A coefficient is therefore not a percentage-point change in probability, and an exponentiated coefficient (an odds ratio) does not mean that probability is multiplied by that amount.
This article explains logistic regression with the logit link for a binary outcome and shows the basic flow for fitting a model with R's glm() and checking predicted probabilities. The key is to translate model numbers back to the probability in the reader's question and to distinguish prediction from causal claims.
Why does a binary outcome need a different regression model?
Linear regression is natural for explaining the mean of a continuous outcome. But a straight line fitted to 0/1 data can predict values below 0 or above 1, outside the range of a probability. Also, the same numerical change in a prediction can mean something different near probability 0.5 than near 0.02.
Logistic regression uses a function that maps predictions back into the interval from 0 to 1. For example, a team could estimate a visitor's purchase probability from visit counts and purchase completion. A yes/no outcome is a common use case, but the model does not by itself reveal what caused a purchase. First decide whether the goal is to predict probabilities or explain relationships between variables.
How are probability, odds, and log-odds different?
If the probability of an event is p, the probability that it does not happen is 1-p. Odds are the ratio of these two probabilities:
odds = p / (1 - p)A probability of 0.20 is 20%; its odds are 0.20 / 0.80 = 0.25, a success-to-failure ratio of 1 to 4. Probability and odds are different scales. Probability runs from 0 to 1, while odds can grow from 0 without an upper bound. UCLA's statistical teaching material defines odds as the ratio of the probability of success to the probability of failure, and defines the logit as the natural logarithm of odds.
Taking the natural logarithm of odds gives log-odds, or the logit:
logit(p) = log(p / (1 - p))Although p is between 0 and 1, the logit can range from negative to positive infinity. That lets us model it with a linear expression in the predictors. The inverse transformation back to probability is:
p = 1 / (1 + exp(-z))
z = β₀ + β₁X₁ + ... + βₖXₖHere z is the linear predictor formed from the variables and coefficients. The model is linear on the log-odds scale, but probability can follow an S-shaped curve as a predictor changes. R's binomial family uses the logit link by default and also supports alternatives such as probit and complementary log-log. The calculations and code below use the default logit. (R documentation: Family Objects for Models; UCLA model explanation)
How should you read a coefficient and an odds ratio?
Suppose the model is:
logit(p) = β₀ + β₁XWhen X increases by one unit, log-odds change by β₁, holding the other modeled conditions constant. The exponentiated coefficient, exp(β₁), is the odds ratio (OR). For a numeric predictor it is the conditional odds ratio for a one-unit increase; for a 0/1 predictor it usually compares the odds in the group coded 1 with the reference group coded 0. In a model with multiple predictors, the comparison is conditional on the other included variables.
`OR = 1` means the model implies no odds difference for that change.
`OR > 1` means higher odds; `OR < 1` means lower odds.
`OR = 2` means the odds double. It does not mean probability doubles.
The meaning of “one unit” depends on how a numeric variable is measured. One visit and one minute of time are different changes. Changing units changes the coefficient and the one-unit OR, but the interpretation remains consistent when you compare the same real-world change. For a categorical variable, check the reference category. With an interaction, one variable's relationship depends on the value of another, so do not read one coefficient as a common effect for every group.
Work through how an odds ratio changes probability
The following is a hypothetical example to demonstrate the calculation, not an observed study or product result. Suppose the baseline probability of purchase under one set of conditions is 10%, and the comparison condition has an odds ratio of 2.
| Step | Calculation | Value |
|---|---|---|
| Baseline probability | p | 0.10 (10%) |
| Baseline odds | p / (1-p) | 0.10 / 0.90 = 1/9 |
| Doubled odds | baseline odds × OR | 2/9 |
| Probability in comparison condition | convert odds back to probability | (2/9) / (1 + 2/9) = 2/11 |
| Probability difference | 18.2% - 10% | about 8.2 percentage points |
So in this example, doubling the odds moves probability from 10% to about 18.2%, not to 20%. The probability difference from a given odds ratio changes with the baseline probability. In general, if the baseline probability is p and the odds ratio is OR, the comparison probability is:
comparison probability = OR × p / (1 - p + OR × p)This conversion helps interpret a predicted probability for a specified case. In a model with several predictors, converting an odds ratio directly into an average population probability difference requires calculating predictions for relevant combinations of variables and defining the average of interest.
Fit a model and check probabilities in R
This example uses glm() from base R's stats package. Assume train contains training data, test contains new data, purchased is coded 1 for a purchase and 0 otherwise, and visits is the visit count.
model <- glm(
purchased ~ visits,
data = train,
family = binomial(link = "logit")
)
summary(model) # coefficients are on the log-odds scale
exp(coef(model)) # convert coefficients to odds ratios
predicted_probability <- predict(
model,
newdata = test,
type = "response"
)
range(predicted_probability, na.rm = TRUE)type = "response" returns predictions on the response scale, which means probabilities for a binomial logit model. The default prediction scale is the linear predictor, or log-odds. R's official predict.glm() documentation distinguishes these scales, so specify type = "response" when you need probabilities. Checking that range() is between 0 and 1 is a basic check that the returned values are on a probability scale; it does not show that the model is accurate or useful.
If the outcome is a count of successes and failures rather than a 0/1 value, R can take a two-column matrix as the response. For a proportion response, pass the number of trials per row through weights. With a factor response, the level order affects which outcome R treats as success, so check the levels and define which outcome is success before fitting. (R documentation: Family Objects for Models, Fitting Generalized Linear Models, Predict Method for GLM Fits)
Do not confuse predicted probabilities with class labels
A predicted probability answers how likely the event is estimated to be under the case's conditions. Applying a threshold to turn that probability into yes/no is a separate decision. A threshold of 0.5 can be a convenient starting point, but it is not right for every situation. Consider the cost of false positives and false negatives, the intended use, operating capacity, and other constraints.
For a prediction task, evaluate the model on validation data that were not used to choose the model, rather than looking only at fit to training data. Check whether predicted probabilities broadly match observed event rates (calibration), whether the model distinguishes events from non-events as the task requires, and whether it provides practical improvement over a simple baseline. If the output drives a classification decision, also examine how false positives and false negatives change with the threshold. For an explanatory task, report uncertainty as well as coefficients and odds ratios, and state variable coding and included conditions.
Limits and reporting cautions
Logistic regression assumes that the specified linear combination of predictors relates to log-odds. If the actual relationship bends or varies with another predictor, nonlinear terms or interactions may be appropriate. Adding terms can make interpretation harder and overfit the sample, so choose them based on the question and validation results.
R's official glm() documentation describes a warning that can occur when fitted probabilities in a binomial model are numerically 0 or 1. If it appears, do not simply hide the message: check outcome coding, rare categories, sample size, combinations of predictors, and convergence, and assess whether estimates and uncertainty are stable. The cause and remedy depend on the data; removing a warning alone does not make a model valid.
An observed odds ratio above 1 does not show that a variable caused the outcome. Unmeasured confounding, selection bias, measurement, and time order may explain a relationship. If the question is causal, research design and identification assumptions matter before the regression equation.
Report the success/failure definition and reference categories, predictor units, conditions in the model, the change represented by each odds ratio, uncertainty intervals, and—if predicting—the validation data and evaluation approach. Showing predicted probabilities for representative baseline conditions helps readers distinguish an odds ratio from an actual probability change.
References
[R: Family Objects for Models](https://stat.ethz.ch/R-manual/R-devel/library/stats/html/family.html)
[R: Fitting Generalized Linear Models](https://www.stat.ethz.ch/R-manual/R-devel/library/stats/html/glm.html)
[R: Predict Method for GLM Fits](https://www.stat.ethz.ch/R-manual/R-devel/library/stats/html/predict.glm.html)
[UCLA: How do I interpret odds ratios in logistic regression?](https://stats.oarc.ucla.edu/stata/faq/how-do-i-interpret-odds-ratios-in-logistic-regression/)
[UCLA: Logistic Regression in Stata — odds, logits, and coefficients](https://stats.oarc.ucla.edu/wp-content/uploads/2025/05/logistic_regression_stata.html)