rrjags

forest(relative.effect()) / Error in result[["model"]] : subscript out of bounds


I am trying to plot the results of a network meta-analysis. I have successfully generated the rank probabilities for each treatment relative to placebo. However, when I call forest(relative.effect(results.rank)) I encounter the following error:

Error in result[["model"]] : subscript out of bounds

I realise there are many questions on this forum relating to "subscript out of bounds" however none that I have applied have adequately solved my issue.

Can I get an indication as to whether this error means there is something wrong with the way I have labeled my variables or do I need to specify in the forest(relative effect(results.rank)) line to widen the bounds somehow?

Any guidance is much appreciated.

UPDATE 29 DEC.... Apologies for the minimal context, here is my code:

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))

My data for this issue are:

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)

Solution

  • From the docs, the relative.effect() function takes

    An object of S3 class mtc.result to derive the relative effects from.

    In your example, the nw.mcmc object is of type mtc.result, and nw.rank is not.

    class(nw.mcmc) # "mtc.result"
    class(nw.rank) # "mtc.rank.probability"
    

    So, pass nw.mcmc in your call to relative.effect(). Also note that the second argument, t1, is required, and this is missing in your code:

    t1: A list of baselines to calculate a relative effects against. Will be extended to match the length of t2.

    Calling forest/relative.effect with the correct object, along with a treatment level as baseline, runs without error:

    forest(relative.effect(nw.mcmc, "ax1"))
    

    enter image description here