More Related Content
Similar to Tokyo r #37 Rubin's Rule
Similar to Tokyo r #37 Rubin's Rule (20)
Tokyo r #37 Rubin's Rule
- 3. 自己紹介
• Matsui Hiroki (RPT,MPH)
• 出身:琵琶湖 住まい:荒川 職場:文京区
• 職業:臨床疫学と医療政策に関するSQLを書きな
がら、ルーターの設定をする下っ端アンチリア充
研究者。
• Twitter: Hiro_macchan
未熟者ですので間違い等は指摘して下さ
い。
(できれば、お手柔らかに。。)
2014/3/29 3
- 13. 実際にRubin’s Rule を使ってみる
使用するMissing Data
R のmice パッケージに含まれる、nhanes データ
25名のAge, BMI, hyp, chl 欠損有。
age bmi hyp chl
1.00
2.00 22.70 1.00 187.00
1.00 1.00 187.00
3.00
1.00 20.40 1.00 113.00
3.00 184.00
2014/3/29 13
- 14. 実際にRubin’s Rule を使ってみる。
library(mice)
imp_data <- mice::mice(nhanes, seed = 1, m = 20)
fit <- with(imp_data, lm(chl ~ age + bmi))
summary(pool(fit))
est se t df Pr(>|t|) lo 95 hi 95
(Interce
pt)
-0.97 68.08 -0.01 13.17 0.99 -147.85 145.92
age 31.99 12.04 2.66 9.84 0.02 5.10 58.88
bmi 5.12 2.21 2.32 12.96 0.04 0.35 9.88
まずは、mice 使ってやってみる。
2014/3/29 14
- 15. 実際にRubin’s Rule を使ってみる。
# 各imputed data にlmを当てはめて、推計値と標準偏差を引っ張る。
model_Estimate <- function(x){
coef(summary(lm(data = x, formula = chl ~ age + bmi)))[, "Estimate"]
}
model_inSD <- function(x){
coef(summary(lm(data = x, formula = chl ~ age + bmi)))[, "Std. Error"]
}
# complete 関数からimputed data をリストにいったんまとめる。
comp_list <- list()
for (i in 1:20){
comp_list[[i]] <- complete(imp_data, i)
}
# EstimateとSDのマトリックスを吐く
Estimate_Matrix <- sapply(comp_list, model_Estimate)
SD_matrix <- sapply(comp_list, model_inSD)
# Rubin's Ruleを適応し統合
M <- 20
estimated_beta <- mean(Estimate_Matrix["age", ])
estimated_beta_V <- mean(SD_matrix["age", ]^2)
estimated_beta_V_2 <- (1 + (1/M)) * (sum(((Estimate_Matrix["age", ] - estimated_beta)^2)/(M - 1)))
# age の推計量とSDを表示
c(estimated_beta, (estimated_beta_V + estimated_beta_V_2)^(1/2))
> 31.99 12.04
2014/3/29
15
- 16. 実際にRubin’s Rule を使ってみる。
# 各imputed data にlmを当てはめて、推計値と標準偏差を引っ張る。
model_Estimate <- function(x){
coef(summary(lm(data = x, formula = chl ~ age + bmi)))[, "Estimate"]
}
model_inSD <- function(x){
coef(summary(lm(data = x, formula = chl ~ age + bmi)))[, "Std. Error"]
}
# complete 関数からimputed data をリストにいったんまとめる。
comp_list <- list()
for (i in 1:20){
comp_list[[i]] <- complete(imp_data, i)
}
# EstimateとSDのマトリックスを吐く
Estimate_Matrix <- sapply(comp_list, model_Estimate)
SD_matrix <- sapply(comp_list, model_inSD)
# Rubin's Ruleを適応し統合
M <- 20
estimated_beta <- mean(Estimate_Matrix["age", ])
estimated_beta_V <- mean(SD_matrix["age", ]^2)
estimated_beta_V_2 <- (1 + (1/M)) * (sum(((Estimate_Matrix["age", ] - estimated_beta)^2)/(M - 1)))
# age の推計量とSDを表示
c(estimated_beta, (estimated_beta_V + estimated_beta_V_2)^(1/2))
> 31.99 12.04
2014/3/29
16
できた!!!
- 17. まとめ
• mice に限らず多くのMultiple Imputation は Rubin’s Rule による。
• Rubin’s Rule 自体はかなり簡単。
• pool(with(mice(data),model)) はかなり広範なモデルに適応できそ
う。
• 例えば
• Imputed data にクラスターを想定して、lme4を適応しpool
• Imputed data にPropensity Score を適応しpool
• Rubin すげぇ。
2014/3/29 17