0

I have been using R for about a year, and apparently I never have had to work with rows so am quite lost ha.

I am trying to make a forest plot with two subgroups with the 'metafor' package. I tried implementing the code the metafor site provides that uses subgroups. However, it also uses extra rows in the middle I don't need, but decide to address that later. When I run the code it tell me "Error in forest.rma(meta.random.model, xlim = c(-16, 6), at = log(c(0.05,:Number of outcomes does not correspond to the length of the 'rows' argument." When it comes to working with rows as well as creating dimensions on the plots, I am lost. I was hoping someone could help me with this, or at least explain how rows work in this scenario?

png(filename="subgroups_forestplot.png",
    res=95, width=680, height=680, type="cairo")


par(mar=c(4,4,1,2))


Study <- c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14)

Author <- c('Study 1', 'Study 2', 'Study 3', 'Study 4','Study 5', 'Study 6', 'Study 7', 'Study 8', 'Study 9',
        'Study 10', 'Study 11', 'Study 12', 'Study 13', 'Study 14')

Year <- c(2014, 2008, 2013, 2013, 2011, 2013, 2013, 2012, 2013, 2012, 2013, 2014, 2011, 2014)

EffectSize <- c(0.520, 0.110, 0.260, 0.204, 0.443, 0.156, 0.160, 0.280, 0.051, 0.082, 0.268, 0.333, 0.519, 0.300)

SampleSize<- c(37, 255, 143, 143, 92, 563, 94, 117, 147, 1352, 178, 52, 21, 48)

Outcome <- c('Positive parenting behaviors', 'Alcohol Usage', 
         'Anxiety', 'Depression', 
         'Headache Management Self-Efficacy', 'Anxiety & Depression', 
         'Depression',  'Anorexia Nervosa', 
         'Anxiety & Depression', 'Anxiety & Depression', 'Physical ACitvity', 
         'Anxiety & Depression', 'PTSD', 'PTSD')

Allocation <- c('Other', 'Other', 'Other', 'Other', 'Other', 'Other', 'Other', 'Other', 'Other', 'Other', 'Other',
            'Other', 'Trauma', 'Trauma')


meta.data <-data.frame(Study, Author, Year, EffectSize, SampleSize, Outcome, Allocation)


Meta.poster <- escalc(measure = "COR", ri = EffectSize, ni = SampleSize, data = meta.data)


meta.random.model <- rma(yi = yi, vi = vi, data = Meta.poster, measure="RR",
                     slab=paste(Author, Year, sep=", "), method="REML")


forest(meta.random.model, xlim=c(-16, 6), at=log(c(.05, .25, 1, 4)), atransf=exp,
   ilab=cbind(meta.data$SampleSize, meta.data$EffectSize, meta.data$Outcome, meta.data$Study),
   ilab.xpos=c(-9.5,-8,-6,-4.5), cex=.75, ylim=c(-1, 27),
   order=order(meta.data$Allocation), rows=c(3:4,9:15),
   xlab="Effect Size", mlab="RE Model for All Studies", psize=1)

op <- par(cex=.75, font=4)


text(-16, c(24,16,5), pos=4, c("Trauma", "Other"))


par(font=2)


text(c(-9.5,-8,-6,-4.5), 26, c("n", "Study ES", "Outcome", "Number"))
text(c(-8.75,-5.25),     27, c("Study Statistics", "Study Information"))
text(-16,                26, "Author(s) and Year",     pos=4)
text(6,                  26, "Effect Size [95% CI]", pos=2)


par(op)


res.o <- rma(yi = yi, vi = vi, data=meta.data, measure="RR",
         subset=(alloc=="Other"), method="REML")
res.t <- rma(yi = yi, vi = vi, data=meta.data, measure="RR",
         subset=(alloc=="Trauma"), method="REML")




addpoly(res.o, row=18.5, cex=.75, atransf=exp, mlab="RE Model for Subgroup")
addpoly(res.t, row= 7.5, cex=.75, atransf=exp, mlab="RE Model for Subgroup")


dev.off()

Here is the picture of the Forest Plot I was attempting, horribly, to mimic. However, I have no use for the middle columns. I planned on removing that part of the code after getting the subgroups to work.\

enter image description here Imgur

Heroka
  • 12,889
  • 1
  • 28
  • 38
Austin
  • 153
  • 2
  • 11
  • 2
    Looking at `?forest.rma`, it says that rows is 'optional vector specifying the rows (or more generally, the horizontal positions) for plotting the outcomes. If unspecified, the function sets this value automatically. Can also be a single value specifying the row (horizontal position) of the first outcome (the remaining outcomes are then plotted below this starting row).' So it either needs to be of length one, or length n_outcomes. In your example you have 14 outcomes, while `length(c(3:4,9:15)` is 9. So you could try something like c(2:13,15:16). – Heroka Oct 22 '15 at 07:48
  • This worked, thank you. However, I am still confused as to how it works. For instance, what is the 3 and the 4 corresponding to? Is the 3 my third outcome and 4 is the horizontal position for it on the graph? I apologize for my confusion. I want to learn this so I don't have to ask for help each time. I just found another study, so now at 15, and need to know how to work with the rows. – Austin Oct 23 '15 at 00:48
  • 2
    If I understand correctly, all numbers passed to 'rows' are interpreted as horizontal positions (eg, position on the y-axis) of your data. You can either put in one number (experiment with it, it will shift your whole plot up and down) or a vector of positions, one for each observation you have. x:y is just a way to generate a vector from x to y, increasing by 1. – Heroka Oct 23 '15 at 06:28
  • I just tried this and I feel really dumb ha. That makes perfect sense and it is extremely helpful haha. I appreciate you taking the time to explain this. I want to declare your first response as the answer to my question but I don't see how I can do that. – Austin Oct 23 '15 at 06:44
  • 2
    No worries. It doesn't really warrant an answer and rep in my opinion, I just explained the help-file to you in slightly different words. For the future: help-files are really useful when debugging/figuring things out. Try to find out exactly what a function-argument influences, and what kind of argument (type, length, etc) it needs to do that. – Heroka Oct 23 '15 at 06:48

0 Answers0