使用 R 中的库 (Hmisc) 复制 `mice()` 的结果

replicate the result of `mice()` using library(Hmisc) in R

下面,我使用 library(mice) 从我的 data.frame popmis 中乘以推算 5 个数据集。然后,我对所有这 5 个估算数据集进行了我想要的分析 with(),最后对这些分析进行了 pool()

问题:是否可以使用library(Hmisc)复制相同的步骤?

library(mice)
library(lme4)
library(broom.mixed)

imp <- mice(popmis, m = 5) # `popmis` is a dataset from `mice`

fit <- with(data = imp, exp = lme4::lmer(popular ~ sex + (1|school)))

pool(fit) 

您可以使用 Hmisc::aregImpute:

library(Hmisc)
library(mice)
library(lme4)
library(broom.mixed)

imps <- aregImpute(~pupil + school + popular + sex + texp + teachpop, 
                   data = popmis)$imputed$popular
#> Iteration 1 Iteration 2 Iteration 3 Iteration 4 Iteration 5 

fit2 <- lapply(1:5, function(x) lme4::lmer(popular ~ sex + (1|school),
       data = within(popmis, popular[is.na(popular)] <- imps[,x])))

pool(fit2) 
#> Class: mipo    m = 5 
#>          term m  estimate        ubar            b           t dfcom        df
#> 1 (Intercept) 5 4.9029688 0.007668137 0.0006677781 0.008469470  1996 358.18134
#> 2         sex 5 0.8569774 0.001215393 0.0002971695 0.001571996  1996  73.99956
#>         riv     lambda        fmi
#> 1 0.1045017 0.09461438 0.09962785
#> 2 0.2934059 0.22684749 0.24692949

使用 mice:

给出与您的代码相似的结果
imp <- mice(popmis, m = 5) # `popmis` is a dataset from `mice`

fit <- with(data = imp, exp = lme4::lmer(popular ~ sex + (1|school)))

pool(fit) 
#> Class: mipo    m = 5 
#>          term m  estimate        ubar            b           t dfcom        df
#> 1 (Intercept) 5 4.8984082 0.007438482 0.0004775986 0.008011601  1996 549.60298
#> 2         sex 5 0.8543277 0.001177158 0.0009930326 0.002368797  1996  15.55799
#>          riv     lambda        fmi
#> 1 0.07704775 0.07153605 0.07489638
#> 2 1.01230146 0.50305656 0.55661230

reprex package (v0.3.0)

于 2020-11-08 创建