tokyo r #37 rubin's rule

17
ちょっと詳しいMissing Dataお話 ~Rubin’s Rule~ 2014/03/29 Tokyo.R #37 @Hiro_macchan

Upload: hiroki-matsui

Post on 07-Jul-2015

876 views

Category:

Healthcare


2 download

TRANSCRIPT

Page 1: Tokyo r #37 Rubin's Rule

ちょっと詳しいMissing Dataのお話

~Rubin’s Rule~2014/03/29

Tokyo.R #37

@Hiro_macchan

Page 2: Tokyo r #37 Rubin's Rule

はじめに

• この資料は個人の見解で有り、いかなる所属組織の公式見解ではありません。

2014/3/29 2

Page 3: Tokyo r #37 Rubin's Rule

自己紹介• Matsui Hiroki (RPT,MPH)

• 出身:琵琶湖 住まい:荒川 職場:文京区

• 職業:臨床疫学と医療政策に関するSQLを書きながら、ルーターの設定をする下っ端アンチリア充研究者。

• Twitter: Hiro_macchan

未熟者ですので間違い等は指摘して下さい。

(できれば、お手柔らかに。。)

2014/3/29 3

Page 4: Tokyo r #37 Rubin's Rule

背景

• 仕事柄、予測モデルの構築ではなく、因果関係の推計を行うためにデータを扱うことが多い。

• データは不完全であることが多い。

• 欠測したデータの取り扱いを勉強する機会があった。

• Rubin’s Rule すげぇと感じたので少し紹介したい。。

2014/3/29 4

Page 5: Tokyo r #37 Rubin's Rule

これまでのあらすじ

Tokyo.R #28 http://www.slideshare.net/dichika/maeshori-missing

臨床疫学研究における報告の質向上のための統計学の研究会第14回研究集会資料(資料一部非公開)http://blue.zero.jp/yokumura/workshop.html

行動計量学会第16回春の合宿セミナー欠測データ解析から統計的因果推論へー近年の動向とガイドラインー星野崇宏

オンライン資料無し

2014/3/29 5

Page 6: Tokyo r #37 Rubin's Rule

これまでのあらすじ

Tokyo.R #28 http://www.slideshare.net/dichika/maeshori-missing

臨床疫学研究における報告の質向上のための統計学の研究会第14回研究集会資料(資料一部非公開)http://blue.zero.jp/yokumura/workshop.html

行動計量学会第16回春の合宿セミナー欠測データ解析から統計的因果推論へー近年の動向とガイドラインー星野崇宏

オンライン資料無し

ここで、触れられていなかった話をする事を目標とします。

2014/3/29 6

Page 7: Tokyo r #37 Rubin's Rule

これまでのあらすじ

Tokyo.R #28 http://www.slideshare.net/dichika/maeshori-missing

• 欠測を可視化する。• 欠測を分類する。

MCAR、MAR、MNAR• 分類にあった対応をする。

最尤法か多重代入法(MI)• Rubin すごい。

2014/3/29 7

Page 8: Tokyo r #37 Rubin's Rule

これまでのあらすじ

多重代入法(MI)とは

M個の Imputed data M個の Estimator

各データでのparameter estimate

Missing Data Pooled Estimator

Imputation Data の作成

解析

統合

2014/3/29 8

Page 9: Tokyo r #37 Rubin's Rule

これまでのあらすじ

多重代入法(MI)とは

• R で多重代入法を実行するパッケージ• Norm

• Hmisc

• mi

• mice: Multiple imputation by Chained Equations

• Amelia

2014/3/29 9

Page 10: Tokyo r #37 Rubin's Rule

これまでのあらすじ

miceで行う多重代入法(MI)とは

M個の Imputed data M個の Estimator

各データでのparameter estimate

Missing Data Pooled Estimator

Imputation Data の作成mice

解析:with

統合:pool

pool(with(mice(data),model))2014/3/29 10

Page 11: Tokyo r #37 Rubin's Rule

これまでのあらすじ

miceで行う多重代入法(MI)とは

M個の Imputed data M個の Estimator

各データでのparameter estimate

Missing Data Pooled Estimator

Imputation Data の作成mice()

解析:with()

統合:pool()

pool(with(mice(data),model))2014/3/29 11

Page 12: Tokyo r #37 Rubin's Rule

Rubin’s Rules

Rubin (1987), Little and Rubin (2002)

2014/3/29 12

Page 13: Tokyo r #37 Rubin's Rule

実際に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

Page 14: Tokyo r #37 Rubin's Rule

実際に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

Page 15: Tokyo r #37 Rubin's Rule

実際に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 <- 20estimated_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.042014/3/29

15

Page 16: Tokyo r #37 Rubin's Rule

実際に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 <- 20estimated_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.042014/3/29

16

できた!!!

Page 17: Tokyo r #37 Rubin's Rule

まとめ

• 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