Logistic regression
Shown in the app as logistic_regression. Part of the method reference, under Regression.
When to use
Model a binary outcome from predictors, adjusting for covariates.
What you provide
- Outcome: one two-level column.
- Predictors: one or more columns.
Options
Missing data
- Complete case (listwise deletion)
- Mean imputation (single)
- Median imputation (single)
- Multiple imputation
Multiple comparisons
- Not adjustable for this method. Where it makes post-hoc comparisons, the procedure applies its own correction.
Confidence level
Every interval in the result is reported at the level you choose:
- 90%
- 95%
- 99%
Related methods
Other methods under Regression:
- Linear regression
- Firth penalised logistic regression
- Poisson regression
- Negative-binomial regression
- Ordinal logistic regression
- Multinomial logistic regression
- Factors associated with outcome (continuous outcome)
- Factors associated with outcome (binary outcome)
Guides that discuss this method
- How to choose a statistical test for your data
- Logistic regression: odds ratios and separation
- Odds ratio or relative risk: which to report?
How to read the output
Logistic regression models a yes/no outcome, for example whether a student passes an exam or whether a seedling survives a season, from one or more predictors.
Coefficients and odds ratios. Each coefficient is on the log-odds scale. Exponentiated, it is an odds ratio: for a numeric predictor, the multiplicative change in the odds of the outcome per one-unit increase; for a categorical predictor, the odds in that category relative to the reference category, which is always the first category (an ordered category is compared with its first level too, never fitted as a polynomial trend). Each is adjusted for the other predictors in the model. An odds ratio above 1 means higher odds and below 1 lower odds; read it with its confidence interval. The headline result is the odds ratio for the first predictor.
Intervals. Confidence intervals are profile-likelihood intervals, which stay accurate where the simpler estimate-plus-or-minus interval does not (small samples, odds ratios far from 1). You can choose a 90%, 95% or 99% level, and every interval in the result uses it. Under multiple imputation the intervals are Wald intervals pooled across the imputed datasets by Rubin’s rules, and the Methods text says so.
Testing a whole predictor. A categorical predictor with three or more levels has several contrasts, so each predictor is also tested as a whole with a likelihood-ratio test, and the whole model is tested against a model with no predictors. When the first predictor has three or more levels, read its whole-predictor test before the single contrast in the headline. These tests are not computed under multiple imputation.
Missing outcomes. With mean or median imputation, only missing predictor values are filled. A row with a missing outcome is dropped and counted, because filling a yes/no outcome with an average would invent an outcome.
An odds ratio is not a risk ratio. When the outcome is common, the odds ratio is further from 1 than the corresponding risk ratio, so avoid reading it as “times as likely”.
Checks to read alongside. With few events per estimated parameter, coefficients are unstable; a common rule of thumb asks for about 10 events of the rarer outcome per parameter (Peduzzi and colleagues, 1996). The calibration check asks whether predicted probabilities match the observed outcome rates (Hosmer and Lemeshow). If a predictor separates the outcomes perfectly, ordinary estimates do not exist; the predictor’s likelihood-ratio test is still reported, and Celeus flags the fit and offers penalised (Firth) logistic regression instead.
Survey designs. When the data come from a complex survey (sampling weights, and optionally PSUs, strata and a finite population correction), the model is fitted to the design: estimates are weighted to the surveyed population, standard errors use Taylor-series linearisation, and the odds ratio’s confidence interval uses t on the design’s degrees of freedom. Each predictor also gets a design-based Wald F test.
A subpopulation is analysed by restricting the design, not the data. The events-per-parameter check still counts the unweighted rows, the calibration check and the power estimate are not computed, and a penalised (Firth) model is not available under a design, so a separated model is flagged with advice to simplify it.
Sources: Hosmer DW, Lemeshow S, Sturdivant RX (2013), Applied Logistic Regression, 3rd ed., Wiley, doi:10.1002/9781118548387. Peduzzi P et al. (1996), Journal of Clinical Epidemiology 49(12):1373-1379, doi:10.1016/S0895-4356(96)00236-3. Lumley T (2004), “Analysis of complex survey samples”, Journal of Statistical Software 9(1):1-19.
Worked examples
Celeus's result on a published or illustrative dataset, next to an independent computation and, where one exists, a published value. The data themselves are not reproduced here.
datasets::mtcars
- Source: Published dataset distributed with an R package
- Licence: base R (GPL)
- Reference: Henderson & Velleman (1981)
| Quantity | Celeus | Independent computation | Published value | Agrees |
|---|---|---|---|---|
| Estimate | -8.08348 | -8.08348 | - | Yes |
| p-value | 0.00843381 | 0.00843381 | - | Yes |
logistf::sex2
- Source: Published dataset distributed with an R package
- Licence: logistf (GPL)
- Reference: Heinze G, Schemper M (2002), Statistics in Medicine 21:2409-2419 (the worked example); data from Cytel Inc., LogXact 9 user manual
| Quantity | Celeus | Independent computation | Published value | Agrees |
|---|---|---|---|---|
| Estimate | 16.7342 | 16.7342 | - | Yes |
| p-value | 0.983299 | 0.983299 | - | Yes |
MASS::birthwt
- Source: Published dataset distributed with an R package
- Licence: MASS (GPL)
- Reference: Hosmer & Lemeshow (1989), Applied Logistic Regression
| Quantity | Celeus | Independent computation | Published value | Agrees |
|---|---|---|---|---|
| Estimate | -0.0389946 | -0.0389946 | - | Yes |
| p-value | 0.23344 | 0.23344 | - | Yes |
datasets::mtcars
- Source: Published dataset distributed with an R package
- Licence: base R (GPL)
- Reference: Henderson & Velleman (1981); independent computation
| Quantity | Celeus | Independent computation | Published value | Agrees |
|---|---|---|---|---|
| Estimate | -4.02397 | -4.02397 | - | Yes |
| p-value | 0.0050882 | 0.0050882 | - | Yes |
| Effect size | 0.0178818 | 0.0178818 | - | Yes |
| Test statistic for each model term | 24.0536 | 24.0536 | - | Yes |
| Whole-model likelihood-ratio statistic | 24.0536 | 24.0536 | - | Yes |
| Number of observations | 32 | 32 | - | Yes |
| Confidence interval | -7.69893, -1.83336 | -7.69866, -1.83328 | - | Yes |
| Effect size confidence interval | 0.000453312, 0.159875000 | 0.000453434, 0.159888000 | - | Yes |
datasets::mtcars
- Source: Published dataset distributed with an R package
- Licence: base R (GPL)
- Reference: Henderson & Velleman (1981); independent computation
| Quantity | Celeus | Independent computation | Published value | Agrees |
|---|---|---|---|---|
| Estimate | -4.02397 | -4.02397 | - | Yes |
| p-value | 0.0050882 | 0.0050882 | - | Yes |
| Effect size | 0.0178818 | 0.0178818 | - | Yes |
| Test statistic for each model term | 24.0536 | 24.0536 | - | Yes |
| Whole-model likelihood-ratio statistic | 24.0536 | 24.0536 | - | Yes |
| Number of observations | 32 | 32 | - | Yes |
| Confidence interval | -6.97910, -2.11505 | -6.97860, -2.11389 | - | Yes |
| Effect size confidence interval | 0.000931141, 0.120627000 | 0.000931609, 0.120767000 | - | Yes |
datasets::mtcars
- Source: Published dataset distributed with an R package
- Licence: base R (GPL)
- Reference: Henderson & Velleman (1981); independent computation
| Quantity | Celeus | Independent computation | Published value | Agrees |
|---|---|---|---|---|
| Estimate | -4.02397 | -4.02397 | - | Yes |
| p-value | 0.0050882 | 0.0050882 | - | Yes |
| Effect size | 0.0178818 | 0.0178818 | - | Yes |
| Test statistic for each model term | 24.0536 | 24.0536 | - | Yes |
| Whole-model likelihood-ratio statistic | 24.0536 | 24.0536 | - | Yes |
| Number of observations | 32 | 32 | - | Yes |
| Confidence interval | -9.27355, -1.34614 | -9.27305, -1.34474 | - | Yes |
| Effect size confidence interval | 9.38746e-05, 2.60242e-01 | 9.39214e-05, 2.60609e-01 | - | Yes |
MASS::birthwt
- Source: Published dataset distributed with an R package
- Licence: MASS (GPL)
- Reference: Hosmer & Lemeshow, Applied Logistic Regression; independent computation
| Quantity | Celeus | Independent computation | Published value | Agrees |
|---|---|---|---|---|
| Estimate | 1.0039 | 1.0039 | - | Yes |
| p-value | 0.043755 | 0.043755 | - | Yes |
| Effect size | 2.7289 | 2.7289 | - | Yes |
| Test statistic for each model term | 4.425290, 0.505907, 5.321740, 0.087731 | 4.425290, 0.505907, 5.321740, 0.087731 | - | Yes |
| Whole-model likelihood-ratio statistic | 12.0991 | 12.0991 | - | Yes |
| Number of observations | 189 | 189 | - | Yes |
| Confidence interval | 0.0229561, 1.9909700 | 0.0229922, 1.9909300 | - | Yes |
| Effect size confidence interval | 1.02322, 7.32260 | 1.02326, 7.32230 | - | Yes |
| Hosmer-Lemeshow calibration statistic | 3.31255 | 3.31255 | - | Yes |
MASS::birthwt (race as integer codes)
- Source: Published dataset distributed with an R package
- Licence: MASS (GPL)
- Reference: Hosmer & Lemeshow, Applied Logistic Regression; independent computation
| Quantity | Celeus | Independent computation | Published value | Agrees |
|---|---|---|---|---|
| Estimate | 1.0039 | 1.0039 | - | Yes |
| p-value | 0.043755 | 0.043755 | - | Yes |
| Effect size | 2.7289 | 2.7289 | - | Yes |
| Test statistic for each model term | 4.425290, 0.505907, 5.321740, 0.087731 | 4.425290, 0.505907, 5.321740, 0.087731 | - | Yes |
| Whole-model likelihood-ratio statistic | 12.0991 | 12.0991 | - | Yes |
| Number of observations | 189 | 189 | - | Yes |
| Confidence interval | 0.0229561, 1.9909700 | 0.0229922, 1.9909300 | - | Yes |
| Effect size confidence interval | 1.02322, 7.32260 | 1.02326, 7.32230 | - | Yes |
MASS::birthwt (race declared ordinal)
- Source: Published dataset distributed with an R package
- Licence: MASS (GPL)
- Reference: Hosmer & Lemeshow, Applied Logistic Regression; independent computation
| Quantity | Celeus | Independent computation | Published value | Agrees |
|---|---|---|---|---|
| Estimate | 1.0039 | 1.0039 | - | Yes |
| p-value | 0.043755 | 0.043755 | - | Yes |
| Effect size | 2.7289 | 2.7289 | - | Yes |
| Test statistic for each model term | 4.425290, 0.505907, 5.321740, 0.087731 | 4.425290, 0.505907, 5.321740, 0.087731 | - | Yes |
| Whole-model likelihood-ratio statistic | 12.0991 | 12.0991 | - | Yes |
| Number of observations | 189 | 189 | - | Yes |
| Confidence interval | 0.0229561, 1.9909700 | 0.0229922, 1.9909300 | - | Yes |
| Effect size confidence interval | 1.02322, 7.32260 | 1.02326, 7.32230 | - | Yes |
datasets::infert
- Source: Published dataset distributed with an R package
- Licence: base R (GPL)
- Reference: Trichopoulos et al. (1976), Br J Obstet Gynaecol 83; independent computation
| Quantity | Celeus | Independent computation | Published value | Agrees |
|---|---|---|---|---|
| Estimate | 1.19721 | 1.19721 | - | Yes |
| p-value | 1.543e-08 | 1.543e-08 | - | Yes |
| Effect size | 3.31085 | 3.31085 | - | Yes |
| Test statistic for each model term | 36.48680, 4.14965 | 36.48680, 4.14965 | - | Yes |
| Whole-model likelihood-ratio statistic | 36.5591 | 36.5591 | - | Yes |
| Number of observations | 248 | 248 | - | Yes |
| Confidence interval | 0.793945, 1.626580 | 0.793934, 1.626570 | - | Yes |
| Effect size confidence interval | 2.21211, 5.08646 | 2.21208, 5.08639 | - | Yes |
datasets::esoph (expanded to 975 subjects)
- Source: Published dataset distributed with an R package
- Licence: base R (GPL)
- Reference: Breslow & Day (1980), Statistical Methods in Cancer Research I; independent computation
| Quantity | Celeus | Independent computation | Published value | Agrees |
|---|---|---|---|---|
| Estimate | 1.98088 | 1.98088 | - | Yes |
| Test statistic for each model term | 126.4880, 127.9330, 23.5443 | 126.4880, 127.9330, 23.5443 | - | Yes |
| Whole-model likelihood-ratio statistic | 285.617 | 285.617 | - | Yes |
datasets::esoph (expanded, ordered factors)
- Source: Published dataset distributed with an R package
- Licence: base R (GPL)
- Reference: Breslow & Day (1980), Statistical Methods in Cancer Research I; independent computation
| Quantity | Celeus | Independent computation | Published value | Agrees |
|---|---|---|---|---|
| Estimate | 1.98088 | 1.98088 | - | Yes |
| Test statistic for each model term | 126.4880, 127.9330, 23.5443 | 126.4880, 127.9330, 23.5443 | - | Yes |
datasets::Titanic (expanded to 2201 passengers)
- Source: Published dataset distributed with an R package
- Licence: base R (GPL)
- Reference: Dawson (1995), J. Statistics Education 3(3); independent computation
| Quantity | Celeus | Independent computation | Published value | Agrees |
|---|---|---|---|---|
| Estimate | 2.42006 | 2.42006 | - | Yes |
| p-value | 1.43183e-66 | 1.43183e-66 | - | Yes |
| Effect size | 11.2465 | 11.2465 | - | Yes |
| Test statistic for each model term | 352.9110, 119.0340, 18.8517 | 352.9110, 119.0340, 18.8517 | - | Yes |
| Whole-model likelihood-ratio statistic | 559.396 | 559.396 | - | Yes |
| Number of observations | 2201 | 2201 | - | Yes |
| Confidence interval | 2.14859, 2.69935 | 2.14858, 2.69934 | - | Yes |
| Effect size confidence interval | 8.57273, 14.87010 | 8.57268, 14.87000 | - | Yes |
carData::TitanicSurvival
- Source: Published dataset distributed with an R package
- Licence: carData (GPL)
- Reference: Dawson (1995), J. Statistics Education 3(3); independent computation on the 1046 complete rows
| Quantity | Celeus | Independent computation | Published value | Agrees |
|---|---|---|---|---|
| Estimate | -2.49784 | -2.49784 | - | Yes |
| p-value | 3.78293e-51 | 3.78293e-51 | - | Yes |
| Effect size | 0.0822621 | 0.0822621 | - | Yes |
| Test statistic for each model term | 273.2390, 31.3441, 118.8860 | 273.2390, 31.3441, 118.8860 | - | Yes |
| Whole-model likelihood-ratio statistic | 432.167 | 432.167 | - | Yes |
| Number of observations | 1046 | 1046 | - | Yes |
| Confidence interval | -2.82906, -2.17762 | -2.82905, -2.17761 | - | Yes |
| Effect size confidence interval | 0.0590684, 0.1133110 | 0.0590689, 0.1133120 | - | Yes |
| Number of rows dropped for missing values | 263 | 263 | - | Yes |
carData::TitanicSurvival
- Source: Published dataset distributed with an R package
- Licence: carData (GPL)
- Reference: Dawson (1995), J. Statistics Education 3(3); the same multiple-imputation call
| Quantity | Celeus | Independent computation | Published value | Agrees |
|---|---|---|---|---|
| Estimate | -2.50242 | -2.50242 | - | Yes |
| p-value | 2.23132e-57 | 2.23132e-57 | - | Yes |
| Confidence interval | -2.74778, -2.25707 | -2.74778, -2.25707 | - | Yes |
| Effect size | 0.0818862 | 0.0818862 | - | Yes |
| Effect size confidence interval | 0.064070, 0.104657 | 0.064070, 0.104657 | - | Yes |
datasets::mtcars (am removed in rows 3, 7 and 11)
- Source: Published dataset distributed with an R package
- Licence: base R (GPL)
- Reference: Henderson & Velleman (1981); independent computation on the 29 rows with an outcome
| Quantity | Celeus | Independent computation | Published value | Agrees |
|---|---|---|---|---|
| Estimate | -3.72102 | -3.72102 | - | Yes |
| p-value | 0.00883814 | 0.00883814 | - | Yes |
| Effect size | 0.0242093 | 0.0242093 | - | Yes |
| Test statistic for each model term | 20.8348 | 20.8348 | - | Yes |
| Whole-model likelihood-ratio statistic | 20.8348 | 20.8348 | - | Yes |
| Number of observations | 29 | 29 | - | Yes |
| Confidence interval | -7.38670, -1.58527 | -7.38666, -1.58427 | - | Yes |
| Effect size confidence interval | 0.000619434, 0.204892000 | 0.000619461, 0.205098000 | - | Yes |
datasets::mtcars (rows 1-15)
- Source: Published dataset distributed with an R package
- Licence: base R (GPL)
- Reference: Henderson & Velleman (1981); independent computation
| Quantity | Celeus | Independent computation | Published value | Agrees |
|---|---|---|---|---|
| Test statistic for each model term | 15.0121 | 15.0121 | - | Yes |
| Whole-model likelihood-ratio statistic | 15.0121 | 15.0121 | - | Yes |
| Number of observations | 15 | 15 | - | Yes |
datasets::mtcars
- Source: Published dataset distributed with an R package
- Licence: base R (GPL)
- Reference: Henderson & Velleman (1981); independent computation
| Quantity | Celeus | Independent computation | Published value | Agrees |
|---|---|---|---|---|
| Test statistic for each model term | 27.9534 | 27.9534 | - | Yes |
| Whole-model likelihood-ratio statistic | 27.9534 | 27.9534 | - | Yes |
| Number of observations | 32 | 32 | - | Yes |
survey::apiclus1 (school-wide growth target met, Yes/No)
- Source: Published dataset distributed with an R package
- Licence: survey (GPL-2 | GPL-3)
- Reference: Lumley T, "A survey analysis example" (survey package vignette) for the published coefficients; independent computation with the survey package
| Quantity | Celeus | Independent computation | Published value | Agrees |
|---|---|---|---|---|
| Estimate | 0.0399254 | 0.0399254 | 0.039925 | Yes |
| Test statistic | 3.20875 | 3.20875 | 3.209 | Yes |
| p-value | 0.00750961 | 0.00750961 | 0.00751 | Yes |
| Degrees of freedom | 12 | 12 | - | Yes |
| Confidence interval | 0.0128152, 0.0670357 | 0.0128152, 0.0670357 | - | Yes |
| Test statistic for the term, predictor 1 | 10.2961 | 10.2961 | - | Yes |
| p-value for the term, predictor 1 | 0.00750961 | 0.00750961 | - | Yes |
| Test statistic for the term, predictor 2 | 4.69095 | 4.69095 | - | Yes |
| p-value for the term, predictor 2 | 0.0511723 | 0.0511723 | - | Yes |
| Effect size | 1.04073 | 1.04073 | - | Yes |
| Effect size confidence interval | 1.01290, 1.06933 | 1.01290, 1.06933 | - | Yes |
survey::apistrat (school-wide growth target met)
- Source: Published dataset distributed with an R package
- Licence: survey (GPL-2 | GPL-3)
- Reference: independent computation with the survey package
| Quantity | Celeus | Independent computation | Published value | Agrees |
|---|---|---|---|---|
| Estimate | -0.00248964 | -0.00248964 | - | Yes |
| Test statistic | -0.187862 | -0.187862 | - | Yes |
| p-value | 0.851181 | 0.851181 | - | Yes |
| Degrees of freedom | 194 | 194 | - | Yes |
| Confidence interval | -0.0243926, 0.0194134 | -0.0243926, 0.0194134 | - | Yes |
| Test statistic for the term, predictor 1 | 0.035292 | 0.035292 | - | Yes |
| p-value for the term, predictor 1 | 0.851181 | 0.851181 | - | Yes |
| Test statistic for the term, predictor 2 | 0.117421 | 0.117421 | - | Yes |
| p-value for the term, predictor 2 | 0.73222 | 0.73222 | - | Yes |
| Test statistic for the term, predictor 3 | 3.63616 | 3.63616 | - | Yes |
| p-value for the term, predictor 3 | 0.0580148 | 0.0580148 | - | Yes |
| Effect size confidence interval | 0.975902, 1.019600 | 0.975902, 1.019600 | - | Yes |
survey::nhanes (race and sex recoded to text labels; a missing cholesterol outcome is a domain restriction)
- Source: Published dataset distributed with an R package
- Licence: survey (GPL-2 | GPL-3)
- Reference: independent computation with the survey package
| Quantity | Celeus | Independent computation | Published value | Agrees |
|---|---|---|---|---|
| Estimate | -0.0848865 | -0.0848865 | - | Yes |
| Test statistic | -1.06263 | -1.06263 | - | Yes |
| p-value | 0.31563 | 0.31563 | - | Yes |
| Degrees of freedom | 9 | 9 | - | Yes |
| Confidence interval | -0.2655950, 0.0958222 | -0.2655950, 0.0958222 | - | Yes |
| Test statistic for the term, predictor 1 | 3.10577 | 3.10577 | - | Yes |
| p-value for the term, predictor 1 | 0.0815733 | 0.0815733 | - | Yes |
| Test statistic for the term, predictor 2 | 30.37 | 30.37 | - | Yes |
| p-value for the term, predictor 2 | 4.87663e-05 | 4.87663e-05 | - | Yes |
| Test statistic for the term, predictor 3 | 6.32281 | 6.32281 | - | Yes |
| p-value for the term, predictor 3 | 0.0330646 | 0.0330646 | - | Yes |
| Number of observations | 7846 | 7846 | - | Yes |
| Number of rows dropped for missing values | 745 | 745 | - | Yes |
References
- Nelder, J. A., Wedderburn, R. W. M. (1972). Generalized linear models. Journal of the Royal Statistical Society, Series A 135: 370-384. doi:10.2307/2344614 doi:10.2307/2344614