The metafor Package

A Meta-Analysis Package for R

User Tools

Site Tools


plots:forest_plot_with_subgroups

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
plots:forest_plot_with_subgroups [2021/12/20 15:39] Wolfgang Viechtbauerplots:forest_plot_with_subgroups [2023/09/21 19:09] (current) Wolfgang Viechtbauer
Line 26: Line 26:
  
 ### a little helper function to add Q-test, I^2, and tau^2 estimate info ### a little helper function to add Q-test, I^2, and tau^2 estimate info
-mlabfun <- function(text, res) {+mlabfun <- function(text, x) {
    list(bquote(paste(.(text),    list(bquote(paste(.(text),
-      " (Q = ", .(formatC(res$QE, digits=2, format="f")), +      " (Q = ", .(fmtx(x$QE, digits=2)), 
-      ", df = ", .(res$k - res$p), +      ", df = ", .(x$k - x$p), ", ", 
-      ", ", .(metafor:::.pval(res$QEp, digits=2showeq=TRUE, sep=" ")), "; ", +      .(fmtp(x$QEp, digits=3pname="p", add0=TRUE, sep=TRUE, equal=TRUE)), "; ", 
-      I^2, " = ", .(formatC(res$I2, digits=1, format="f")), "%, ", +      I^2, " = ", .(fmtx(x$I2, digits=1)), "%, ", 
-      tau^2, " = ", .(formatC(res$tau2, digits=2, format="f")), ")")))}+      tau^2, " = ", .(fmtx(x$tau2, digits=2)), ")")))}
  
 ### set up forest plot (with 2x2 table counts added; the 'rows' argument is ### set up forest plot (with 2x2 table counts added; the 'rows' argument is
 ### used to specify in which rows the outcomes will be plotted) ### 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, forest(res, xlim=c(-16, 4.6), at=log(c(0.05, 0.25, 1, 4)), atransf=exp,
-       ilab=cbind(dat$tpos, dat$tneg, dat$cpos, dat$cneg), +       ilab=cbind(tpos, tneg, cpos, cneg), ilab.xpos=c(-9.5,-8,-6,-4.5), 
-       ilab.xpos=c(-9.5,-8,-6,-4.5), cex=0.75, ylim=c(-1, 27), +       cex=0.75, ylim=c(-1, 27), order=alloc, rows=c(3:4,9:15,20:23),
-       order=dat$alloc, rows=c(3:4,9:15,20:23),+
        mlab=mlabfun("RE Model for All Studies", res),        mlab=mlabfun("RE Model for All Studies", res),
        psize=1, header="Author(s) and Year")        psize=1, header="Author(s) and Year")
Line 76: Line 75:
 ### add text for the test of subgroup differences ### add text for the test of subgroup differences
 text(-16, -1.8, pos=4, cex=0.75, bquote(paste("Test for 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), +     Q[M], " = ", .(fmtx(res$QM, digits=2)), 
-     ", p = ", .(formatC(res$QMp, digits=2, format="f")))))+     ", df = ", .(res$p - 1), ", ", 
 +     .(fmtp(res$QMp, digits=2, pname="p", add0=TRUE, sep=TRUE, equal=TRUE)))))
 </code> </code>
  
plots/forest_plot_with_subgroups.txt · Last modified: 2023/09/21 19:09 by Wolfgang Viechtbauer