Marco Colagrossi
2015-Aug-24 14:03 UTC
[R] Metafor and forest(); not showing 'ilab' and text
Hello folks, I have a couple of issues with the metafor package, specifically with the forest graphs. I am currently conducting a Meta-Analysis in economics throughout the metafor package. My meta-analysis has the specific of having different cases from single studies, and this proven to be challenging especially when trying to plot graphically the results I'm obtaining. Here's the code: forest(pc, var, ci95m, ci95p, slab = authoryear, psize=1, subset=(pub==1), ilab = cbind(ys, f_dim, SIMdv, SIMiv), ilab.xpos = c(-9.5, -8, -6, -4.5), cex = 0.75) par(font=2) text(c(-9.5,-8,-6,-4.5), 26, c("Years", "Firm(s) Dimension", "DV", "IV")) text(-16, 26, "Author(s) and Year", pos=4) text(6, 26, "Observed Outcome [95% CI]", pos=2) par(op) 'pc' is the 'effect size', 'var' the variance, 'ci95m & ci95p' the CI, 'pub' if the paper has been published or not. the pub subset was the first idea I had in order to split my sample that otherwise would have been to big. The issue with this solution is that forest() displays only the slap argument and the forest with the confidence interval, completely ignoring the lab argument and the text I'm trying to add. Moreover, the graph is showed correctly only within the zoom in Rstudio but if I save it it is showed as enclosed. What I'm doing wrong? I tried both to look at the package documentation and online but I can't figure it out. Moreover, how would you suggest to handle (graphically) the multiple-cases-per-study thing? It's a 'good' way to average the cases among different studies in the graphs? In my meta-analysis I'm using a multilevel model as shown in Gelman-Hill but graphically (and in tables) I'm struggling. Thanks for your help and patience
Dear Marco Comments inline On 24/08/2015 15:03, Marco Colagrossi wrote:> Hello folks, > > I have a couple of issues with the metafor package, specifically with > the forest graphs. > I am currently conducting a Meta-Analysis in economics throughout the > metafor package. > > My meta-analysis has the specific of having different cases from > single studies, and this proven to be challenging especially when > trying to plot graphically the results I'm obtaining. > > Here's the code: > > forest(pc, var, ci95m, ci95p, slab = authoryear, psize=1, subset=(pub==1), > ilab = cbind(ys, f_dim, SIMdv, SIMiv), > ilab.xpos = c(-9.5, -8, -6, -4.5), cex = 0.75)At this point I think you meant to close the call to forest with another ) as the subsequent calls to text are further commands and not internal to the call of forest.> par(font=2) > text(c(-9.5,-8,-6,-4.5), 26, c("Years", "Firm(s) Dimension", "DV", "IV")) > text(-16, 26, "Author(s) and Year", pos=4) > text(6, 26, "Observed Outcome [95% CI]", pos=2) > par(op)For that to have worked you probably meant to go op <- par() somewhere earlier> > 'pc' is the 'effect size', 'var' the variance, 'ci95m & ci95p' the CI, > 'pub' if the paper has been published or not. the pub subset was the > first idea I had in order to split my sample that otherwise would have > been to big. The issue with this solution is that forest() displays > only the slap argument and the forest with the confidence interval, > completely ignoring the lab argument and the text I'm trying to add. > Moreover, the graph is showed correctly only within the zoom in > Rstudio but if I save it it is showed as enclosed. >Sorry, do not use Rstudio myself> What I'm doing wrong? I tried both to look at the package > documentation and online but I can't figure it out. > > Moreover, how would you suggest to handle (graphically) the > multiple-cases-per-study thing? It's a 'good' way to average the cases > among different studies in the graphs?Are you looking for rma.mv perhaps?> In my meta-analysis I'm using a multilevel model as shown in > Gelman-Hill but graphically (and in tables) I'm struggling. > > Thanks for your help and patience > > ______________________________________________ > R-help at 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. >-- Michael http://www.dewey.myzen.co.uk/home.html
Viechtbauer Wolfgang (STAT)
2015-Aug-24 14:50 UTC
[R] Metafor and forest(); not showing 'ilab' and text
I cannot reproduce the issue with 'ilab' not being shown when using 'subset'. My guess is that the values for 'ilab.xpos' specified are actually outside of the plotting region. After you have drawn the forest plot, try: par("usr")[1:2] to see what the default limits actually are. Then use 'xlim' to adjust the limits to your taste. And then use appropriate values for 'ilab.xpos', so they are inside those limits.> Moreover, the graph is showed correctly only within the zoom in > Rstudio but if I save it it is showed as enclosed.Nothing was enclosed (or it was stripped).> Moreover, how would you suggest to handle (graphically) the > multiple-cases-per-study thing? It's a 'good' way to average the cases > among different studies in the graphs?Maybe add some space between groupings (i.e., studies). The example given here can provide some clues how one could go about this: http://www.metafor-project.org/doku.php/plots:forest_plot_with_subgroups But drawing a plot like this requires a lot of hand-tweaking. 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-bounces at r-project.org] On Behalf Of Marco > Colagrossi > Sent: Monday, August 24, 2015 16:04 > To: r-help at r-project.org > Subject: [R] Metafor and forest(); not showing 'ilab' and text > > Hello folks, > > I have a couple of issues with the metafor package, specifically with > the forest graphs. > I am currently conducting a Meta-Analysis in economics throughout the > metafor package. > > My meta-analysis has the specific of having different cases from > single studies, and this proven to be challenging especially when > trying to plot graphically the results I'm obtaining. > > Here's the code: > > forest(pc, var, ci95m, ci95p, slab = authoryear, psize=1, > subset=(pub==1), > ilab = cbind(ys, f_dim, SIMdv, SIMiv), > ilab.xpos = c(-9.5, -8, -6, -4.5), cex = 0.75) > par(font=2) > text(c(-9.5,-8,-6,-4.5), 26, c("Years", "Firm(s) Dimension", "DV", > "IV")) > text(-16, 26, "Author(s) and Year", pos=4) > text(6, 26, "Observed Outcome [95% CI]", pos=2) > par(op) > > 'pc' is the 'effect size', 'var' the variance, 'ci95m & ci95p' the CI, > 'pub' if the paper has been published or not. the pub subset was the > first idea I had in order to split my sample that otherwise would have > been to big. The issue with this solution is that forest() displays > only the slap argument and the forest with the confidence interval, > completely ignoring the lab argument and the text I'm trying to add. > Moreover, the graph is showed correctly only within the zoom in > Rstudio but if I save it it is showed as enclosed. > > What I'm doing wrong? I tried both to look at the package > documentation and online but I can't figure it out. > > Moreover, how would you suggest to handle (graphically) the > multiple-cases-per-study thing? It's a 'good' way to average the cases > among different studies in the graphs? > In my meta-analysis I'm using a multilevel model as shown in > Gelman-Hill but graphically (and in tables) I'm struggling. > > Thanks for your help and patience > > ______________________________________________ > R-help at 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.
Marco Colagrossi
2015-Aug-24 17:49 UTC
[R] Metafor and forest(); not showing 'ilab' and text
I tried to upload the file once again. I tweaked it a bit, now my code is: forest(pc, var, ci95m, ci95p, slab = authoryear, psize=1, subset=(pub==1), xlim = c(-16, 6), ilab = cbind(SIMdv, SIMiv), ilab.xpos = c(-7.5, -5.5), cex = 0.75) op <- par(cex=.75, font=2) text(c(-7.5, -5.5), 54, c("DV", "IV")) text(-16, 54, "Author(s) and Year", pos=4) text(6, 54, "Outcome [95% CI]", pos=2) par(op) I managed to show both the Ilab argument and the text above. I still have 3 issues: - now the forest plot is too narrow - that is, pretty unreadable; - I cannot still export it properly, as shown in the enclosed .png - SIMdv, SIMiv are shown as number while on mine .csv are actually text variable. regarding the rma.mv package, I set it up this way (preliminarily) multi <- rma.mv(pc, var, random = ~ 1 | author, data=codebook) I'm trying to compare the results with this equation, which is what - I think, correct me if I'm wrong - in econometrics we call author-fixed effect, that is, model which are constant across individuals (the random\fix notation is a bit tricky): author_fix <- rma(pc, var, mods = ~ I(author), data=codebook, method="ML") What I was wondering if that the two equation above mentioned also correct for heteroskedasticity which I need since my studies have different sample and specifications. Thanks for your help, your patience and your time, and many compliments for the package, is guiding me through the use of R for the first time - as you might have guessed. Marco On 24 August 2015 at 16:50, Viechtbauer Wolfgang (STAT) <wolfgang.viechtbauer at maastrichtuniversity.nl> wrote:> I cannot reproduce the issue with 'ilab' not being shown when using 'subset'. My guess is that the values for 'ilab.xpos' specified are actually outside of the plotting region. After you have drawn the forest plot, try: > > par("usr")[1:2] > > to see what the default limits actually are. Then use 'xlim' to adjust the limits to your taste. And then use appropriate values for 'ilab.xpos', so they are inside those limits. > >> Moreover, the graph is showed correctly only within the zoom in >> Rstudio but if I save it it is showed as enclosed. > > Nothing was enclosed (or it was stripped). > >> Moreover, how would you suggest to handle (graphically) the >> multiple-cases-per-study thing? It's a 'good' way to average the cases >> among different studies in the graphs? > > Maybe add some space between groupings (i.e., studies). The example given here can provide some clues how one could go about this: http://www.metafor-project.org/doku.php/plots:forest_plot_with_subgroups But drawing a plot like this requires a lot of hand-tweaking. > > 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-bounces at r-project.org] On Behalf Of Marco >> Colagrossi >> Sent: Monday, August 24, 2015 16:04 >> To: r-help at r-project.org >> Subject: [R] Metafor and forest(); not showing 'ilab' and text >> >> Hello folks, >> >> I have a couple of issues with the metafor package, specifically with >> the forest graphs. >> I am currently conducting a Meta-Analysis in economics throughout the >> metafor package. >> >> My meta-analysis has the specific of having different cases from >> single studies, and this proven to be challenging especially when >> trying to plot graphically the results I'm obtaining. >> >> Here's the code: >> >> forest(pc, var, ci95m, ci95p, slab = authoryear, psize=1, >> subset=(pub==1), >> ilab = cbind(ys, f_dim, SIMdv, SIMiv), >> ilab.xpos = c(-9.5, -8, -6, -4.5), cex = 0.75) >> par(font=2) >> text(c(-9.5,-8,-6,-4.5), 26, c("Years", "Firm(s) Dimension", "DV", >> "IV")) >> text(-16, 26, "Author(s) and Year", pos=4) >> text(6, 26, "Observed Outcome [95% CI]", pos=2) >> par(op) >> >> 'pc' is the 'effect size', 'var' the variance, 'ci95m & ci95p' the CI, >> 'pub' if the paper has been published or not. the pub subset was the >> first idea I had in order to split my sample that otherwise would have >> been to big. The issue with this solution is that forest() displays >> only the slap argument and the forest with the confidence interval, >> completely ignoring the lab argument and the text I'm trying to add. >> Moreover, the graph is showed correctly only within the zoom in >> Rstudio but if I save it it is showed as enclosed. >> >> What I'm doing wrong? I tried both to look at the package >> documentation and online but I can't figure it out. >> >> Moreover, how would you suggest to handle (graphically) the >> multiple-cases-per-study thing? It's a 'good' way to average the cases >> among different studies in the graphs? >> In my meta-analysis I'm using a multilevel model as shown in >> Gelman-Hill but graphically (and in tables) I'm struggling. >> >> Thanks for your help and patience >> >> ______________________________________________ >> R-help at 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.-------------- next part -------------- A non-text attachment was scrubbed... Name: Rplot.png Type: image/png Size: 105241 bytes Desc: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20150824/7e75b138/attachment.png>