如何在Diagnostics Meta分析中将行调整为森林图的数据集

时间:2018-07-03 18:04:23

标签: r

我正在尝试使用“ metafor”软件包制作一个包含三个子组的森林图。我尝试实现metafor网站提供的使用子组的代码。
我的子组例如是A,B和C。
 当我运行代码时,它会告诉我:

  

“ forest.rma(meta.random.model,xlim = c(-16,6),at =中的错误   log(c(0.05 ,:结果数与   “行”参数。”

我真的迷路了,需要帮助。我想知道是否有人可以帮助编写代码。

例如,用于诊断的mydata看起来像这样:

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', 'Study 15', 'Study 16', 'Study 17', 'Study 18', 'Study 19','Study 20', 'Study 21', 'Study 22', 'Study 23', 'Study 24', 'Study 25', 'Study 26', 'Study 27', 'Study 28', 'Study 29', 'Study 30',  'Study 31', 'Study 32', 'Study 33') 

Year <- c(2010,  2010,    2012, 2012,  2004, 2004,    2004,    2006,    2003, 2003,    2003,    2012,    2012,    2004,    2016,    2001,    2006,    2001, 2006,    2006,    2002,    2001,    2001,    2008,    2008,    2008,   2008, 2008, 2008, 2006,    2006,    2006,    2006)


modality<- c('A','A','A','A','A','A','A','A','A','A','A','A','A','A','B','B','B','B','C','C','C','C','C','C','C','C','C','C','C','C','C','C','C')

tp<-c(80, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71 ,72, 73, 74, 75, 76, 77, 78, 79, 80,  81, 82,  83  ,84,85 ,86  ,87 ,88 ,89,90, 91)

fp<-c(6,  2,  3,   4, 5, 6,  7, 8, 9,  10,  11, 12, 13, 14,   15, 16, 17, 18,  19,  20,  21, 22,  23,  24, 25, 26,   27,  28, 29,  30, 31, 32, 33)

fn<-c(2,  6, 7, 8, 9, 10, 11, 12, 13, 14,  15, 16, 17, 18, 19, 20, 21,  22, 23, 24, 25, 26, 27, 28, 29, 30,  31, 32, 33, 34, 35, 36, 37)  

tn<-c(23, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52,  53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66)

我试图模仿的森林图的图片可以     在以下位置可以找到:     How do I adjust the rows to my data set for the forest plot?

但是,中间列没有用。我计划     在使子组正常工作后,删除该部分代码。

我在网上找到了此代码,但似乎对我不起作用:

library(metafor)

### decrease margins so the full space is used
par(mar=c(4,4,1,2))   

### fit random-effects model (use slab argument to define study labels)
res <- rma(ai=tpos, bi=tneg, ci=cpos, di=cneg,
data=dat.bcg, measure="RR",slab=paste(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(-16, 6), at=log(c(0.05, 0.25, 1, 4)),
atransf=exp,ilab=cbind(dat.bcg$tpos, dat.bcg$tneg, dat.bcg$cpos, dat.bcg$cneg),
ilab.xpos=c(-9.5,-8,-6,-4.5), cex=0.75, ylim=c(-1, 27),
order=order(dat.bcg$alloc), rows=c(3:4,9:15,20:23),
       xlab="Risk Ratio", mlab="", psize=1)

### add text with Q-value, dfs, p-value, and I^2 statistic
text(-16, -1, pos=4, cex=0.75, bquote(paste("RE Model
for All Studies (Q = ",
     .(formatC(res$QE,
digits=2, format="f")), ", df = ", .(res$k - res$p), 
     ", p =
", .(formatC(res$QEp, digits=2, format="f")), "; ",
I^2, " = ",
     .(formatC(res$I2,
digits=1, format="f")), "%)")))

###设置字体扩展因子(如上面的forest()所示)并使用     粗斜体

 ### font and save original settings in object 'op'
op <- par(cex=0.75, font=4)   

### add text for the subgroups
text(-16, c(24,16,5), pos=4, c("Systematic
Allocation","Random Allocation", "Alternate
Allocation"))

### switch to bold font   
par(font=2)

### add column headings to the plot
text(c(-9.5,-8,-6,-4.5), 26, c("TB+","TB-", "TB+", "TB-"))
text(c(-8.75,-5.25), 27, c("Vaccinated", "Control"))   
text(-16,  26, "Author(s) and Year",  pos=4)   
text(6, 26, "Risk Ratio [95% CI]", pos=2)

### set par back to the original settings
par(op)

### fit random-effects model in the three subgroups
res.s <- rma(ai=tpos, bi=tneg, ci=cpos, di=cneg,
data=dat.bcg, measure="RR",  
subset=(alloc=="systematic"), method="REML")

res.r <- rma(ai=tpos, bi=tneg, ci=cpos, di=cneg,
data=dat.bcg, measure="RR",             
subset=(alloc=="random"), method="REML")


res.a <- rma(ai=tpos, bi=tneg, ci=cpos, di=cneg,
data=dat.bcg, measure="RR",
subset=(alloc=="alternate"), method="REML")    

### add summary polygons for the three subgroups
addpoly(res.s, row=18.5, cex=0.75, atransf=exp, mlab="")  
addpoly(res.r, row= 7.5, cex=0.75, atransf=exp, mlab="")    
addpoly(res.a, row= 1.5, cex=0.75, atransf=exp, mlab="")

### add text with Q-value, dfs, p-value, and I^2 statistic for subgroups
text(-16, 18.5, pos=4, cex=0.75, bquote(paste("RE Model
for Subgroup (Q = ",
.(formatC(res.s$QE, digits=2, format="f")), ", df =
", .(res.s$k - res.s$p),
      ", p =
", .(formatC(res.s$QEp, digits=2, format="f")), "; ",
I^2, " = ",
.(formatC(res.s$I2, digits=1, format="f")), "%)")))

text(-16, 7.5, pos=4, cex=0.75, bquote(paste("RE Model
for Subgroup (Q = ",    
.(formatC(res.r$QE, digits=2, format="f")), ", df =
", .(res.r$k - res.r$p),
     ", p =
", .(formatC(res.r$QEp, digits=2, format="f")), "; ",
I^2, " = ",
.(formatC(res.r$I2, digits=1, format="f")), "%)")))


text(-16, 1.5, pos=4, cex=0.75, bquote(paste("RE Model
for Subgroup (Q = ",
.(formatC(res.a$QE, digits=2, format="f")), ", df =
", .(res.a$k - res.a$p),
     ", p =
", .(formatC(res.a$QEp, digits=2, format="f")), "; ",
I^2, " = ",
.(formatC(res.a$I2, digits=1, format="f")), "%)")))

0 个答案:

没有答案