问题:
我有一个数据集,其中缺少一些预测值。我想将glmer
已应用于这些插补集的模型汇集在一起。我正在使用该mice
包来创建插补(我也使用过amelia
,mi
但也没有成功)。我想主要提取固定效果。
使用pool()
mouse 包中的函数会返回错误:
Error in qhat[i, ] : incorrect number of dimensions
我尝试在pool()
这里使用和调整之前对函数的重写:
https://github.com/stefvanbuuren/mice/pull/5
我可能忽略了一个明显的解决方案!
这是一个例子:
# 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)
我在步骤 4 中应用的另一个函数如下所示,希望它能创建一个适合pool()
.
mice.fit = lapply(imp.data$imp, function(d){ glmer(x1~x2+(1|centre), data=d,
family='binomial') })
我有一个解决方法,涉及使用元分析模型来汇集模型的每个固定效应的结果glmer
。这行得通——但让鲁宾模型工作会更好。