Recall the two competing hypotheses:
Key: Let’s suppose 2 is true; suppose she is guessing.
resample()
and do()
commands you can
library(ggplot2)
library(dplyr)
library(mosaic)
# Single cup
guess_cup <- c(1, 0)
# Simulate many, many, many times someone guessing at random
simulation <- do(10000) * resample(guess_cup, size=8)
V1 | V2 | V3 | V4 | V5 | V6 | V7 | V8 |
---|---|---|---|---|---|---|---|
0 | 0 | 0 | 1 | 1 | 1 | 0 | 0 |
0 | 0 | 0 | 1 | 1 | 1 | 1 | 1 |
1 | 0 | 0 | 1 | 1 | 0 | 1 | 0 |
1 | 1 | 1 | 1 | 1 | 0 | 1 | 0 |
1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 |
1 | 0 | 1 | 0 | 0 | 1 | 1 | 1 |
simulation <- simulation %>%
mutate(n_correct = V1 + V2 + V3 + V4 + V5 + V6 + V7 + V8)
V1 | V2 | V3 | V4 | V5 | V6 | V7 | V8 | n_correct |
---|---|---|---|---|---|---|---|---|
0 | 0 | 0 | 1 | 1 | 1 | 0 | 0 | 3 |
0 | 0 | 0 | 1 | 1 | 1 | 1 | 1 | 5 |
1 | 0 | 0 | 1 | 1 | 0 | 1 | 0 | 4 |
1 | 1 | 1 | 1 | 1 | 0 | 1 | 0 | 6 |
1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 2 |
1 | 0 | 1 | 0 | 0 | 1 | 1 | 1 | 5 |
i.e. What is the distribution of n_correct
?
ggplot(simulation, aes(x=n_correct)) +
geom_bar() +
labs(x="Number of Guesses Correct")
i.e. she got 8/8 correct. We add a vertical red line:
ggplot(simulation, aes(x=n_correct)) +
geom_bar() +
labs(x="Number of Guesses Correct") +
geom_vline(xintercept=8, col="red", size=2)