October 27, 2015

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?

An experiment conducted by the MythBusters tested if a person can be subconsciously influenced into yawning if another person near them yawns.

http://snagplayer.video.dp.discovery.com/614929/snag-it-player.htm?auto=no

In this study 50 people were randomly assigned to two groups: 34 to a group where a person near them yawned (treatment) and 16 to a control group where they didn't see someone yawn (control).

table(mb_yawn$group, mb_yawn$outcome)

## ## not yawn yawn ## control 12 4 ## treatment 24 10

addmargins(table(mb_yawn$group, mb_yawn$outcome))

## ## not yawn yawn Sum ## control 12 4 16 ## treatment 24 10 34 ## Sum 36 14 50

Proportion of yawners in the treatment group: \(\frac{10}{34} = 0.2941\)

Proportion of yawners in the control group: \(\frac{4}{16} = 0.25\)

Our results match the ones calculated on the MythBusters episode.

Based on the proportions we calculated, do you think yawning is really contagious, i.e. are seeing someone yawn and yawning dependent?

The observed differences might suggest that yawning is contagious, i.e. seeing someone yawn and yawning are dependent.

But the differences are small enough that we might wonder if they might simple be

**due to chance**.Perhaps if we were to repeat the experiment, we would see slightly different results.

So we will do just that - well, somewhat - and see what happens.

Instead of actually conducting the experiment many times, we will our results.

``There is nothing going on." Promotion and gender are

**independent**, no gender discrimination, observed difference in proportions is simply due to chance. \(\rightarrow\) Null hypothesis``There is something going on." Promotion and gender are

**dependent**, there is gender discrimination, observed difference in proportions is not due to chance. \(\rightarrow\) Alternative hypothesis

A regular deck of cards is comprised of 52 cards: 4 aces, 4 of numbers 2-10, 4 jacks, 4 queens, and 4 kings.

Take out two aces from the deck of cards and set them aside.

- The remaining 50 playing cards to represent each participant in the study:
- 14 face cards (including the 2 aces) represent the people who yawn.
- 36 non-face cards represent the people who don't yawn.

Shuffle the 50 cards at least 7 times* to ensure that the cards counted out are from a random process.

Count out the top 16 cards and set them aside. These cards represent the people in the control group.

Out of the remaining 34 cards (treatment group) count the (the number of people who yawned in the treatment group).

Calculate the difference in proportions of yawners (treatment - control), and submit this value using your clicker.

Mark the difference you find on the dot plot.

*http://www.dartmouth.edu/~chance/course/topics/winning_number.html*

Do the simulation results suggest that yawning is contagious, i.e. does seeing someone yawn and yawning appear to be dependent?

## $p_hat_diff ## [1] 0.0441 ## ## $p_value ## [1] 0.513

**Application exercise 10:**

Write a function that conducts a randomization test as described above for two categorical variables. Run the function for the yawning dataset. Comminicate with other teams to match your answers for a given seed.