8

I'm new to package mice in R. But I'm trying to impute 5 datasets from popmis and then fit an lmer() model with() each and finally pool() across them.

I think the pool() function in mice() doesn't work with the lmer() call from lme4 package, right?

If that is the case, is there a way to write a custom-made function that acts like pool() for my case below?

library(mice)
library(lme4)

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

fit <- with(imp, lme4::lmer(popular ~ sex + (1|school))) # works fine.

pool(fit) # BUT this one fails, should I loop here?
polkas
  • 3,797
  • 1
  • 12
  • 25
rnorouzian
  • 7,397
  • 5
  • 27
  • 72

1 Answers1

5

I have the solution for you. It is as simple as install.packages("broom.mixed") and then library(broom.mixed).broom.mixed package is providing the proper glance method

# install.packages("broom.mixed")
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) 

Results:

> pool(fit)
Class: mipo    m = 5 
         term m  estimate        ubar            b           t dfcom       df        riv     lambda        fmi
1 (Intercept) 5 4.9122016 0.007589694 0.0003823641 0.008048531  1996 743.8691 0.06045526 0.05700878 0.05953397
2         sex 5 0.8378947 0.001187606 0.0002937859 0.001540149  1996  72.7305 0.29685175 0.22890184 0.24926611

Ben Bolker is the author of broom.mixed

polkas
  • 3,797
  • 1
  • 12
  • 25
  • But `ubar` which relates to random-effects in your solution should ONLY show for `(intercept)` NOT for `sex` (as the model only has a random effect for `intercept`), what is going on here? – rnorouzian Nov 09 '20 at 02:00
  • @BenBolker is the author of broom.mixed. For me it looks to be ok though I am not a specialist in mixed models. – polkas Nov 09 '20 at 13:48