R による数値データの推測
Mine Cetinkaya-Rundel
Associate Professor of the Practice, Duke University
問題の背景:胚性幹細胞を用いた治療は、従来療法と比べて心臓発作後の心機能改善に有効か?
データ:openintro パッケージの stem.cell データ
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
ステップ1. 各羊の change を計算:心拍出量の治療前後の差。
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 ?
ステップ2. 仮説の設定:
$H_0: \mu_{esc} = \mu_{ctrl}$;治療群と対照群の平均変化量に差はない。
$H_A: \mu_{esc} > \mu_{ctrl}$;治療群の平均変化量は対照群より大きい。
ステップ3. 仮説検定を実施します。
change の値を18枚のカードに書く。change 平均の差)を計算・記録する。infer パッケージを使って検定を実施します:
library(infer)
データフレームからモデルを指定します:
library(infer)
diff_ht_mean <- stem.cell %>%
specify(__) %>% # y ~ x
...
帰無仮説を宣言します(平均の差なし):
library(infer)
diff_ht_mean <- stem.cell %>%
specify(__) %>% # y ~ x
hypothesize(null = __) %>% # "independence" or "point"
...
$H_0$ が真と仮定してリサンプルを生成します:
library(infer)
diff_ht_mean <- stem.cell %>%
specify(__) %>% # y ~ x
hypothesize(null = __) %>% # "independence" or "point"
generate(reps = __, type = __) %>% # "bootstrap", "permute", or "simulate"
...
検定統計量を計算します:
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
シミュレーションで得られた標本平均の差が観測値と同等以上に極端となる割合をp値として算出します。
$$P ((\bar{x}_{esc,sim} - \bar{x}_{ctrl,sim}) \ge (\bar{x}_{esc,obs} - \bar{x}_{ctrl,obs}))$$
R による数値データの推測