Today’s agenda

Today’s agenda

  • Wrap up one variable inference

  • Testing for independence

  • Get started on App Ex 8

Wrap up one variable inference

Rent in Durham

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")

Exploratory analysis

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

durham_apts %>%
  summarise(xbar = mean(rent), med = median(rent))
##    xbar med
## 1 920.1 887

Load helper functions

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")

Bootstrap CI for mean rent in Durham

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)

Bootstrap CI for median rent in Durham

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)

Bootstrap testing for a mean

  • 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

Bootstrap test for average rent in Durham

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

Other helper functions

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")

Testing for independence

Is yawning contagious?

Do you think yawning is contagious?

empirical