Search code examples
rr-forestplotmetafor

How can I add tau^2 to Forest Plot in metafor R-package?


I am conducting a meta-analysis in R with the metafor package. I followed the tutorial on http://www.metafor-project.org/doku.php/plots:forest_plot_with_subgroups

How can I add tau^2 to "RE Model for All studies"?

library(metafor)

### load BCG vaccine dataset
data(dat.bcg)

res <- rma(ai=tpos, bi=tneg, ci=cpos, di=cneg, data=dat.bcg, measure="OR",
       slab=paste(author, year, sep=", "), method="REML")

###Plot Forest Plot
forest(res)

### Add Text
text(-5, -1, pos=4, cex=0.75, bquote(paste("RE Model for All Studies (Q 
= ",.(formatC(res$QE, digits=2, format="f")), ", df = ", .(res$k - 
res$p),", p = ", .(formatC(res$QEp, digits=2, format="f")), "; ", I^2, " = ",.(formatC(res$I2, digits=1, format="f")), "%)")))

Thanks in advance, C.


Solution

  • This will print a Greek tau with superscript-2 followed by two decimal places of the tau2 item in the res object:

    text(-5, -0.5, pos=4, cex=0.75, bquote(
    paste("RE Model for All Studies (Q = ",
    .(formatC(res$QE, digits=2, format="f")), 
    ", df = ", .(res$k - res$p),", p = ", 
    .(formatC(res$QEp, digits=2, format="f")),
     "; ", I^2, " = ",
    .(formatC(res$I2, digits=1, format="f")), 
     "%)", "; ", tau^2 == 
    .(formatC(res$tau2, digits=2, format="f")))))
    

    I moved the text up a half line so it didn't overwrite the summary OR-diamond. You should understand that you are actually using the plotmath paste function and that means you can change tau to Tau if you want a capital-Greek-Tau. Read ?plotmath.

    enter image description here