[R] metafor package
John Peterson
john.peterson.can at gmail.com
Mon Dec 7 01:39:27 CET 2015
Hi Everyone,
I am conducting a meta-analysis using the metafor package. I am interested
in obtaining an estimate by subgroup only without showing an overall
effect. This is directly from the metafor website. How would i modify this
code to only show subgroup effects? Further, I want to show weights by
subgroup. The option showweights=TRUE does not display weights by subgroup
but by the weight of each study in comparison to all studies (and not the
subgroup). You help would be appreciated.
library <http://stat.ethz.ch/R-manual/R-devel/library/base/html/library.html>(metafor)
### to save as png filepng
<http://stat.ethz.ch/R-manual/R-devel/library/grDevices/html/png.html>(filename="forest_plot_with_subgroups.png",
res=95, width=680, height=680, type="cairo")
### decrease margins so the full space is usedpar
<http://stat.ethz.ch/R-manual/R-devel/library/graphics/html/par.html>(mar=c
<http://stat.ethz.ch/R-manual/R-devel/library/base/html/c.html>(4,4,1,2))
### load BCG vaccine datadata
<http://stat.ethz.ch/R-manual/R-devel/library/utils/html/data.html>(dat.bcg)
### fit random-effects model (use slab argument to define study labels)
res <- rma(ai=tpos, bi=tneg, ci=cpos, di=cneg, data
<http://stat.ethz.ch/R-manual/R-devel/library/utils/html/data.html>=dat.bcg,
measure="RR",
slab=paste
<http://stat.ethz.ch/R-manual/R-devel/library/base/html/paste.html>(author,
year, sep=", "), method="REML")
### set up forest plot (with 2x2 table counts added; rows argument is
used### to specify exactly in which rows the outcomes will be plotted)
forest(res, xlim=c
<http://stat.ethz.ch/R-manual/R-devel/library/base/html/c.html>(-16,
6), at=log <http://stat.ethz.ch/R-manual/R-devel/library/base/html/log.html>(c
<http://stat.ethz.ch/R-manual/R-devel/library/base/html/c.html>(.05,
.25, 1, 4)), atransf=exp
<http://stat.ethz.ch/R-manual/R-devel/library/base/html/exp.html>,
ilab=cbind
<http://stat.ethz.ch/R-manual/R-devel/library/base/html/cbind.html>(dat.bcg$tpos,
dat.bcg$tneg, dat.bcg$cpos, dat.bcg$cneg),
ilab.xpos=c
<http://stat.ethz.ch/R-manual/R-devel/library/base/html/c.html>(-9.5,-8,-6,-4.5),
cex=.75, ylim=c
<http://stat.ethz.ch/R-manual/R-devel/library/base/html/c.html>(-1,
27),
order <http://stat.ethz.ch/R-manual/R-devel/library/base/html/order.html>=order
<http://stat.ethz.ch/R-manual/R-devel/library/base/html/order.html>(dat.bcg$alloc),
rows=c <http://stat.ethz.ch/R-manual/R-devel/library/base/html/c.html>(3:4,9:15,20:23),
xlab="Relative Risk", mlab="RE Model for All Studies", psize=1)
### set font expansion factor (as in forest() above) and use bold
italic### font and save original settings in object 'op'
op <- par <http://stat.ethz.ch/R-manual/R-devel/library/graphics/html/par.html>(cex=.75,
font=4)
### add text for the subgroupstext
<http://stat.ethz.ch/R-manual/R-devel/library/graphics/html/text.html>(-16,
c <http://stat.ethz.ch/R-manual/R-devel/library/base/html/c.html>(24,16,5),
pos=4, c <http://stat.ethz.ch/R-manual/R-devel/library/base/html/c.html>("Systematic
Allocation",
"Random Allocation",
"Alternate Allocation"))
### switch to bold fontpar
<http://stat.ethz.ch/R-manual/R-devel/library/graphics/html/par.html>(font=2)
### add column headings to the plottext
<http://stat.ethz.ch/R-manual/R-devel/library/graphics/html/text.html>(c
<http://stat.ethz.ch/R-manual/R-devel/library/base/html/c.html>(-9.5,-8,-6,-4.5),
26, c <http://stat.ethz.ch/R-manual/R-devel/library/base/html/c.html>("TB+",
"TB-", "TB+", "TB-"))text
<http://stat.ethz.ch/R-manual/R-devel/library/graphics/html/text.html>(c
<http://stat.ethz.ch/R-manual/R-devel/library/base/html/c.html>(-8.75,-5.25),
27, c <http://stat.ethz.ch/R-manual/R-devel/library/base/html/c.html>("Vaccinated",
"Control"))text
<http://stat.ethz.ch/R-manual/R-devel/library/graphics/html/text.html>(-16,
26, "Author(s) and Year", pos=4)text
<http://stat.ethz.ch/R-manual/R-devel/library/graphics/html/text.html>(6,
26, "Relative Risk [95% CI]", pos=2)
### set par back to the original settingspar
<http://stat.ethz.ch/R-manual/R-devel/library/graphics/html/par.html>(op)
### fit random-effects model in the three subgroups
res.s <- rma(ai=tpos, bi=tneg, ci=cpos, di=cneg, data
<http://stat.ethz.ch/R-manual/R-devel/library/utils/html/data.html>=dat.bcg,
measure="RR",
subset
<http://stat.ethz.ch/R-manual/R-devel/library/base/html/subset.html>=(alloc=="systematic"),
method="REML")
res.r <- rma(ai=tpos, bi=tneg, ci=cpos, di=cneg, data
<http://stat.ethz.ch/R-manual/R-devel/library/utils/html/data.html>=dat.bcg,
measure="RR",
subset
<http://stat.ethz.ch/R-manual/R-devel/library/base/html/subset.html>=(alloc=="random"),
method="REML")
res.a <- rma(ai=tpos, bi=tneg, ci=cpos, di=cneg, data
<http://stat.ethz.ch/R-manual/R-devel/library/utils/html/data.html>=dat.bcg,
measure="RR",
subset
<http://stat.ethz.ch/R-manual/R-devel/library/base/html/subset.html>=(alloc=="alternate"),
method="REML")
### add summary polygons for the three subgroups
addpoly(res.s, row
<http://stat.ethz.ch/R-manual/R-devel/library/base/html/row.html>=18.5,
cex=.75, atransf=exp
<http://stat.ethz.ch/R-manual/R-devel/library/base/html/exp.html>,
mlab="RE Model for Subgroup")
addpoly(res.r, row
<http://stat.ethz.ch/R-manual/R-devel/library/base/html/row.html>=
7.5, cex=.75, atransf=exp
<http://stat.ethz.ch/R-manual/R-devel/library/base/html/exp.html>,
mlab="RE Model for Subgroup")
addpoly(res.a, row
<http://stat.ethz.ch/R-manual/R-devel/library/base/html/row.html>=
1.5, cex=.75, atransf=exp
<http://stat.ethz.ch/R-manual/R-devel/library/base/html/exp.html>,
mlab="RE Model for Subgroup")
dev.off <http://stat.ethz.ch/R-manual/R-devel/library/grDevices/html/dev.off.html>()
[[alternative HTML version deleted]]
More information about the R-help
mailing list