链式方程多重插补

R 中的缺失值填补处理

Michal Oleszak

Machine Learning Engineer

MICE 算法

一个图示说明 MICE 算法的四个阶段。由"非完整数据"节点出发,有三条箭头指向"插补数据"节点,箭头标注为函数"mice()"。每个"插补数据"节点再以标注"with()"的箭头连接到"分析结果"节点,随后以标注"pooled()"的箭头汇总到最终的"合并结果"节点。

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:优缺点

优点:

  • 比自助法需要更少的重复。
  • 适用于 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 中的缺失值填补处理

预测矩阵

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 中的缺失值填补处理

让我们用 MICE 做插补练习!

R 中的缺失值填补处理

Preparing Video For Download...