【问题标题】:Adding Labels in Scientific Notation to Forest Plots Using the metafor package使用 metafor 包将科学记数法标签添加到森林图
【发布时间】:2018-02-06 18:30:15
【问题描述】:

所以我正在使用R 中的meta.for 包进行元分析。我正在准备在科学期刊上发表的数据,我想在我的森林图中添加 p 值,但科学注释的格式为

x10<sup>-04</sup>
而不是标准

e-04

但是forest 函数中的参数ilab 不接受expression 类对象,而只接受向量

这是一个例子:

library(metafor)
data(dat.bcg)

## REM 
res <- rma(ai = tpos, bi = tneg, ci = cpos, di = cneg, data = dat.bcg,
           measure = "RR",
           slab = paste(author, year, sep = ", "), method = "REML")
# MADE UP PVALUES
set.seed(513)
p.vals <- runif(nrow(dat.bcg), 1e-6,0.02)

# Format pvalues so only those bellow 0.01 are scientifically notated
p.vals <- ifelse(p.vals < 0.01, 
                 format(p.vals,digits = 3,scientific = TRUE,trim = TRUE),
                 format(round(p.vals, 2), nsmall=2, trim=TRUE))

## Forest plot
forest(res, ilab = p.vals, ilab.xpos = 3, order = "obs", xlab = "Relative Risk")

我希望将 p 值的科学记数法格式化为

x10<sup>-04</sup>
我见过的所有类似问题的答案都建议使用expression(),但这给出了Error in cbind(ilab) : cannot create a matrix from type 'expression',这是有道理的,因为forest 上的帮助文件指定ilab 参数应该是一个向量。

关于如何解决或解决此问题的任何想法?

【问题讨论】:

    标签: r expression scientific-notation forestplot metafor


    【解决方案1】:

    一个hacky的解决方案是

    forest.rma <- edit(forest.rma)
    

    转到第 574 行并更改

    ## line 574
    text(ilab.xpos[l], rows, ilab[, l], pos = ilab.pos[l],
    

    text(ilab.xpos[l], rows, parse(text = ilab[, l]), pos = ilab.pos[l],
    

    修正你的 p 值并绘图

    p.vals <- gsub('e(.*)', '~x~10^{"\\1"}', p.vals)
    forest(res, ilab = p.vals, ilab.xpos = 3, order = "obs", xlab = "Relative Risk")
    

    【讨论】:

      猜你喜欢
      • 2022-12-15
      • 2016-11-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-10
      • 1970-01-01
      • 1970-01-01
      • 2014-08-11
      相关资源
      最近更新 更多