Problem:
I have a dataset with some missing predictor values. I would like to combine the models glmer
that have been applied to these sets of imputations. I use the package mice
to create imputation (I also used amelia
and mi
also without success). I would like to extract fixed effects first.
Using a function pool()
in a mouse package returns an error:
Error in qhat[i, ] : incorrect number of dimensions
I tried to use and adapt the previous function entry pool()
here:
https://github.com/stefvanbuuren/mice/pull/5
Probably the obvious solution that I forget about!
Here is an example:
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) ))
data = sapply(data, as.factor)
library(mice)
imp.data = mice(data, m=5, maxit=20, seed=1234, pri=F)
library(lme4)
mice.fit = with(imp.data, glmer(x1~x2+(1|centre), family='binomial'))
pooled.mi = pool(mice.fit)
Another function that I applied in step 4 below is in the hope that it will create an object that can be processed pool()
.
mice.fit = lapply(imp.data$imp, function(d){ glmer(x1~x2+(1|centre), data=d,
family='binomial') })
, glmer
. , , Rubin.