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/03/19 13:31] – Wolfgang Viechtbauer | plots:forest_plot_with_subgroups [2021/03/29 19:47] – Wolfgang Viechtbauer | ||
---|---|---|---|
Line 14: | Line 14: | ||
library(metafor) | library(metafor) | ||
- | ### decrease margins so the full space is used | + | ### copy BCG vaccine meta-analysis data into ' |
- | par(mar=c(4, | + | dat <- dat.bcg |
- | ### fit random-effects model (use slab argument to define | + | ### calculate log risk ratios and corresponding sampling variances |
- | res <- rma(ai=tpos, bi=tneg, ci=cpos, di=cneg, data=dat.bcg, measure=" | + | ### the 'slab' |
- | | + | dat <- escalc(measure=" |
+ | slab=paste(author, | ||
- | ### set up forest plot (with 2x2 table counts added; rows argument is used | + | ### fit random-effects model |
- | ### to specify | + | res <- rma(yi, vi, data=dat) |
+ | |||
+ | ### set up forest plot (with 2x2 table counts added; | ||
+ | ### 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, 6), at=log(c(0.05, | ||
- | | + | |
| | ||
- | | + | |
| | ||
Line 34: | Line 38: | ||
", | ", | ||
| | ||
+ | |||
+ | ### 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(" | ||
+ | Q[M], " = ", .(formatC(res$QM, | ||
+ | ", | ||
### set font expansion factor (as in forest() above) and use bold italic | ### set font expansion factor (as in forest() above) and use bold italic | ||
Line 55: | Line 67: | ||
### fit random-effects model in the three subgroups | ### fit random-effects model in the three subgroups | ||
- | res.s <- rma(ai=tpos, bi=tneg, ci=cpos, di=cneg, data=dat.bcg, | + | res.s <- rma(yi, vi, subset=(alloc==" |
- | subset=(alloc==" | + | res.r <- rma(yi, vi, subset=(alloc==" |
- | res.r <- rma(ai=tpos, bi=tneg, ci=cpos, di=cneg, data=dat.bcg, | + | res.a <- rma(yi, vi, subset=(alloc==" |
- | subset=(alloc==" | + | |
- | res.a <- rma(ai=tpos, bi=tneg, ci=cpos, di=cneg, data=dat.bcg, | + | |
- | subset=(alloc==" | + | |
### add summary polygons for the three subgroups | ### add summary polygons for the three subgroups |
plots/forest_plot_with_subgroups.txt · Last modified: 2023/09/21 19:09 by Wolfgang Viechtbauer