Is it possible to plot separate meta-analyses with a moderator on the same plot? That is, in this example (taken from the metafor package website: https://www.metafor-project.org/doku.php/plots:forest_plot_with_subgroups)
library(metafor)
### copy BCG vaccine meta-analysis data into 'dat'
dat <- dat.bcg
### calculate log risk ratios and corresponding sampling variances (and use
### the 'slab' argument to store study labels as part of the data frame)
dat <- escalc(measure="RR", ai=tpos, bi=tneg, ci=cpos, di=cneg, data=dat,
slab=paste(author, year, sep=", "))
### fit random-effects model
res <- rma(yi, vi, data=dat)
### a little helper function to add Q-test, I^2, and tau^2 estimate info
mlabfun <- function(text, res) {
list(bquote(paste(.(text),
" (Q = ", .(formatC(res$QE, digits=2, format="f")),
", df = ", .(res$k - res$p),
", p ", .(metafor:::.pval(res$QEp, digits=2, showeq=TRUE, sep=" ")), "; ",
I^2, " = ", .(formatC(res$I2, digits=1, format="f")), "%, ",
tau^2, " = ", .(formatC(res$tau2, digits=2, format="f")), ")")))}
### set up forest plot (with 2x2 table counts added; the 'rows' argument is
### used to specify in which rows the outcomes will be plotted)
forest(res, xlim=c(-16, 4.6), at=log(c(0.05, 0.25, 1, 4)), atransf=exp,
ilab=cbind(tpos, tneg, cpos, cneg), ilab.xpos=c(-9.5,-8,-6,-4.5),
cex=0.75, ylim=c(-1, 27), order=alloc, rows=c(3:4,9:15,20:23),
mlab=mlabfun("RE Model for All Studies", res),
psize=1, header="Author(s) and Year")
### set font expansion factor (as in forest() above) and use a bold font
op <- par(cex=0.75, font=2)
### add additional column headings to the plot
text(c(-9.5,-8,-6,-4.5), 26, c("TB+", "TB-", "TB+", "TB-"))
text(c(-8.75,-5.25), 27, c("Vaccinated", "Control"))
### switch to bold italic font
par(font=4)
### add text for the subgroups
text(-16, c(24,16,5), pos=4, c("Systematic Allocation",
"Random Allocation",
"Alternate Allocation"))
### set par back to the original settings
par(op)
### fit random-effects model in the three subgroups
res.s <- rma(yi, vi, subset=(alloc=="systematic"), data=dat)
res.r <- rma(yi, vi, subset=(alloc=="random"), data=dat)
res.a <- rma(yi, vi, subset=(alloc=="alternate"), data=dat)
### add summary polygons for the three subgroups
addpoly(res.s, row=18.5, mlab=mlabfun("RE Model for Subgroup", res.s))
addpoly(res.r, row= 7.5, mlab=mlabfun("RE Model for Subgroup", res.r))
addpoly(res.a, row= 1.5, mlab=mlabfun("RE Model for Subgroup", res.a))
### fit meta-regression model to test for subgroup differences
res <- rma(yi, vi, mods = ~ alloc, data=dat)
### add text for the test of subgroup differences
text(-16, -1.8, pos=4, cex=0.75, bquote(paste("Test for Subgroup Differences: ",
Q[M], " = ", .(formatC(res$QM, digits=2, format="f")), ", df = ", .(res$p - 1),
", p = ", .(formatC(res$QMp, digits=2, format="f")))))
if I add
res <- rma(yi, vi, data=dat, mods=moderator)
then I have the same moderator for each effect size, and there will be a grey diamond indicating the expected effect size next to each effect size. I would like to add a moderator separately for every allocation group, but not add a moderator of allocation, just treat each allocation as an independent subgroup, which happens to be plotted together. Is that possible? For example by plotting multiple rma models in one plot? In other words, can I run separate analyses for each allocation group, but then plot them as one plot to save space and make comparison easier?