rrjagsmetafor

mtc.network error "Error in `levels<-`(`*tmp*`, value = as.character(levels)) : factor level [5] is duplicated"


I have seen some similar problems to my query here but those solutions have not worked for me. I am trying to build a network meta-analysis and am encountering the following error after calling the mtc.network command:

Error in `levels<-`(`*tmp*`, value = as.character(levels)) : factor level [5] is duplicated

My data are

library(gemtc)
library(rjags)

study<-c("Jones", "Jones", "Prieto", "Prieto", "Scott", "Scott", "Mickle", "Mickle", "Yang", "Yang", "Zhao", "Zhao")
n<-c(3886, 3876, 218, 214, 2040, 2014, 137, 137, 683, 683, 221, 230)
surv<-c(114, 94, 3, 8, 30, 20, 1, 4, 9, 11, 1, 2)
treat<-c("dx1", "px1", "rx1", "tx1", "rx1", "ax1", "zx1", "tx1", "gx1", "tx1", "ax1", "px1")

df<-data.frame(study, n, surv, treat)

network1<-mtc.network(data.ab=df, treatments=df$treat)

I then get this message

Error in `levels<-`(`*tmp*`, value = as.character(levels)) : 
  factor level [5] is duplicated

I would greatly appreciate any assistance in this.


Solution

  • It seems that the function requires data to be formatted in a particular way. We could change the column names as in the example datasets and it would work

    names(df) <- c("study", "sampleSize", "responders", "treatment")
    network <- mtc.network(df, description="Example", treatments=unique(df$treatment))