plots:forest_plot_with_subgroups
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
plots:forest_plot_with_subgroups [2020/06/03 07:36] – Wolfgang Viechtbauer | plots:forest_plot_with_subgroups [2021/05/16 16:06] – Wolfgang Viechtbauer | ||
---|---|---|---|
Line 24: | Line 24: | ||
### fit random-effects model | ### fit random-effects model | ||
res <- rma(yi, vi, data=dat) | res <- rma(yi, vi, data=dat) | ||
+ | |||
+ | ### a little helper function to add Q-test, I^2, and tau^2 estimate info | ||
+ | mlabfun <- function(text, | ||
+ | | ||
+ | " (Q = ", .(formatC(res$QE, | ||
+ | ", df = ", .(res$k - res$p), | ||
+ | ", p ", .(metafor::: | ||
+ | I^2, " = ", .(formatC(res$I2, | ||
+ | tau^2, " = ", .(formatC(res$tau2, | ||
### set up forest plot (with 2x2 table counts added; the ' | ### set up forest plot (with 2x2 table counts added; the ' | ||
### 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, 6), at=log(c(0.05, | + | forest(res, xlim=c(-16, |
| | ||
| | ||
- | | + | |
- | xlab=" | + | mlab=mlabfun("RE Model for All Studies", |
+ | psize=1, header=" | ||
- | ### add text with Q-value, dfs, p-value, | + | ### set font expansion factor (as in forest() above) |
- | text(-16, -1, pos=4, | + | op <- par(cex=0.75, |
- | | + | |
- | ", | + | |
- | | + | |
- | ### fit meta-regression model to test for subgroup differences | + | ### add additional column headings |
- | res <- rma(yi, vi, mods = ~ alloc, data=dat) | + | text(c(-9.5,-8,-6,-4.5), 26, c("TB+", |
- | + | text(c(-8.75,-5.25), 27, c(" | |
- | ### 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], " | + | |
- | | + | |
- | ### set font expansion factor (as in forest() above) and use bold italic | + | ### switch to bold italic font |
- | ### font and save original settings in object ' | + | par(font=4) |
- | op <- par(cex=0.75, | + | |
### add text for the subgroups | ### add text for the subgroups | ||
Line 55: | Line 57: | ||
" | " | ||
" | " | ||
- | |||
- | ### switch to bold font | ||
- | par(font=2) | ||
- | |||
- | ### add column headings to the plot | ||
- | text(c(-9.5, | ||
- | text(c(-8.75, | ||
### set par back to the original settings | ### set par back to the original settings | ||
Line 68: | Line 63: | ||
### fit random-effects model in the three subgroups | ### fit random-effects model in the three subgroups | ||
res.s <- rma(yi, vi, subset=(alloc==" | res.s <- rma(yi, vi, subset=(alloc==" | ||
- | res.r <- rma(yi, vi, subset=(alloc==" | + | res.r <- rma(yi, vi, subset=(alloc==" |
- | res.a <- rma(yi, vi, subset=(alloc==" | + | res.a <- rma(yi, vi, subset=(alloc==" |
### add summary polygons for the three subgroups | ### add summary polygons for the three subgroups | ||
- | addpoly(res.s, | + | addpoly(res.s, |
- | addpoly(res.r, | + | addpoly(res.r, |
- | addpoly(res.a, | + | addpoly(res.a, |
- | ### add text with Q-value, dfs, p-value, and I^2 statistic | + | ### fit meta-regression model to test for subgroup differences |
- | text(-16, 18.5, pos=4, cex=0.75, bquote(paste(" | + | res <- rma(yi, vi, mods = ~ alloc, data=dat) |
- | | + | |
- | ", p = ", .(formatC(res.s$QEp, | + | ### add text for the test of subgroup differences |
- | .(formatC(res.s$I2, | + | text(-16, |
- | text(-16, | + | Q[M], " = ", .(formatC(res$QM, digits=2, format=" |
- | .(formatC(res.r$QE, digits=2, format="f")), ", df = ", .(res.r$k - res.r$p), | + | ", |
- | ", | + | |
- | .(formatC(res.r$I2, digits=1, format=" | + | |
- | text(-16, 1.5, pos=4, cex=0.75, bquote(paste(" | + | |
- | | + | |
- | ", | + | |
- | | + | |
</ | </ | ||
plots/forest_plot_with_subgroups.txt · Last modified: 2023/09/21 19:09 by Wolfgang Viechtbauer