Calculating odds-ratios

In the previous exercise, we saw how to compare the effects of a friend's recommendation on sales. However, regression outputs can be hard to describe and sometimes odds-ratios can be easier to use. Using the outputs from the previous exercise, we're going to calculate odds-ratios.

Refresher on odds-ratios:

  • If an odds-ratio is 1.0, then both events have an equal chance of occurring. For example, if the odds-ratio for a friend's recommendation was 1.0, then a friend would have no influence on a purchase decision.
  • If an odds-ratio is less than 1, then a friend's recommendation would decrease the chance of a purchase occurring. For example, an odds-ratio of 0.5 would mean a friend's recommendation has odds of 1:2 or 1 purchase occurring for every 2 passes.
  • If an odds-ratio is greater than 1, then a friend's recommendation would increase the chance of a purchase occurring. For example, an odds-ratio of 3.0 would mean a friend's recommendation has odds of 3:1 or 3 purchases occurring for every 1 passes.

Note on course code: Since this course launched, the broom package has dropped support for lme4::lmer() models. If you try to repeat this on your own, you will need the broom.mixed package, which is on cran.

This exercise is part of the course

Hierarchical and Mixed Effects Models in R

View Course

Exercise instructions

  • Look at the summary() of model_out.
  • Extract the coefficients from model_out with fixef() and then convert to an odds-ratio by taking exponential. Repeat with confint() to get the confidence intervals.
  • Calculate the confidence intervals and then exponentiate the effect of friends on a purchase using tidy(). Make sure to set the conf.int and exponentiate parameters.

Hands-on interactive exercise

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

# Run the code to see how to calculate odds ratios
summary( ___) 
exp(___(model_out))
exp(___(model_out))

# Create the tidied output
tidy(model_out, conf.int = ___, exponentiate = ___)