Fondamenti di inferenza in R
Jo Hardin
Instructor






Generare una distribuzione della statistica dalla popolazione nulla indica se i dati osservati sono incompatibili con l'ipotesi nulla
Dati originali
| Location | Cola | Aranciata |
|---|---|---|
| Est | 28 | 6 |
| Ovest | 19 | 7 |
$\hat{p}_\text{east} = 28/(28 + 6) = 0.82$
$\hat{p}_\text{west} = 19/(19 + 7) = 0.73$
Primo rimescolamento, uguale all'originale
| Location | Cola | Aranciata |
|---|---|---|
| Est | 28 | 6 |
| Ovest | 19 | 7 |

Secondo rimescolamento
| Location | Cola | Aranciata |
|---|---|---|
| Est | 27 | 7 |
| Ovest | 20 | 6 |

Terzo rimescolamento
| Location | Cola | Aranciata |
|---|---|---|
| Est | 28 | 8 |
| Ovest | 21 | 5 |

Quarto rimescolamento
| Location | Cola | Aranciata |
|---|---|---|
| Est | 25 | 9 |
| Ovest | 22 | 4 |

Quinto rimescolamento
| Location | Cola | Aranciata |
|---|---|---|
| Est | 29 | 5 |
| Ovest | 18 | 8 |

Quinto rimescolamento
| Location | Cola | Aranciata |
|---|---|---|
| Est | 29 | 5 |
| Ovest | 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

Fondamenti di inferenza in R