I computed linear mixed effects models using lme4::lmer() on data that I multiply imputed using the mice package. On these lmer objects, I want to apply ggeffects::ggeffect() to get marginal effects that I can then plot for mean, +1sd and -1sd.
The pool_predictions function seems perfectly suited and does a great job for lm objects; however, for lmer objects the ggeffect() function does not work. ggpredict() for some reason works, but I want to get marginal, not conditional effects.
Here's a minimal reproducible example that I adapted from the pool_predictions() reference (the mixed model doesn't make sense, it's just to create an example):
if (!require("pacman")) install.packages("pacman")
pacman::p_load(mice,stats,lme4,ggeffects)
data("nhanes2")
#First, the working example from the pool_predictions() reference, using an lm object and ggpredict():
imp <- mice(nhanes2, printFlag = FALSE)
predictions1 <- lapply(1:5, function(i) {
m1 <- lm(bmi ~ age + hyp + chl, data = complete(imp, action = i))
ggpredict(m1, "age")
})
pool_predictions(predictions1)
#Now the same example, but using ggeffect() on the lm object, which also works:
predictions2 <- lapply(1:5, function(i) {
m2 <- lm(bmi ~ age + hyp + chl, data = complete(imp, action = i))
ggeffect(m2, "age")
})
pool_predictions(predictions2)
#It also seems to work for lmer objects, at least when using ggpredict():
predictions3 <- lapply(1:5, function(i) {
m3 <- lmer(bmi ~ age + chl + (1|hyp), data = complete(imp, action = i))
ggpredict(m3, "age")
})
pool_predictions(predictions3)
#But when I use ggeffect() instead of ggpredict(), this doesn't work anymore for lmer objects.
predictions4 <- lapply(1:5, function(i) {
m4 <- lmer(bmi ~ age + chl + (1|hyp), data = complete(imp, action = i))
ggeffect(m4, "age")
})
pool_predictions(predictions4)
Does anyone have an idea why this happens or has any tips how I can get the pooled marginal effects for my lmer object?
Thanks a lot!
Antje