[R-meta] Metafor package: Using subset in forest()

Viechtbauer, Wolfgang (SP) wolfg@ng@viechtb@uer @ending from m@@@trichtuniver@ity@nl
Tue Jul 31 00:29:56 CEST 2018


Dear Julia,

Indeed, forest.rma() (which is what you are implicitly using by passing an object of class 'rma' to the forest() function) does not have a 'subset' argument (see help(forest.rma) to confirm that). I see why this might be useful -- or alternatively, forest.rma() should automatically apply the same subsetting (e.g., to the elements/rows of the 'ilab' argument), but this could get confusing.

I think the easier approach would be to create a data frame that is already subsetted and work with that. So, for example:

sub <- subset(dat, outcome=="periorneomortalityany" & Parity=="nullip" & Integration=="integ")

primary <- rma(yi, vi, data=sub, measure="OR", 
               slab = paste(sub$author, sub$year, sep=", "), 
               digits=2, level=95)

forest(primary, addfit=TRUE, showweights=TRUE, atransf=exp, 
       xlab="Odds Ratio", mlab="Random Effects Model", 
       order=order(sub$PragIdeal), 
       ilab=cbind(sub$HomePos, sub$HomeNeg, sub$HospPos, sub$HospNeg),
       ilab.xpos=c(-14.5,-12,-9,-6))

You might still need to play around with the 'xlim' and 'ilab.pos' arguments to get everything to fit well. Also, setting 'at' explicitly might be useful here. For example:

forest(primary, addfit=TRUE, showweights=TRUE, atransf=exp, 
       xlab="Odds Ratio", mlab="Random Effects Model", 
       order=order(sub$PragIdeal), 
       ilab=cbind(sub$HomePos, sub$HomeNeg, sub$HospPos, sub$HospNeg),
       ilab.xpos=c(-20,-16,-12,-8), xlim=c(-35,20), at=log(c(.01, .1, 1, 10, 100)))

This seems to work alright with your png() call.

Best,
Wolfgang

-----Original Message-----
From: R-sig-meta-analysis [mailto:r-sig-meta-analysis-bounces using r-project.org] On Behalf Of Simioni, Julia
Sent: Monday, 30 July, 2018 18:39
To: r-sig-meta-analysis using r-project.org
Subject: [R-meta] Metafor package: Using subset in forest()

ATTACHMENT(S) REMOVED: MyData.csv 

I'm using the Metafor package in R to run a metanalysis and generate a forest plot. I'm wondering if it is possible to use subset as an argument in the forest() function? It is not listed as one in the documentation but through looking online for a solution to my problem, I've seen it mentioned in forums that is possible. I think I may be using it incorrectly though.

I have a csv file that contains data from many studies but I only want to use some of them in my meta analysis and forest plot. I have attached the csv file. When I run rma() using subset it works fine.

png(filename="primary2.png", pointsize=11, res=95, width=900, height=680, type="cairo")
primary <-           rma(yi, vi,
                                data=dat,
                                measure="OR",
                                slab = paste(dat$author, dat$year, sep=", "),
                                subset=(outcome=="periorneomortalityany" & Parity=="nullip" & Integration=="integ"),
                                digits=2, level=95)

but when I try this in forest() I get warnings saying that subset is not a graphical parameter and the plot will not populate. Without the subset argument working correctly in forest() the order argument does not work properly and the ilab argument results in the ai, bi, ci, di from the first studies in my csv file being added to my plot, rather than the ai, bi, ci, di from the studies that I want.

forest(primary,
                addfit=TRUE,
                showweights=TRUE,
                atransf=exp,
                xlab="Odds Ratio",
                mlab="Random Effects Model",
                subset=(dat$outcome=="periorneomortalityany" & dat$Parity=="nullip" & dat$Integration=="integ"),
                order=order(dat$PragIdeal),
                ilab=cbind(dat$HomePos, dat$HomeNeg, dat$HospPos, dat$HospNeg),
                ilab.xpos=c(-14.5,-12,-9,-6)
                )
dev.off()

Any advice is greatly appreciated.



More information about the R-sig-meta-analysis mailing list