我已经使用R大约一年了,显然我从来没有必须使用行,所以我很失落哈哈。
我正在尝试制作一个带有两个子组的森林图,其中包含' metafor'包。我尝试实现metafor网站提供的使用子组的代码。但是,它也在我不需要的中间使用额外的行,但是后来决定解决这个问题。当我运行代码时,它告诉我"在forest.rma中的错误(meta.random.model,xlim = c(-16,6),at = log(c(0.05 ,:结果数量不对应于'行'参数的长度。"当涉及到处理行以及在图上创建维度时,我迷失了。我希望有人可以帮助我,或者在至少解释在这种情况下行如何工作?
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()
这是我正在尝试模仿森林情节的图片。但是,我没有使用中间列。我计划在让子组工作后删除该部分代码。\