rmissing-dataimputationr-micehmisc

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


Below, I've used library(mice) to multiply impute 5 datasets from my data.frame popmis. Then, I performed my desired analysis with() all those 5 imputed datasets and finally pool() across those analyses.

Question: Is it possible to replicate the same steps using 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) 

Solution

  • You can use 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
    

    Which gives similar results to your code using 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
    

    Created on 2020-11-08 by the reprex package (v0.3.0)