鏈式方程多重插補(MICE)

在 R 中以插補處理遺漏值

Michal Oleszak

Machine Learning Engineer

MICE 演算法

一張圖示出 MICE 演算法的四個步驟。從「incomplete data」節點出發,有三條箭頭通往三個「imputed data」節點,箭頭標示為「mice()」。每個節點再以標示「with()」的箭頭連到「analysis results」。這些節點再以標示「pooled()」的箭頭匯入同一個最終節點「pooled results」。

1 van Buuren, S., & Groothuis-Oudshoorn, C. G. M. (2011). mice: Multivariate Imputation by Chained Equations in R. Journal of statistical software, 45(3).
在 R 中以插補處理遺漏值

MICE:優缺點

優點:

  • 複製次數少於自助法(bootstrap)。
  • 適用 MAR 與 MCAR 資料。
  • 可對 MNAR 進行敏感度分析。

缺點:

  • 僅支援特定插補方法。
  • 需要較多調校(模型選擇、預測變數選取)。
在 R 中以插補處理遺漏值

mice - with - pool 的流程

nhanes 進行 20 次插補:

library(mice)
nhanes_multiimp <- mice(nhanes, m = 20)

對每個插補資料集擬合線性迴歸模型:

lm_multiimp <- with(nhanes_multiimp, lm(Weight ~ Height + TotChol + PhysActive))

匯整迴歸結果:

lm_pooled <- pool(lm_multiimp)
在 R 中以插補處理遺漏值

分析匯整後的結果

summary(lm_pooled, conf.int = TRUE, conf.level = 0.95)
            estimate std.error statistic      df p.value    2.5 %   97.5 %
(Intercept) -122.964    10.933   -11.247 735.389   0.000 -144.428 -101.500
Height         1.086     0.060    18.158 796.106   0.000    0.968    1.203
TotChol        2.653     0.884     3.003 305.460   0.003    0.915    4.392
PhysActive    -1.746     1.422    -1.228 733.957   0.220   -4.536    1.045
在 R 中以插補處理遺漏值

MICE:可用方法

van Buuren 等人論文中的一張表,列出 MICE 可用的插補模型。每個模型包含名稱、關鍵字、可用的變數型別,以及是否為預設選項。

1 van Buuren, S., & Groothuis-Oudshoorn, C. G. M. (2011). mice: Multivariate Imputation by Chained Equations in R. Journal of statistical software, 45(3).
在 R 中以插補處理遺漏值

依變數型別選方法

mice() 的參數 defaultMethod 是一個含 4 個字串的向量,用來指定下列方法:

  1. 連續變數
  2. 二元變數
  3. 類別變數(無序因子)
  4. 因子變數(有序因子)
nhanes_multiimp <- mice(nhanes, m = 20, 
                        defaultMethod = c("pmm", "logreg", "polyreg", "polr"))
在 R 中以插補處理遺漏值

預測矩陣(predictor matrix)

predictorMatrix 決定用哪些變數來插補其他變數。

nhanes_multiimp <- mice(nhanes, m = 20)
nhanes_multiimp$predictorMatrix
           Age Gender Weight Height Diabetes TotChol Pulse PhysActive
Age          0      1      1      1        1       1     1          1
Gender       1      0      1      1        1       1     1          1
Weight       1      1      0      1        1       1     1          1
Height       1      1      1      0        1       1     1          1
Diabetes     1      1      1      1        0       1     1          1
TotChol      1      1      1      1        1       0     1          1
Pulse        1      1      1      1        1       1     0          1
PhysActive   1      1      1      1        1       1     1          0
在 R 中以插補處理遺漏值

為各變數選預測因子

  • 理想狀況下,應先進行妥善的模型選擇。
  • 快速替代法:只用與目標具相關性的變數。
pred_mat <- quickpred(nhanes, mincor = 0.25)
nhanes_multiimp <- mice(nhanes, m = 20, predictorMatrix = pred_mat)
print(pred_mat)
           Age Gender Weight Height Diabetes TotChol Pulse PhysActive
Age          0      0      0      0        0       0     0          0
Gender       0      0      0      0        0       0     0          0
Weight       1      1      0      0        0       0     1          0
...
在 R 中以插補處理遺漏值

一起來練習吧!

在 R 中以插補處理遺漏值

Preparing Video For Download...