我是新来的包裹 mice
在 R 中。但我试图从 popmis
估算 5 个数据集然后安装一个 lmer()
型号 with()
最后pool()
穿过他们。
我认为pool()
函数在 mice()
不适用于 lmer()
来自 lme4
的来电包,对吗?
如果是这种情况,有没有办法编写一个自定义函数,其作用类似于 pool()
对于我下面的情况?
library(mice)
library(lme4)
imp <- mice(popmis, m = 5) # `popmis` is a dataset from `mice`
fit <- with(imp, lme4::lmer(popular ~ sex + (1|school))) # works fine.
pool(fit) # BUT this one fails, should I loop here?
最佳答案
我有你的解决方案。就像install.packages("broom.mixed")
一样简单然后 library(broom.mixed)
. broom.mixed
包提供了正确的 glance
方法
# install.packages("broom.mixed")
library(mice)
library(lme4)
library(broom.mixed)
imp <- mice(popmis, m = 5) # `popmis` is a dataset from `mice`
fit <- with(data = imp, exp = lme4::lmer(popular ~ sex + (1|school)))
pool(fit)
结果:> pool(fit)
Class: mipo m = 5
term m estimate ubar b t dfcom df riv lambda fmi
1 (Intercept) 5 4.9122016 0.007589694 0.0003823641 0.008048531 1996 743.8691 0.06045526 0.05700878 0.05953397
2 sex 5 0.8378947 0.001187606 0.0002937859 0.001540149 1996 72.7305 0.29685175 0.22890184 0.24926611
Ben Bolker is the author of broom.mixed
关于r - 使用来自库 mouse() 的估算数据集来拟合 R 中的多级模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64735451/