R에서의 추론 기초
Jo Hardin
Instructor






귀무모집단에서 통계량 분포를 생성하면 관측값이 귀무가설과 불일치하는지 판단할 수 있습니다
원자료
| Location | Cola | Orange |
|---|---|---|
| East | 28 | 6 |
| West | 19 | 7 |
$\hat{p}_\text{east} = 28/(28 + 6) = 0.82$
$\hat{p}_\text{west} = 19/(19 + 7) = 0.73$
첫 번째 셔플, 원본과 동일
| Location | Cola | Orange |
|---|---|---|
| East | 28 | 6 |
| West | 19 | 7 |

두 번째 셔플
| Location | Cola | Orange |
|---|---|---|
| East | 27 | 7 |
| West | 20 | 6 |

세 번째 셔플
| Location | Cola | Orange |
|---|---|---|
| East | 28 | 8 |
| West | 21 | 5 |

네 번째 셔플
| Location | Cola | Orange |
|---|---|---|
| East | 25 | 9 |
| West | 22 | 4 |

다섯 번째 셔플
| Location | Cola | Orange |
|---|---|---|
| East | 29 | 5 |
| West | 18 | 8 |

다섯 번째 셔플
| Location | Cola | Orange |
|---|---|---|
| East | 29 | 5 |
| West | 18 | 8 |







soda %>%
group_by(location) %>%
summarize(prop_cola =
mean(drink == "cola")) %>%
summarize(diff(prop_cola))
# A tibble: 1 x 1
`diff(prop_cola)`
<dbl>
1 -0.09276018
library(infer)
soda %>% specify(drink ~ location,
success = "cola") %>%
hypothesize(null = "independence") %>%
generate(reps = 1, type = "permute") %>%
calculate(stat = "diff in props",
order = c("west","east"))
# A tibble: 1 x 2
replicate stat
<int> <dbl>
1 1 -0.02488688
soda %>%
specify(drink ~ location, success = "cola") %>%
hypothesize(null = "independence") %>%
generate(reps = 5, type = "permute") %>%
calculate(stat = "diff in props", order = c("west", "east"))
# A tibble: 5 x 2
replicate stat
<int> <dbl>
1 1 0.04298643
2 2 -0.09276018
3 3 0.11085973
4 4 0.17873303
5 5 -0.16063348

R에서의 추론 기초