Consolidating imputed dataset accounts

Problem:

I have a dataset with some missing predictor values. I would like to combine the models glmerthat have been applied to these sets of imputations. I use the package miceto create imputation (I also used ameliaand mialso 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:

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

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.

+4
2

mice, , , : try

devtools::install_github("bbolker/mice")

, . ( , - / ...)

+3

"glmerMod" "lmerMod"? lme4. , mice.fit "lmerMod", .

0

Source: https://habr.com/ru/post/1610211/


All Articles