forest(relative.effect()) / 结果错误[["model"]]:下标越界
forest(relative.effect()) / Error in result[["model"]] : subscript out of bounds
我正在尝试绘制网络荟萃分析的结果。我已经成功地生成了每种治疗相对于安慰剂的等级概率。但是,当我调用 forest(relative.effect(results.rank)) 时遇到以下错误:
Error in result[["model"]] : subscript out of bounds
我知道这个论坛上有很多关于“下标越界”的问题,但是我申请的none已经充分解决了我的问题。
我能否得到关于此错误是否意味着我标记变量的方式有问题或者我是否需要在 forest(relative effect(results.rank))
行中指定以某种方式扩大边界的指示?
非常感谢任何指导。
12 月 29 日更新....
为最小上下文道歉,这是我的代码:
library(gemtc)
library(rjags)
library(readxl)
df<-read_xlsx("...Book1.xlsx")
#Create network model#
nw<-mtc.network(data.ab=df, treatments=unique(df$treatment))
#Build model#
nw.model <- mtc.model(nw,
linearModel = "random",
n.chain = 4,
type="consistency",
likelihood='binom',
link="logit")
#Run MCMC#
nw.mcmc <- mtc.run(nw.model, n.adapt = 50, n.iter = 10000, thin = 10)
#Rank treatments#
nw.rank<-rank.probability(nw.mcmc, preferredDirection = -1)
#Plot relative effect#
forest(relative.effect(nw.rank))
我这个问题的数据是:
study<-c("Jones", "Jones", "Prieto", "Prieto", "Scott", "Scott", "Mickle", "Mickle", "Yang", "Yang", "Zhao", "Zhao")
sampleSize<-c(3886, 3876, 218, 214, 2040, 2014, 137, 137, 683, 683, 221, 230)
responders<-c(114, 94, 3, 8, 30, 20, 1, 4, 9, 11, 1, 2)
treatment<-c("dx1", "px1", "rx1", "tx1", "rx1", "ax1", "zx1", "tx1", "gx1", "tx1", "ax1", "px1")
df<-as.data.frame(study, sampleSize, responders, treatment)
从 the docs 开始,relative.effect()
函数需要
An object of S3 class mtc.result
to derive the relative effects from.
在您的示例中,nw.mcmc
对象是 mtc.result
类型,而 nw.rank
不是。
class(nw.mcmc) # "mtc.result"
class(nw.rank) # "mtc.rank.probability"
因此,在您对 relative.effect()
的调用中传递 nw.mcmc
。另请注意,第二个参数 t1
是必需的,而您的代码中缺少此参数:
t1
: A list of baselines to calculate a relative effects against. Will be extended to match the length of t2
.
使用正确的对象调用 forest
/relative.effect
,并将处理级别作为基线,运行无误:
forest(relative.effect(nw.mcmc, "ax1"))
我正在尝试绘制网络荟萃分析的结果。我已经成功地生成了每种治疗相对于安慰剂的等级概率。但是,当我调用 forest(relative.effect(results.rank)) 时遇到以下错误:
Error in result[["model"]] : subscript out of bounds
我知道这个论坛上有很多关于“下标越界”的问题,但是我申请的none已经充分解决了我的问题。
我能否得到关于此错误是否意味着我标记变量的方式有问题或者我是否需要在 forest(relative effect(results.rank))
行中指定以某种方式扩大边界的指示?
非常感谢任何指导。
12 月 29 日更新.... 为最小上下文道歉,这是我的代码:
library(gemtc)
library(rjags)
library(readxl)
df<-read_xlsx("...Book1.xlsx")
#Create network model#
nw<-mtc.network(data.ab=df, treatments=unique(df$treatment))
#Build model#
nw.model <- mtc.model(nw,
linearModel = "random",
n.chain = 4,
type="consistency",
likelihood='binom',
link="logit")
#Run MCMC#
nw.mcmc <- mtc.run(nw.model, n.adapt = 50, n.iter = 10000, thin = 10)
#Rank treatments#
nw.rank<-rank.probability(nw.mcmc, preferredDirection = -1)
#Plot relative effect#
forest(relative.effect(nw.rank))
我这个问题的数据是:
study<-c("Jones", "Jones", "Prieto", "Prieto", "Scott", "Scott", "Mickle", "Mickle", "Yang", "Yang", "Zhao", "Zhao")
sampleSize<-c(3886, 3876, 218, 214, 2040, 2014, 137, 137, 683, 683, 221, 230)
responders<-c(114, 94, 3, 8, 30, 20, 1, 4, 9, 11, 1, 2)
treatment<-c("dx1", "px1", "rx1", "tx1", "rx1", "ax1", "zx1", "tx1", "gx1", "tx1", "ax1", "px1")
df<-as.data.frame(study, sampleSize, responders, treatment)
从 the docs 开始,relative.effect()
函数需要
An object of S3 class
mtc.result
to derive the relative effects from.
在您的示例中,nw.mcmc
对象是 mtc.result
类型,而 nw.rank
不是。
class(nw.mcmc) # "mtc.result"
class(nw.rank) # "mtc.rank.probability"
因此,在您对 relative.effect()
的调用中传递 nw.mcmc
。另请注意,第二个参数 t1
是必需的,而您的代码中缺少此参数:
t1
: A list of baselines to calculate a relative effects against. Will be extended to match the length oft2
.
使用正确的对象调用 forest
/relative.effect
,并将处理级别作为基线,运行无误:
forest(relative.effect(nw.mcmc, "ax1"))