Skip to content
Prev 4446 / 5636 Next

[R-meta] margins command

Dear Patricia,

To start: 'sei = vi' looks wrong. Argument 'sei' is for passing the standard errors to the rma() function, but 'vi' sounds like a variable that contains sampling variances.

This aside, the answer to your question is yes. You can do this with: predict(res, newmods=c(1,1), intercept=FALSE).

As for marginal effects, you can use emmprep() together with the emmeans package (note that you will need to install the 'devel' version of metafor for this, since emmprep() was recent added; https://wviechtb.github.io/metafor/#installation).

An example:

library(metafor)

dat <- dat.bangertdrowns2004

res <- rma(yi, vi, mods = ~ wic + info, data=dat)
res

predict(res, newmods=c(1,1), intercept=FALSE)

sav <- emmprep(res)

library(emmeans)

emmeans(sav, specs="1", weights="proportional")

# this is identical to
predict(res, newmods = colMeans(model.matrix(res))[-1], digits=3)

# marginal means for 'wic' and 'info'
emmeans(sav, specs="wic", weights="proportional")
emmeans(sav, specs="info", weights="proportional")

If you do not want proportional weights, then just leave out the 'weights="proportional"' part.

Best,
Wolfgang