Get startedGet started for free

From coefficients to odds ratios

From the fact that the computational target variable in the logistic regression model is the log of odds, it follows that applying the exponent function to the modelled values gives the odds:

$$\exp \left( log\left( \frac{p}{1 - p} \right) \right) = \frac{p}{1 - p}.$$

For this reason, the exponents of the coefficients of a logistic regression model can be interpret as odds ratios between a unit change (vs no change) in the corresponding explanatory variable.

This exercise is part of the course

Helsinki Open Data Science

View Course

Exercise instructions

  • Use glm() to fit a logistic regression model.
  • Creat the object OR: Use coef() on the model object to extract the coefficients of the model and then apply the exp function on the coefficients.
  • Use confint() on the model object to compute confidence intervals for the coefficients. Exponentiate the values and assign the results to the object CI. (R does this quite fast, despite the "Waiting.." message)
  • Combine and print out the odds ratios and their confidence intervals. Which predictor has the widest interval? Does any of the intervals contain 1 and why would that matter?

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# alc and dlyr are available 

# find the model with glm()
m <- glm(high_use ~ failures + absences + sex, data = alc, family = "binomial")

# compute odds ratios (OR)
OR <- coef(m) %>% exp

# compute confidence intervals (CI)


# print out the odds ratios with their confidence intervals
cbind(OR, CI)
Edit and Run Code