Opens in a new tab

METHOD GUIDE

Logistic Regression in R
Odds Ratios, Intervals and Separation Warnings

A binomial glm prints coefficients on the log-odds scale, so its table is a step short of the result. The odds ratios, the method behind their intervals and any warning about fitted probabilities each need a decision before a figure is quoted.

IN SHORT

What the Binomial Model Estimates and What Must Be Computed

Logistic regression models the probability of a binary outcome, such as readmission or a positive screening result, from one or more predictors, and its coefficients are changes in the log odds. To run logistic regression in R, fit glm(outcome ~ predictors, family = binomial, data = d), exponentiate the coefficients to obtain odds ratios, and take their intervals from confint() on the fitted model, which profiles the likelihood in current versions of R. An odds ratio compares odds, not probabilities, and it approximates a risk ratio only when the outcome is uncommon. OnlineSPSS, a specialist statistical consultancy for academic, clinical and professional research, carries out and reviews this analysis through an in-house PhD-level statistician.

ANALYSIS SUPPORT

Analysis Support for This Method

The glm call is brief, but the model behind it is not, because the covariate set, the form of each predictor and the handling of sparse outcome categories are settled before the call.

Logistic Regression

The binary-outcome model planned for your study design, from the choice of covariates to odds ratios reported with intervals and, where prediction matters, calibration.

Explore Logistic Regression
Firth's Logistic Regression

A penalized fit for data in which an outcome category is sparse or a predictor splits the groups almost perfectly, so that maximum likelihood estimates head toward infinity.

Explore Firth's Logistic Regression

BEFORE YOU RUN IT

Levels, Event Counts and Curvature Before glm()

Three of these points are settled before glm() is called, and the fourth decides whether glm() is the right function at all.

Factor Levels and the Event For a glm binomial in R with a factor outcome, the second level is modeled as the event. levels() shows the order, and relevel() sets the reference so the event comes second; a 0/1 outcome models the 1s.

Events Counted Before the Formula Grows table(d$y) gives the size of the rarer outcome category, which, more than the number of rows, sets how many terms the formula can carry. A factor adds one coefficient per non-reference level, so a five-level factor costs four.

Curvature Tested, Not Assumed In an R formula a continuous predictor such as age enters as a straight line on the log-odds scale. A natural spline, splines::ns(age, df = 3), is fitted beside it and the two are compared by a likelihood-ratio test before the simpler form is kept.

Clustering Ruled Out Rows from the same person, ward or school are related, yet glm() prints its usual standard errors without any warning. Clustered or repeated data call for a model that allows for the clustering.

IN R

How to Run Logistic Regression in R

Everything up to the odds ratio table uses base R. Fits that cope with separation and measures of prediction need add-on packages, and their versions are recorded with the results.

  1. Confirm the design: a binary outcome, independent rows, and a factor whose second level is the event.
  2. Tabulate the outcome with table() and cross it with each categorical predictor to find empty cells.
  3. Fit fit <- glm(y ~ x1 + x2, family = binomial, data = d) and print summary(fit).
  4. Obtain odds ratios with exp(cbind(OR = coef(fit), confint(fit))), which pairs each exponentiated estimate with its profile interval.
  5. Compare nested models with anova(fit0, fit, test = “Chisq”), and get probabilities with predict(fit, type = “response”).
  6. If a warning about fitted probabilities appears, inspect the cells and consider a penalized fit, for example logistf() in the logistf package.

READING THE OUTPUT

What summary() Prints and Where the Odds Ratios Are

The summary block reports coefficients on the log-odds scale with deviances beneath them, and neither the odds ratios nor their intervals appear until they are computed.

Output element What it tells you What to check
Estimate column The change in log odds per unit of a predictor, or against the reference level of a factor That it is exponentiated before it is called an odds ratio, and never read as a change in probability
Std. Error and z value The Wald standard error and the Wald statistic for each coefficient That an enormous estimate beside an enormous standard error is read as separation, not as a finding
p-value column The Wald p for each coefficient That Wald p-values and profile intervals are not presented as if they came from the same test
Dispersion note The line stating that the dispersion parameter for the binomial family is taken to be 1 That overdispersion is a question for grouped counts, since 0/1 rows cannot reveal it
Null and Residual deviance The deviance of the intercept-only model and of the fitted model, each with degrees of freedom That the drop is tested as a likelihood-ratio chi-squared, and not read as variance explained
AIC A penalized measure of fit for comparing models That the compared models used the same rows after incomplete cases were dropped
Fisher Scoring iterations How many steps the fitting algorithm needed That a count near the default limit of 25 is followed up with the warnings
Warning messages Notes such as fitted probabilities numerically 0 or 1, or an algorithm that did not converge That the outcome is cross-tabulated against each predictor before any estimate is quoted

REPORTING

Reporting Odds Ratios With Their Intervals

