I am using metafor to run a multivariate meta-analysis. I want to predict effects of new moderators but for one of the moderators I do not want to input a value itself, but I want the predict function to meta-analyse that moderator (in the example below this is grade
)
I am using here the toy dataset dat.bangertdrowns2004
.
# load metafor package
library(metafor)
dat <- dat.bangertdrowns2004
# fit model
res <- rma.mv(yi, vi, mods = ~ grade + length + pers - 1, random = ~ 1 | ni, data=dat)
res
# predict
gridpred <- expand.grid(length=4:10, pers=1)
pred.res <- predict.rma(object = res , newmods = as.matrix(gridpred))
When I run this code I get an error as it mentions that I need to input a value for grade
.
Error in predict.rma(object = res, newmods = as.matrix(gridpred)) :
Argument 'newmods' does not specify values for this variable: grade
Is there a way of using predict.rma() to meta-analyse grade across length=4:10
and pers=1
?
If you are indeed looking for such 'adjusted means/estimates', then one would hold the value of grade
constant at its mean. So the syntax would be:
gridpred <- expand.grid(length=4:10, pers=1, grade=colMeans(model.matrix(res))["grade"])
pred.res <- predict.rma(object = res , newmods = as.matrix(gridpred))
pred.res
If you want to use emmeans
, then you would use:
library(emmeans)
sav <- emmprep(res, at=list(pers=1, length=4:10))
emmeans(sav, specs="1", by=c("pers","length"))