15. Wrap up one var inf + Testing for independence

Wrap up one variable inference

Testing for independence

Get started on App Ex 8

Data from a random sample of 20 1+ bedroom apartments in Durham in 2012.

`durham_apts <- read.csv("https://stat.duke.edu/~mc301/data/durham_apts.csv")`

```
ggplot(data = durham_apts, aes(x = rent)) +
geom_dotplot()
```

```
durham_apts %>%
summarise(xbar = mean(rent), med = median(rent))
```

```
## xbar med
## 1 920.1 887
```

```
source("https://stat.duke.edu/courses/Fall15/sta112.01/code/one_num_boot.R")
source("https://stat.duke.edu/courses/Fall15/sta112.01/code/one_num_test.R")
```

Estimate the average rent in Durham for 1+ bedroom apartments using a 95% confidence interval.

`one_num_boot(durham_apts$rent, statistic = mean, seed = 195729)`

```
## Summary stats: n = 20, sample mean = 920.1
## 95% CI: (795.968, 1044.232)
```

Estimate the median rent in Durham for 1+ bedroom apartments using a 95% confidence interval.

`one_num_boot(durham_apts$rent, statistic = median, seed = 571035)`

```
## Summary stats: n = 20, sample median = 887
## 95% CI: (712.8174, 1061.1826)
```

Construct the bootstrap distribution

Shift it to be centered at the null value

Calculate the p-value as usual: observed or more extreme outcome (more extreme in the direction of the null hypothesis) given that the null value is true

Do these data provide convincing evidence that the average rent in Durham for 1+ bedroom apartments is greater than $800?

`one_num_test(durham_apts$rent, statistic = mean, null = 800, alt = "greater", seed = 28732)`

```
## H0: mu = 800
## HA: mu > 800
## Summary stats: n = 20, sample mean = 920.1
## p-value = 0.0251
```

For future use…

```
source("https://stat.duke.edu/courses/Fall15/sta112.01/code/one_cat_boot.R")
source("https://stat.duke.edu/courses/Fall15/sta112.01/code/one_cat_test.R")
```

Do you think yawning is contagious?