4

The problem:

I have a dataset, with some missing predictor values. I'd like to pool glmer models together which have been applied to these imputation sets. I'm using the mice package to create the imputations (I've also used amelia and mi too with no success). I'd like to extract the fixed effects primarily.

Using the pool() function within the mice package returns the error:

Error in qhat[i, ] : incorrect number of dimensions

I've tried to use and adapt a previous rewrite of the pool() function here:

https://github.com/stefvanbuuren/mice/pull/5

There's probably an obvious solution I'm overlooking!

Here's an example:

# 1. create data (that can be replicated and converge later)

data = data.frame(x1=c(rep("1",0.1*1000), rep("0",0.5*1000), 
                       rep("1",0.3*1000), rep("0",0.1*1000)), 
                  x2=c(rep("fact1",0.55*1000), rep("fact2",0.1*1000), 
                       rep(NA,0.05*1000), rep("fact3",0.3*1000)),
                  centre=c(rep("city1",0.1*1000), rep("city2",0.2*1000), 
                           rep("city3",0.15*1000), rep("city1",0.25*1000), 
                           rep("city2",0.3*1000)                          ))

# 2. set factors
data = sapply(data, as.factor)

# 3. mice imputation 
library(mice)
imp.data = mice(data, m=5, maxit=20, seed=1234, pri=F) 

# 4. apply the glmer function
library(lme4)
mice.fit = with(imp.data, glmer(x1~x2+(1|centre), family='binomial'))

# 5. pool imputations together
pooled.mi = pool(mice.fit)

The other function I've applied at step 4 is below, in the hope it'd create an object amenable to pool().

mice.fit = lapply(imp.data$imp, function(d){ glmer(x1~x2+(1|centre), data=d, 
                                                   family='binomial')        })

I've got a work around that involves using a meta-analysis model to pool the results of each of the fixed effects of the glmer models. That works- but it'd be much better to have the Rubin model working.

2 Answers 2

3

This Just Works for me after making my own fork of mice, pulling the extended version you referenced above into it, and cleaning it up a little bit: try

devtools::install_github("bbolker/mice")

and see how your process goes after that. (If it works, someone should submit a reminder/new pull request ...)

4
  • Dear Ben, Sadly, when I try your command above (R version 3.3.0, mice_2.30, lme4_1.1-12), I get following error message „Error: Could not find build tools necessary to build mice“. Best regards
    – Kev
    Mar 23, 2017 at 18:10
  • you need to have Rtools installed.
    – Ben Bolker
    Mar 23, 2017 at 18:15
  • Thank you for your fast answer, but I am using a mac (mac os 10.11.6). As far as I know there is no Rtools for macintosh.
    – Kev
    Mar 23, 2017 at 18:44
  • "Rtools for MacOS" = "XCode" (see rstudio.com/products/rpackages/devtools and search for XCode)
    – Ben Bolker
    Mar 23, 2017 at 18:50
1

Is there a difference between an object of class "glmerMod" and "lmerMod"? I am unfamiliar with that package lme4. But if there is no difference, you can change the class of the mice.fit analyses to "lmerMod" and then it should run fine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.