Three details decide whether a reader can rebuild the odds ratio: which level was the event, what one unit of each predictor means, and whether the interval was profiled or Wald.

Name the outcome and its event level, then give OR = ___, 95% CI [___, ___], p = ___ for each predictor, with the unit of a continuous predictor or the reference group of a factor stated, and say whether the interval is profile likelihood or Wald. Add the likelihood-ratio test for the model as χ²(df = ___) = ___, p = ___, and the number of cases analyzed, since glm() drops incomplete rows and notes it only below the table. Where the model serves prediction, add the area under the ROC curve with its interval and a calibration plot, and say whether they come from new data or from the data that built the model. Odds ratios from an observational design are worded as associations with the odds of the outcome, and the R version and packages are recorded.

Odds Ratio With CIEvent Level NamedInterval MethodLikelihood-Ratio TestCalibration Shown

COMMON MISTAKES

Reading Errors That Survive a Converged Model

A model can converge without a warning and still be misreported, and several of these errors sit in how the exponentiated numbers are described.

Log Odds Quoted as Odds Ratios The Estimate column is on the log-odds scale. Quoting it as an odds ratio, or exponentiating the estimate while leaving the interval limits untransformed, mixes two scales in one table.

Main Term Read Despite an Interaction With x1 * x2 in the formula, the coefficient for x1 is its log odds ratio when x2 is zero or at its reference level. Exponentiating it alone does not give an overall odds ratio for x1.

Odds Ratio Worded as Risk When the outcome is common, an odds ratio lies further from 1 than the corresponding risk ratio, so describing it as twice as likely overstates the difference between the groups.

Shift in Odds Ratio Read as Confounding Adding a covariate that predicts the outcome moves an odds ratio that differs from 1 further from 1, even when that covariate is unrelated to the predictor, because odds ratios are non-collapsible. A change between crude and adjusted values is not, on its own, evidence of confounding.

Continuous Predictor Dichotomized Splitting age or a score at the median to obtain a two-group odds ratio discards information and makes the result depend on where the cut falls. The continuous form is kept, with a check for curvature.

Prediction Judged on Training Data A model assessed on the data that built it looks better than it will on new cases. Where prediction is the aim, validation by resampling or on new data is reported, not the apparent fit alone.

Profile or Wald, and which level is the event? Independent Statistical Review reads your glm script beside the odds ratio table and the sentences that report it.

Request an Assessment

FREQUENTLY ASKED QUESTIONS

Questions About Odds Ratios and Warnings From glm()

Two interval functions, one console warning and one default scale explain most of the puzzles in glm output, taken here in that order.

confint() profiles the likelihood, while confint.default() builds Wald limits from the standard errors. Profile limits are generally preferred for logistic models, especially in smaller or sparse samples, because they need not be symmetric on the log-odds scale. Older versions of R loaded MASS and printed a profiling message first. For odds ratios from glm in R, exponentiate both limits after they are computed, and state in the report which method the table uses.

Some fitted probabilities are so close to 0 or 1 that R cannot tell them apart from it, which often points to separation. Cross-tabulate the outcome against each categorical predictor and check whether a continuous predictor splits the outcome almost perfectly. If it does, maximum likelihood estimates may not exist, and a penalized fit such as logistf or brglm2 is considered. The warning can also follow extreme predictor values, so the data are examined and not only the message.

By default predict() on a glm returns the linear predictor, which is the log odds, and probabilities need type = “response”. Predicted probabilities are reported at stated values of the other predictors, or averaged over the sample. For an interval around a probability, compute it on the link scale and transform the limits, because a Wald interval built directly on the probability scale can fall outside 0 and 1.

The coding of the outcome and the covariates, because a model that runs can still estimate the odds of the wrong event. An in-house PhD-level statistician can then rerun the fit, confirm the interval method and the handling of any warnings, or carry out the analysis on your data from the start. How the odds ratios and their wording appear in a manuscript is the subject of Results Reporting & Interpretation, and the meaning of the association in your field is yours to judge.

Your data and project details are handled confidentially, and project information is not published. Researcher names and institutions are not used publicly without permission. An NDA is available where required and can be arranged before sensitive materials are shared. Read more about confidentiality and data security.

You share your research question, design and relevant materials, such as the dataset or the output you have, and a statistically trained Research Coordinator reviews the request and responds the same day. The analysis, deliverables, timeline and one fixed project fee are then confirmed before any work begins, so the timeline follows from the agreed scope.

Still have a question? Find more answers in our full FAQ.

View All FAQs →

NEXT STEP

Which Interval Will
Your Odds Ratios Carry?

A model that converged without complaint can still hide a sparse cell or an unnamed interval method. With the script and the console output attached, the scope and fixed fee of a review are set from your own model.

No Commitment Required

Strictly Confidential

Fixed Project Fee

In-House PhD-Level Statisticians

Same-Day Response

Serving Researchers Since 2014