Inference for Numerical Data in R
Mine Cetinkaya-Rundel
Associate Professor of the Practice, Duke University
Motivační otázka: Pomáhá léčba kmenovými buňkami zlepšit funkci srdce po infarktu více než tradiční terapie?
Data: soubor stem.cell z balíčku openintro
library(openintro)
data(stem.cell)
trmt before after
1 ctrl 35.25 29.50
2 ctrl 36.50 29.50
3 ctrl 39.75 36.25
... ... ...
n esc 53.75 51.00
Krok 1. Vypočítejte change pro každou ovci: rozdíl mezi kapacitou čerpání srdce před a po léčbě.
trmt before after change
1 ctrl 35.25 29.50 ?
2 ctrl 36.50 29.50 ?
3 ctrl 39.75 36.25 ?
... ... ...
n esc 53.75 51.00 ?
Krok 2. Stanovte hypotézy:
$H_0: \mu_{esc} = \mu_{ctrl}$; Mezi průměrnou změnou v léčebné a kontrolní skupině není žádný rozdíl.
$H_A: \mu_{esc} > \mu_{ctrl}$; Mezi průměrnou změnou v léčebné a kontrolní skupině je rozdíl.
Krok 3. Proveďte test hypotézy.
change na 18 indexových karet.change mezi léčebnou a kontrolní skupinou.Použijte balíček infer k provedení testu:
library(infer)
Začněte s datovým rámcem a specifikujte model:
library(infer)
diff_ht_mean <- stem.cell %>%
specify(__) %>% # y ~ x
...
Deklarujte nulovou hypotézu, tj. žádný rozdíl mezi středními hodnotami:
library(infer)
diff_ht_mean <- stem.cell %>%
specify(__) %>% # y ~ x
hypothesize(null = __) %>% # "independence" or "point"
...
Generujte převzorkování za předpokladu platnosti $H_0$:
library(infer)
diff_ht_mean <- stem.cell %>%
specify(__) %>% # y ~ x
hypothesize(null = __) %>% # "independence" or "point"
generate(reps = __, type = __) %>% # "bootstrap", "permute", or "simulate"
...
Vypočítejte testovou statistiku:
library(infer)
diff_ht_mean <- stem.cell %>%
specify(__) %>% # y ~ x
hypothesize(null = __) %>% # "independence" or "point"
generate(reps = _N_, type = __) %>%# "bootstrap", "permute", or "simulate"
calculate(stat = "diff in means") # type of statistic to calculate
Vypočítejte p-hodnotu jako podíl simulací, kde simulovaný rozdíl středních hodnot je alespoň tak extrémní jako pozorovaný
$$P ((\bar{x}_{esc,sim} - \bar{x}_{ctrl,sim}) \ge (\bar{x}_{esc,obs} - \bar{x}_{ctrl,obs}))$$
Inference for Numerical Data in R