---
title: "The Donner Party"
output: html_document
---

```{r setup, include=TRUE, message=FALSE}
knitr::opts_chunk$set(echo = TRUE)
require(Sleuth3)
require(tigerstats)
```

## The Donner Party

The [Donner Party](https://en.wikipedia.org/wiki/Donner_Party) was a large group of people who were travelling to California in a [wagon train](https://en.wikipedia.org/wiki/Donner_Party). The Donner Party was trapped in the [Sierra Nevada](https://en.wikipedia.org/wiki/Sierra_Nevada_(U.S.)) mountain range for more than three mothns because of heavy snowfall. Their food supplies were exhausted, and of the 87 members of the party, only 48 survived. .

Getting the data:
```{r}
lines <- 
"AGE,SEX,STATUS
  23,MALE,DIED
  40,FEMALE,SURVIVED
  40,MALE,SURVIVED
  30,MALE,DIED
  28,MALE,DIED
  40,MALE,DIED
  45,FEMALE,DIED
  62,MALE,DIED
  65,MALE,DIED
  45,FEMALE,DIED
  25,FEMALE,DIED
  28,MALE,SURVIVED
  28,MALE,DIED
  23,MALE,DIED
  22,FEMALE,SURVIVED
  23,FEMALE,SURVIVED
  28,MALE,SURVIVED
  15,FEMALE,SURVIVED
  47,FEMALE,DIED
  57,MALE,DIED
  20,FEMALE,SURVIVED
  18,MALE,SURVIVED
  25,MALE,DIED
  60,MALE,DIED
  25,MALE,SURVIVED
  20,MALE,SURVIVED
  32,MALE,SURVIVED
  32,FEMALE,SURVIVED
  24,FEMALE,SURVIVED
  30,MALE,SURVIVED
  15,MALE,DIED
  50,FEMALE,DIED
  21,FEMALE,SURVIVED
  25,MALE,DIED
  46,MALE,SURVIVED
  32,FEMALE,SURVIVED
  30,MALE,DIED
  25,MALE,DIED
  25,MALE,DIED
  25,MALE,DIED
  30,MALE,DIED
  35,MALE,DIED
  23,MALE,SURVIVED
  24,MALE,DIED
  25,FEMALE,SURVIVED"

con <- textConnection(lines)
donner <- read.csv(con, sep=",")
```

Let's run Logistic Regression:

```
fit <- glm(STATUS~SEX + AGE, family=binomial(link="logit"), data=donner)
summary(fit)
```

Here are is what you need for the practice problem:

```{r}
donner$SEX <- relevel(donner$SEX, ref = "MALE")
donner$SEX_eff <- ifelse(donner$SEX == "FEMALE", 1, -1)

fit <- glm(STATUS ~ SEX + AGE, data= donner, family= "binomial")
summary(fit)

fit <- glm(STATUS ~ SEX_eff + AGE, data= donner, family= "binomial")
summary(fit)

fit1 <- glm(STATUS ~ SEX * AGE, data= donner, family= "binomial")
summary(fit1)
anova(fit1, test= "LRT")

fit2 <- glm(STATUS ~ SEX*AGE + I(AGE^2), data= donner, family= "binomial")
summary(fit2)
anova(fit2)

fit3 <- glm(STATUS ~ SEX*AGE + SEX*I(AGE^2), data= donner, family= "binomial")
summary(fit3)
anova(fit3)
```





