user4351176
user4351176

Reputation: 43

Pooling glmers of imputed datasets

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.

Upvotes: 4

Views: 1921

Answers (2)

RayVelcoro
RayVelcoro

Reputation: 534

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.

Upvotes: 1

Ben Bolker
Ben Bolker

Reputation: 226182

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 ...)

Upvotes: 3

Related Questions