-1

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) 
rnorouzian
  • 7,397
  • 5
  • 27
  • 72

1 Answers1

1

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)

Allan Cameron
  • 147,086
  • 7
  • 49
  • 87
  • Thank you Allan. To understand your code better, you separated the `popular` from `imps` because `popular` was the only variable that had missing in it, right? Otherwise (simply replace `popmis` with `popNCR`), you would have subjected the whole `imps` object to your `lapply()` command? Finally, the `formula` part of `aregImpute()` determines the number of variables thought to be needed for imputation of ANY `NA` in ANY variable type (categorical or continuous)? – rnorouzian Nov 08 '20 at 21:25
  • Much appreciated. – rnorouzian Nov 08 '20 at 21:55