Complete all Questions and submit your final PDF or HTML (either works!) under Assignments in Canvas.

Goal

It has been a while since we did logistic regression!! We are going to use our time today to review concepts for logistic regression to help prepare you for the final exam. If you have questions about anything, please let me know!

The Data

In this lab, we will return to the data set about the Titanic. Recall that the RMS Titanic was a huge, luxury passenger liner designed and built in the early 20th century. Despite the fact that the ship was believed to be unsinkable, during her maiden voyage on April 15, 1912, the Titanic collided with an iceberg and sank.

We have information on \(n=714\) passengers from the Titanic. Unlike last time, today we are interested in modeling \(Y=\)

In addition to this \(Y\) variable, we have many possible explanatory variables, including

To load the data, copy and paste the following into a code chunk and press play:

# Load the data 
Titanic <- read.csv("https://www.dropbox.com/scl/fi/26vhy0o0n4zykjvpjgolo/Titanic.csv?rlkey=b4a6ewvjrgvd25gr42tuayoyh&st=yppg7u63&dl=1")

# Some Data cleaning
Titanic$Sex <- as.factor(Titanic$Sex)
Titanic$Pclass <- as.factor(Titanic$Pclass)
Titanic <- na.omit(Titanic)

Question 1

Which of the following models is possible for us to use given our data and stated research question? Choose all that apply.
  1. an LSLR model
  2. a MR model
  3. a logistic regression model
  4. a multiple logistic regression model

Model 1: One Categorical X

We are approached by an historian, Historian 1. Historian 1 knows from their work that in the era when the Titanic sank, social conventions would have indicated that women were prioritized over men for space on the life boats. They therefore suggest you start your work in modeling \(Y\) = survival by building a model using \(X\)= whether the passenger was male or female. Historian 1 believes women were more likely to have survived than men.

To build the appropriate regression model in R, we use:

model1 <- glm(Survived ~ Sex, data = Titanic, family = "binomial")

To see the coefficients of the model and formatted them neatly, we use:

knitr::kable( summary( model1 )$coefficients )

Question 2

What is the baseline for sex? How can you tell?

Question 3

Write out the fitted model using appropriate notation. Round to 2 decimal places.

Hint: To format the model properly, copy and paste the following into WHITE SPACE (not a chunk!!!!) in your Markdown file. Fill in what you need after the \(=\) but before the $$.

$$log \left( \frac{\hat{\pi}}{1-\hat{\pi}} \right) = $$

Question 4

Interpret the slope in terms of the log odds.

Question 5

Interpret the slope in terms of the odds.

Question 6

What is the predicted probability that a man survived the Titanic disaster? Show your work.

Question 7

What is the predicted probability that a woman survived the Titanic disaster? Show your work.

Question 8

The historian believed that women were more likely to have survived than men on the Titanic. Based on the model, does it seem as though they are correct?

Model 2: Adding Age

We have completed everything Historian 1 asked of us, and now we are approached by Historian 2. Historian 2 agrees with Historian 1 that social conventions in 1912 would have prioritized women over men for space in the life boats. However, Historian 2 believes the age of the passenger would also have mattered. They request that we add age into the model, too.

  • Age: The age of the passenger in years. Note: Decimals are for children under a year in age.

Historian 2 is asking for a multiple logistic regression model, which just means more than one X variable is in the model. To add a new variable into the model, we just use +.

model2 <- glm(Survived ~ Sex + Age, data = Titanic, family = "binomial")

Question 9

Interpret the coefficient for age in terms of the odds.

Question 10

What is the predicted probability that a woman of age 30 survived the Titanic disaster? Show your work.

Question 11

Do you have enough evidence to claim that age is associated with the survival probability, after controlling for the variable sex? Justify?

Adapted by Tuhin Majumder from STA 112 Lab 5 by Nicole Dalzell, licensed under the Creative Commons Attribution–NonCommercial 4.0 International License. Original: https://rpubs.com/MST256/STA112Lab5New.