The code you posted is totally mangled up, but it's just what can be found here:

http://www.metafor-project.org/doku.php/plots:forest_plot_with_subgroups

If you don't want an overall estimate, just pass the estimates and 
corresponding sampling variances to the forest() function (and not the model 
object). Use the 'rows' argument to specify where the estimates will be placed 
and adjust 'ylim' so give you enough space to leave gaps for headings and the 
subgroup estimates. Then fit models within the subgroups (the 'subset' argument 
is useful here) and use addpoly() to add the subgroup estimates in the 
appropriate rows. With text(), you can add headings as needed.

If you use weights() on each subgroup model object, you can get the subgroup 
weights (that add up to 100% within each subgroup). It's probably easiest to 
just add those values with text() in an appropriate place to the plot.

Best,
Wolfgang

-- 
Wolfgang Viechtbauer, Ph.D., Statistician | Department of Psychiatry and    
Neuropsychology | Maastricht University | P.O. Box 616 (VIJV1) | 6200 MD    
Maastricht, The Netherlands | +31 (43) 388-4170 | http://www.wvbauer.com    

> -----Original Message-----
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of John
> Peterson
> Sent: Monday, December 07, 2015 01:39
> To: r-help@r-project.org
> Subject: [R] metafor package
> 
> 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_subgrou
> ps.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]]
> 
> ______________________________________________
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to