How to use the logistic regression calculator
- Paste one case per line: one to five predictor values, then the outcome 0 or 1 last. Separate them with commas, spaces or tabs.
- Optionally name the predictors, and enter values to predict the chance of a 1 for a new case.
- Read the coefficients, odds ratios and their intervals, then the likelihood ratio test and pseudo R squared.
- Open the advanced option to change the cutoff used in the table of hits and misses.
Formula
P(y = 1) = 1 / (1 + exp(-(b0 + b1 x1 + ... + bk xk)))
Newton step: b <- b + (X' W X)^-1 X' (y - p), with W = diag(p (1 - p))
Standard error of b_j = sqrt of the j-th diagonal of (X' W X)^-1
Odds ratio = exp(b_j); interval = exp(b_j plus or minus 1.96 x SE)
LR chi-square = 2 (logL - logL0), McFadden R^2 = 1 - logL / logL0, AIC = 2 (k + 1) - 2 logL
logL0 is the log-likelihood of a model with only an intercept. The p values for coefficients use the Wald z statistic, and the LR test uses chi-square with k degrees of freedom.
Hours studied and passing
Twenty students: hours studied from 0.5 to 5.5 with a pass (1) or fail (0) result. The fit gives an intercept of -4.0777 and a coefficient of 1.5046 for hours (standard error 0.6287, p = 0.0167). The odds ratio is 4.5026 with a 95% interval of 1.3131 to 15.4393.
The log-likelihood is -8.0299 against -13.8629 for the intercept-only model, so the likelihood ratio chi-square is 11.6661 (p = 0.0006), McFadden R squared is 0.4208 and AIC is 20.0598. For 3 hours the predicted chance of a pass is 60.74%. At a cutoff of 0.5, 8 passes and 8 fails are called correctly and 2 of each are missed.
Reading the coefficients
Logistic regression models the log odds of the outcome as a straight-line function of the predictors. A coefficient of 1.5046 means each extra hour adds 1.5046 to the log odds, which multiplies the odds of a 1 by exp(1.5046) = 4.50. With several predictors each odds ratio is "holding the others fixed".
The interval for the odds ratio is built from the Wald standard error. If it excludes 1, the data point to a real association at the 95% level. For a 2 by 2 table without a model, the odds ratio and relative risk calculator is simpler, and the linear regression calculator handles a numeric outcome.
Cautions
The model needs enough cases of each outcome. A common guide is at least 10 cases of the rarer outcome per predictor, though that is a rule of thumb. If one predictor separates all the 0s from all the 1s, the best coefficients are infinite and the page says so instead of reporting unstable numbers.
The table of hits and misses uses the same data that fit the model, so it is optimistic. See the confusion matrix metrics calculator for precision, recall and related measures of a table of counts. Predictions apply only within the range of the data.
Assumptions and limits
- Cases are independent, and the outcome is exactly 0 or 1.
- The log odds are a straight-line function of each predictor (no interactions or curves are added).
- There is no perfect separation and no predictor is a copy or exact combination of others.
- Coefficient p values and intervals use a large-sample approximation, so treat them as rough with few cases.
Frequently asked questions
Why does the page say the fit does not settle?
When the predictors split the 0s and 1s completely, the likelihood keeps improving as coefficients grow without limit. No finite best answer exists, so the page stops and suggests more varied data or fewer predictors.
What is McFadden R squared?
It compares the log-likelihood of your model with that of a model that uses only the overall rate of 1s. Values are lower than ordinary R squared would be, and it is meant for comparing models on the same data, not for judging a single model against a fixed scale.
Can I add category predictors?
Recode each category as its own 0 or 1 column, leaving one category out as the baseline. Each coefficient then compares that category with the baseline.
Is this the same output as statsmodels or R?
The coefficients, standard errors, log-likelihood and AIC agree with statsmodels Logit to many digits on the test data. Different packages may report z or chi-square forms of the coefficient test, but the maximum likelihood estimates are identical.