---
title: "dag5"
output: html_document
---

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

## Titanic


```{r}
data(Titanic)     # Få adgang til data
library("MESS")   # Hent pakke med expand_table
titanic <- expand_table(Titanic) 

table(titanic$Survived, titanic$Sex)
xtabs(~ Survived + Sex, data=titanic)

library("tidyverse")

titanic %>% group_by(Sex) %>% count(Survived)

prop.test(367, 367 + 1364)

# B

m1 <- glm(Survived ~ Sex + Age + Class,
          data=titanic, family=binomial())
library("broom")
m1 %>% tidy()

exp(-1.06)
exp(-1.02)
exp(2.42)
exp(0.685)

confint(m1)

exp(confint(m1))

DF <- data.frame(Sex=c("Male", "Female"),
                 Age=c("Adult", "Adult"),
                 Class=c("3rd", "2nd"))

DF

predict(m1, newdata=DF, type="response")
```


# Opgave 2

```{r}
library("MASS")  # Hent den relevante pakke
data(birthwt)    # Hent datasættet      
help(package=MASS)


m2 <- glm(low ~ smoke + age, 
          data=birthwt, family=binomial())

library("tidyverse")
library("broom")
m2 %>% tidy()

exp(-0.0498)

exp(confint(m2))

exp(-0.498)

0.95^10

m3 <- glm(low ~ smoke*age, 
          data=birthwt, family=binomial())


m3 %>% tidy()
```



