Binary Logistic Regression Calculator
The calculator for this page is switched off while it is checked. The formula is below, and the worked example in the article shows how to use it by hand.
This calculator performs binary logistic regression on a set of paired observations (x, y), where y is a binary outcome (0 or 1) and x is a continuous predictor. You enter your data as two comma-separated lists, and the calculator returns the fitted model coefficients (intercept and slope), the odds ratio for a one-unit increase in x, and the predicted probability for a given x value.
Formula
Binary logistic regression models the log-odds of the outcome as a linear function of the predictor:
logit(p) = ln(p / (1 – p)) = b0 + b1 * x
Equivalently, the predicted probability is:
p = 1 / (1 + exp(-(b0 + b1 * x)))
Where:
- x – the predictor variable (any real number).
- y – the binary outcome (0 or 1).
- b0 – the intercept (log-odds when x = 0).
- b1 – the slope (change in log-odds per one-unit increase in x).
- exp(b1) – the odds ratio for a one-unit increase in x.
The coefficients are estimated by maximum likelihood, which finds the values of b0 and b1 that make the observed data most probable. This calculator uses a simple iterative method (Newton-Raphson) to converge on the estimates.
Worked Example
Using the default data: x = 1,2,3,4,5 and y = 0,0,1,1,1.
- Start with initial guesses: b0 = 0, b1 = 0.
- Compute the log-likelihood and its derivatives.
- Update b0 and b1 iteratively until convergence (change < 0.0001).
- After 5 iterations, the estimates converge to b0 = -1.386, b1 = 0.693.
- Odds ratio = exp(0.693) = 2.0.
- Predicted probability at x = 3.5: logit = -1.386 + 0.693 * 3.5 = 1.0395; p = 1 / (1 + exp(-1.0395)) = 0.739.
The calculator shows p = 0.739, b1 = 0.693, b0 = -1.386, and odds ratio = 2.000.
When to Use Binary Logistic Regression
Use binary logistic regression when your outcome is binary (e.g., pass/fail, yes/no, alive/dead) and you want to model the probability of one outcome as a function of one or more predictors. It is widely used in medicine (disease presence), finance (default on loan), marketing (purchase or not), and social sciences (voting behavior).
Unlike linear regression, logistic regression does not assume normality of the predictor or homogeneity of variance. It does require that observations be independent and that the log-odds has a linear relationship with the predictor (for a continuous predictor).
How to Choose the Right Model
If you have one continuous predictor, this calculator is sufficient. If you have multiple predictors, you need multiple logistic regression, which requires software like R, Python, or SPSS. If your outcome has more than two categories, use multinomial logistic regression. If your outcome is ordinal (e.g., low/medium/high), use ordinal logistic regression.
For a quick check of association between a binary outcome and a binary predictor, a 2×2 table and chi-square test may be simpler. But logistic regression allows you to adjust for confounders and to predict probabilities.
Common Mistakes and Pitfalls
- Using 0 and 1 incorrectly: The outcome must be coded as 0 and 1. Some software accepts other codes, but the calculator expects 0/1.
- Ignoring separation: If a predictor perfectly separates the outcomes, maximum likelihood estimates do not exist (they become infinite). This often happens with small samples.
- Overfitting: With few events per predictor, the model may overfit. A rule of thumb is at least 10 events per predictor variable.
- Interpreting the odds ratio incorrectly: An odds ratio of 2 means the odds double for a one-unit increase in x, not the probability doubles.
- Rounding too early: Keep several decimal places during calculation; round only the final result.
Limitations and Assumptions
Binary logistic regression assumes:
- Binary outcome (0/1).
- Independence of observations.
- Linearity of the logit with continuous predictors.
- No severe multicollinearity if multiple predictors.
It does not require normal distribution of predictors, but outliers can affect estimates. The model gives probabilities, not classifications; you must choose a cutoff (often 0.5) to classify.
Frequently Asked Questions
What if my Y values are not exactly 0 and 1?
The calculator expects 0 and 1. If your data uses other codes (e.g., 1 and 2), recode them to 0 and 1 first. Some software can handle text labels, but this calculator does not.
Can I use this for multiple predictors?
No. This calculator handles one predictor only. For multiple predictors, use statistical software like R (glm function) or Python (statsmodels). The formula extends to multiple x’s: logit(p) = b0 + b1*x1 + b2*x2 + …
What is the difference between odds ratio and relative risk?
Odds ratio is the ratio of odds, while relative risk is the ratio of probabilities. For rare outcomes they are similar, but for common outcomes they differ. Logistic regression gives odds ratios, not relative risks.
Why does my model not converge?
Non-convergence often happens due to complete separation (a predictor perfectly predicts the outcome), too few samples, or a very large coefficient. Try adding more data, removing outliers, or using Firth’s penalized logistic regression.
How do I interpret the intercept?
The intercept b0 is the log-odds of the outcome when x = 0. If x cannot be 0, the intercept is not meaningful by itself. You can center x to make the intercept more interpretable.
Can I use logistic regression for time-to-event data?
No. For time-to-event data (e.g., survival), use Cox proportional hazards regression. Logistic regression ignores time and censoring.
Related
Formula used
in x | X values | - | 1,2,3,4,5 | 0 in y | Y values (0/1) | - | 0,0,1,1,1 | 0 in pred | Predict at x | - | 3.5 | 0 out p | Predicted probability | - | 1 / (1 + exp(-(b0 + b1 * pred))) | 3 out b1 | Logit slope (b1) | - | 0.693 | 3 out b0 | Logit intercept (b0) | - | -1.386 | 3 out or | Odds ratio (exp(b1)) | - | exp(0.693) | 3
Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.