Logistic Regression Calculator
Fit a binary-outcome model by maximum likelihood (IRLS) — coefficients, odds ratios, Wald tests, pseudo-R² and predicted probabilities.
| Pass (y = 1) | Fail (y = 0) | |
|---|---|---|
| Control (x = 0) | ||
| Treated (x = 1) |
The predictor is treatment (0 = control, 1 = treated) and the outcome is pass (1) or fail (0).
Predicted probability p = 0.8773
Each extra hour multiplies the odds of passing by 1.89.
How it was worked out
Coefficients, fit and classification
The coefficient table gives the Wald test for each term; the classification table uses a 0.5 cut-off, and the curve shows the fitted probabilities against the observed 0/1 outcomes.
Logistic regression predicts a yes/no outcome — pass or fail, buy or not, disease or healthy — from one or more predictors. It models the log-odds, so each coefficient becomes an odds ratio you can read directly. This calculator fits the model by maximum likelihood, reports Wald tests and pseudo-R², and turns any predictor value into a predicted probability.
How to use the logistic regression calculator
- Choose a mode: Paste data for one predictor and a 0/1 outcome (one pair per line, predictor and outcome separated by a comma), or 2×2 table for weighted counts (control vs treated, pass vs fail).
- Give the predictor a name — for example “Hours studied” — and choose the significance level (α).
- Click Calculate, or press Load Example 1 / Load Example 2 to see the worked examples below run live.
- Read the headline odds ratio, then check the coefficient table (Wald z and p), the fit statistics (log-likelihood, deviance, AIC, pseudo-R²), and the classification table at the 0.5 cut-off. Use Predict for x to turn any predictor value into a predicted probability.
Try it now: load Example 1 (hours studied vs exam pass, n = 20). The calculator gives an intercept of −3.1231 and a slope of 0.6362, so each extra hour of study multiplies the odds of passing by 1.89 (95% CI [1.10, 3.25]). A student who studies 8 hours has a predicted probability of passing of 0.8773.
When should you use logistic regression?
Use logistic regression when your outcome is binary (yes/no, pass/fail, diseased/healthy) and you want to know how one or more predictors change the probability of the outcome. It is the right tool when:
- The outcome has exactly two values, coded 0 and 1.
- You want an odds ratio for each predictor — a single number that says how the odds change per unit of the predictor.
- You want a predicted probability for a given predictor value, not just a yes/no classification.
- You have enough data: a common rule is at least 10 events (the rarer outcome) per predictor.
- The relationship is linear in the log-odds — check this before trusting the fit (see the assumptions below).
If your outcome is continuous rather than binary, use linear regression (one predictor) or multiple regression (several predictors). If you only have a single 2×2 table and want the odds ratio without fitting a model, the odds ratio calculator gives it directly. If you only want to test whether two categorical variables are associated, with no predictor-outcome direction, use the chi-square test. And if you want the correlation between two continuous variables, use the correlation coefficient calculator. The p-value calculator and the z-test are the tools for turning a test statistic into a p-value.
How does logistic regression work?
Logistic regression models the probability p of the outcome (y = 1) through the logit link: logit(p) = ln(p / (1 − p)) = β₀ + β₁x. The left side is the log-odds; the right side is a straight line in the predictor, just like linear regression. Solving for p gives the logistic curve p = 1 / (1 + e−(β₀ + β₁x)), an S-shaped curve that stays between 0 and 1.
Each coefficient is a change in log-odds. Exponentiating turns it into an odds ratio: OR = eβ₁. An OR of 1.89 means each extra unit of the predictor multiplies the odds of the outcome by 1.89; an OR below 1 means the odds fall. The calculator fits the coefficients by maximum likelihood using iteratively reweighted least squares (IRLS), and tests each one with a Wald test: z = β / SE, with the p-value from the standard normal distribution.
Fit is summarised by the log-likelihood, the deviance (−2 × log-likelihood), AIC, and three pseudo-R² values. McFadden R² = 1 − LL / LL₀ is the share of the null deviance the model explains; Cox–Snell and Nagelkerke R² rescale it so the maximum is 1. None of them is a proportion of variance explained, so do not read them like the R² of linear regression. The classification table counts how many cases the model gets right at the 0.5 cut-off, with accuracy, sensitivity (share of true 1s caught) and specificity (share of true 0s caught).
Worked examples
Example 1 — hours studied and exam pass (n = 20)
Twenty students report how many hours they studied, and whether they passed (1) or failed (0). The data (hours, pass) are: 1,0 · 2,0 · 2,0 · 3,0 · 3,0 · 4,1 · 4,0 · 5,1 · 5,1 · 6,0 · 6,1 · 7,1 · 7,1 · 8,1 · 8,1 · 9,0 · 9,1 · 10,1 · 10,1 · 12,1. Twelve students passed and eight failed.
| Term | β | SE | z | p | OR | OR 95% CI |
|---|---|---|---|---|---|---|
| Intercept | −3.1231 | 1.5532 | −2.0107 | 0.0444 | 0.0440 | [0.0021, 0.9242] |
| Hours studied | 0.6362 | 0.2762 | 2.3039 | 0.0212 | 1.8893 | [1.0996, 3.2462] |
Fit: log-likelihood −8.7587 (null −13.4602), deviance 17.5173, AIC 21.5173, McFadden R² 0.3493, Cox–Snell R² 0.3751, Nagelkerke R² 0.5071. The IRLS fit converged in 6 iterations.
Predicted probabilities: 3 hours → 0.2289; 5 hours → 0.5145; 8 hours → 0.8773. At the 0.5 cut-off the model classifies 17 of 20 students correctly (accuracy 0.85, sensitivity 0.9167, specificity 0.75; TP 11, TN 6, FP 2, FN 1). Interpretation: each extra hour of study multiplies the odds of passing by 1.89, and the 95% CI [1.10, 3.25] excludes 1, so the effect is significant (p = 0.0212). A student who studies 8 hours has an 88% predicted chance of passing.
Example 2 — treatment vs control (2×2 table, n = 60)
Sixty patients are randomised to a control group or a treatment group, and the outcome is pass or fail. Control: 8 pass, 22 fail. Treated: 18 pass, 12 fail.
| Pass | Fail | Total | |
|---|---|---|---|
| Control | 8 | 22 | 30 |
| Treated | 18 | 12 | 30 |
| Total | 26 | 34 | 60 |
The fitted model is logit(p) = −1.0116 + 1.4171 × treatment. The odds ratio for treatment is OR = e1.4171 = 4.125, 95% CI [1.3867, 12.2704]. Hand cross-check: (18 × 22) / (12 × 8) = 396 / 96 = 4.125. Predicted probabilities: control 0.2667, treated 0.6. Interpretation: treatment multiplies the odds of passing by 4.13, and the CI excludes 1, so the effect is significant. At the 0.5 cut-off the model classifies 40 of 60 correctly (accuracy 0.6667, sensitivity 0.6923, specificity 0.6471).
How to interpret the results
- Odds ratio: the headline number. OR = 1 means no effect; OR > 1 means higher odds of the outcome as the predictor rises; OR < 1 means lower odds. Always read it with its 95% CI: if the interval includes 1, the effect is not significant at the 5% level.
- Coefficient (β): the change in log-odds per unit of the predictor. Its sign is the direction of the effect; its size is hard to read directly, which is why the odds ratio is the headline.
- Wald z and p: z = β / SE. If p < α, the predictor significantly predicts the outcome. With a small sample the Wald test can be conservative; the likelihood-ratio test is the more reliable alternative.
- Pseudo-R²: McFadden R² of 0.35 in Example 1 means the model explains 35% of the null deviance — a strong fit for a single predictor. Values of 0.2–0.4 are already good. Do not compare pseudo-R² with the R² of linear regression.
- Classification: accuracy is the share of cases the model gets right at the 0.5 cut-off. Sensitivity is the share of true 1s caught; specificity is the share of true 0s caught. A model can have high accuracy and still miss most of the rare outcome — check sensitivity and specificity separately.
- Predicted probability: the most useful number for a single case. It is the model’s estimate of p for that predictor value, and it is what you report when someone asks “what is the chance?”
Assumptions
- Binary outcome: the response has exactly two values (0 and 1). If it has more, use multinomial or ordinal logistic regression instead.
- Independent observations: each row is a separate case. Repeated measurements on the same subject need a mixed model or GEE.
- Linearity in the log-odds: the logit of p must be linear in each continuous predictor. Check it with a smoothed plot of the empirical logits, or by adding a squared term and seeing whether it helps.
- No complete separation: the predictor must not perfectly separate the two outcomes. If it does, the coefficients diverge and no finite standard errors exist — the calculator warns you and suggests Firth logistic regression.
- Enough events per predictor: at least 10 events (cases with the rarer outcome) per predictor, as a rule of thumb. Fewer than that and the estimates are unstable.
- No strong multicollinearity: with several predictors, check that they are not near-perfectly correlated; the standard errors blow up when they are.
How to report logistic regression (APA)
Report the coefficient (b), its standard error, the Wald z, the p-value and the odds ratio with its 95% confidence interval, then the model fit (McFadden R²) and the classification accuracy. Copy and adapt this sentence:
Logistic regression showed that hours studied significantly predicted passing, b = 0.64, SE = 0.28, z = 2.30, p =.021, OR = 1.89, 95% CI [1.10, 3.25]. The model explained 35% of the null deviance (McFadden R² =.35) and classified 85% of students correctly.
Cite this tool: Shafiq, A. (2026). Logistic Regression Calculator. Empirical Rule Calculators. https://empiricalrulecalculators.com/logistic-regression-calculator/
Frequently asked questions
When should I use logistic regression instead of linear regression?
Use logistic regression when the outcome is binary (yes/no, pass/fail). Linear regression assumes a continuous outcome and can predict probabilities below 0 or above 1, which makes no sense for a yes/no outcome. Logistic regression models the log-odds, so its predictions are always valid probabilities between 0 and 1. If the outcome is continuous, use linear regression instead.
How do I interpret an odds ratio?
An odds ratio (OR) says how the odds of the outcome change for a one-unit increase in the predictor. OR = 1.89 means the odds are multiplied by 1.89 (an 89% increase) per extra hour of study. OR = 1 means no effect; OR below 1 means the odds fall. Always read the OR with its 95% confidence interval: if the interval includes 1, the effect is not statistically significant. For a 2×2 table the OR is (a × d) / (b × c); the odds ratio calculator works it out for you.
What is pseudo-R², and why are there three of them?
Pseudo-R² measures how much better the fitted model is than a model with no predictors (the null model), using the log-likelihood instead of the variance. McFadden R² = 1 − LL / LL₀ is the most direct. Cox–Snell R² rescales it using the sample size, but it can never reach 1. Nagelkerke R² divides Cox–Snell by its maximum so that it can reach 1. All three are reported because different fields prefer different ones; they usually agree on whether the fit is weak or strong. None of them is a proportion of variance explained, so do not read 0.35 as “35% of the variance” — it is 35% of the null deviance.
What is complete separation, and what do I do about it?
Complete separation means the predictor perfectly separates the two outcomes — every case with y = 1 has a higher predictor value than every case with y = 0 (or vice versa). Then the maximum-likelihood coefficients run away to infinity, because a steeper and steeper curve always fits better. The calculator detects this and warns you instead of reporting meaningless numbers. The standard fix is Firth logistic regression, a penalised likelihood that gives finite estimates, or collecting more data so the groups overlap.
How many events per predictor do I need?
A common rule of thumb is at least 10 events per predictor, where an “event” is a case with the rarer outcome. In Example 1 there are 8 failures (the rarer outcome) and one predictor, so 8 events for one predictor — just below the rule of thumb, which is why the confidence interval is wide. With fewer events the coefficients and their standard errors become unstable, and separation becomes more likely. If you are short of events, simplify the model or use a penalised method.
Sources: Hosmer, D. W., Lemeshow, S., & Sturdivant, R. X. (2013). Applied Logistic Regression (3rd ed.). Wiley. McFadden, D. (1974). Conditional logit analysis of qualitative choice behavior. In P. Zarembka (Ed.), Frontiers in Econometrics. Academic Press. Cox, D. R., & Snell, E. J. (1989). Analysis of Binary Data (2nd ed.). Chapman & Hall. Nagelkerke, N. J. D. (1991). A note on a general definition of the coefficient of determination. Biometrika, 78(3), 691–692. All values on this page were verified against SciPy 1.11.4 distribution functions.
See all 106 free statistics tools on Empirical Rule Calculators.
Next steps
Keep going with the tools that pair with logistic regression — the regression family and odds ratios.
📊● LiveRegression
Linear Regression Calculator
Fit a straight line to two variables and read off the slope, intercept and R².
📊● LiveRegression
Multiple Regression Calculator
Predict one outcome from several predictors, with VIF and adjusted R².
🎲● LiveHypothesis Test
Odds Ratio Calculator
Turn a 2×2 table into an odds ratio and relative risk with confidence intervals.
More Tools to Explore
Keep going with the calculators that pair with logistic regression — the regression family, odds ratios and paired tests.
Linear Regression Calculator
Fit a straight line to two variables and read off the slope, intercept and R².
Try Calculator →Multiple Regression Calculator
Predict one outcome from several predictors, with VIF and adjusted R².
Try Calculator →Odds Ratio Calculator
Turn a 2×2 table into an odds ratio and relative risk with confidence intervals.
Try Calculator →Chi-Square Test Calculator
Test whether two categorical variables are associated.
Try Calculator →Correlation Coefficient Calculator
Measure the strength of a linear relationship between two variables.
Try Calculator →McNemar Test Calculator
Compare paired binary outcomes before and after a treatment.
Try Calculator →Explore All Tools
Browse all 106 free statistics tools — every calculator on this site in one place.
Browse All Tools