ComenzarEmpieza gratis

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.

Este ejercicio forma parte del curso

Helsinki Open Data Science

Ver curso

Instrucciones del ejercicio

  • 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?

Ejercicio interactivo práctico

Prueba este ejercicio y completa el código de muestra.

# 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)
Editar y ejecutar código