8. Binary logistic regression models

Amy Atkinson

Caution

This page is under construction for 24/25 and may be subject to change before the teaching week.

Lecture

Watch part 1 here

Watch part 2 here

Watch part 3 here

Watch part 4 here

Download the lecture slides here

Post Lecture

Find the post-lecture worksheet here and the answers here

Lab Preparation

Watch the preparation video here

Download the files discussed in the video here

Lab Work

Binary logistic regression with one categorical predictor

Research Question

You are interested in whether the country an individual lives (UK/Australia) predicts reptile ownership (Yes/No).

In the dataset, the outcome variable (reptile) is coded as “Y” and “N”:

  • Y = Yes
  • N = No

To make sure we should all end up with the same output, set UK as your reference category

Not sure how to set the reference category? Have a look at the recode() function from dplyr (tidyverse). Either search in the Help tab on the right, or type ?recode in the console below. Have a read of the second and third paragraph in the description and check out the examples at the bottom of the help pane.

Other options exist too, you can look at relevel() or using the levels argument inside the function as.factor() or factor(). Check these out in the same way as described above.

Steps

  1. Prepare our data for analysis
  2. Explore our data
  3. Run the binary logistic regression model
  4. Evaluate the model
  5. Evaluate the individual predictors
  6. Predicted probabilities
  7. Interpret the output

Upload your script

You can upload your finished script for feedback on your code here and feedback will be posted onto Moodle.

Back to top