Random effect model template: includes correlation structure for 3-arm trials

Adapted from code to be found here:

https://www.bris.ac.uk/cobm/research/mpes/mixed-treatment-comparisons.html

Yellow highlighted sections need to be edited for each analysis.

Substitute these for the numerical values:

N = number of data points (total number of trial arms)

NS = number of studies

NT = number of treatment strategies

BR = baseline risk = event rate in arm 1

model{
sw[1] <- 0
for(i in 1:N) {
logit(p[i])<-mu[s[i]]+ delta[i] * (1-equals(t[i],b[i])) # model
r[i]~dbin(p[i],n[i]) # binomial likelihood
delta[i] ~ dnorm(md[i],taud[i])I(-5,5) # trial-specific LOR distributions
taud[i] <- tau * (1 + equals(m[i],3) /3) # precisions of LOR distributions
md[i] <- d[t[i]] - d[b[i]] + equals(m[i],3) * sw[i] # means of LOR distributions
**#Deviance residuals for data i**
rhat[i] <- p[i] * n[i]
dev[i] <- 2 * (r[i] * (log(r[i])-log(rhat[i])) + (n[i]-r[i]) * (log(n[i]-r[i]) - log(n[i]-rhat[i])))
}
sumdev <- sum(dev[ ]) # Calculate residual deviance
for (i in 2:N)
{ sw[i] <- (delta[i-1] - d[t[i-1]] + d[b[i-1]])/2} # adjustment for 3-arm trials
for(j in 1:NS){ mu[j]~dnorm(0,.0001) } # vague priors for trial baselines
d[1]<-0
for (k in 2:NT) {d[k] ~ dnorm(0,.0001) } # vague priors for basic parameters
sd~dunif(0,2) # vague prior for random effects standard deviation
tau<-1/pow(sd,2)
rr[1]<-1
for (k in 2:NT) {logit(v[k])<-logit(BR)+d[k]
rr[k]<-v[k]/BR } # calculate relative risk
**# Pairwise ORs**
for (c in 1:(NT-1))
{ for (k in (c+1):NT)
{ lor[c,k] <- d[k] - d[c]
log(or[c,k]) <- lor[c,k]
}
}
}
**# Data from trials**
s[ ] t[ ] r[ ] n[ ] b[ ] m[ ]
Insert data here (one row for each trial arm) e.g.
1 1 79 702 1 1
1 2 80 699 1 2
END
s[ ]=Study number
t[ ]=Treatment number
r[ ]=Number of patients experiencing the event
n[ ]=Number of patients in the trial arm
b[ ]=Baseline arm (i.e. lowest treatment number within the trial)
m[ ]=Arm number in the trial
**#initial values**
list(
d=c(NA,-0.5,-1,-0.2), # ensure there is one initial value for each treatment (NT)
sd=1.2,
mu=c(-2.2,-2.3,-2.4,-2.5,-2.6, -2.2,-2.3,-2.4,-2.5,-2.6, -2.2,-2.3,-2.4,-2.5,-2.6, -2.2,-2.3,-2.4,-2.5,-2.6, -2.2,-2.3,-2.4,-2.5,-2.6),
# ensure there is one initial value for each trial (NS)
delta=c(0,-0.2,-0.4,-0.6,-0.8, 0,-0.2,-0.4,-0.6,-0.8, 0,-0.2,-0.4,-0.6,-0.8, 0,-0.2,-0.4,-0.6,-0.8, 0,-0.2,-0.4,-0.6,-0.8, 0,-0.2,-0.4,-0.6,-0.8, 0,-0.2,-0.4,-0.6,-0.8, 0,-0.2,-0.4,-0.6,-0.8)
# ensure there is one initial value for each data point (N)
)