Writes JAGS code for a Bayesian time-course model for model-based network meta-analysis (MBNMA).

mbnma.write(
  fun = dpoly(degree = 1),
  method = "common",
  regress.mat = NULL,
  regress.effect = "common",
  sdscale = FALSE,
  cor = FALSE,
  cor.prior = "wishart",
  omega = NULL,
  om = list(rel = 5, abs = 10),
  class.effect = list(),
  UME = FALSE,
  likelihood = "binomial",
  link = NULL
)

Arguments

fun

An object of class("dosefun") that specifies a functional form to be assigned to the dose-response. See Details.

method

Can take either "common" or "random" to indicate whether relative effects should be modelled with between-study heterogeneity or not (see details).

regress.mat

A Nstudy x Ncovariate design matrix of meta-regression covariates

regress.effect

Indicates whether effect modification should be assumed to be "common" (assumed to be equal versus Placebo throughout the network), "random" (assumed to be exchangeable versus Placebo throughout the network), "agent" (assumed to be equal versus Placebo within each agent), or "class" (assumed to be equal versus Placebo within each class).

sdscale

Logical object to indicate whether to write a model that specifies a reference SD for standardising when modelling using Standardised Mean Differences. Specifying sdscale=TRUE will therefore only modify the model if link function is set to SMD (link="smd").

cor

A boolean object that indicates whether correlation should be modelled between relative effect dose-response parameters. This is automatically set to FALSE if class effects are modelled or if multiple dose-response functions are fitted.

cor.prior

NOT CURRENTLY IN USE - indicates the prior distribution to use for the correlation/covariance between relative effects. Must be kept as "wishart"

omega

A scale matrix for the inverse-Wishart prior for the covariance matrix used to model the correlation between dose-response parameters (see Details for dose-response functions). omega must be a symmetric positive definite matrix with dimensions equal to the number of dose-response parameters modelled using relative effects ("rel"). If left as NULL (the default) a diagonal matrix with elements equal to 100 is used.

om

a list with two elements that report the maximum relative ("rel") and maximum absolute ("abs") efficacies on the link scale.

class.effect

A list of named strings that determines which dose-response parameters to model with a class effect and what that effect should be ("common" or "random"). Element names should match dose-response parameter names. Note that assuming class effects on some dose-response parameters may be unreasonable if the range of doses differ substantially across agents within a class.

UME

A boolean object to indicate whether to fit an Unrelated Mean Effects model that does not assume consistency and so can be used to test if the consistency assumption is valid.

likelihood

A string indicating the likelihood to use in the model. Can take either "binomial", "normal" or "poisson". If left as NULL the likelihood will be inferred from the data.

link

A string indicating the link function to use in the model. Can take any link function defined within JAGS (e.g. "logit", "log", "probit", "cloglog"), be assigned the value "identity" for an identity link function, or be assigned the value "smd" for modelling Standardised Mean Differences using an identity link function. If left as NULL the link function will be automatically assigned based on the likelihood.

Value

A single long character string containing the JAGS model generated based on the arguments passed to the function.

Details

When relative effects are modelled on more than one dose-response parameter and cor = TRUE, correlation between the dose-response parameters is automatically estimated using a vague Wishart prior. This prior can be made slightly more informative by specifying the relative scale of variances between the dose-response parameters using omega. cor will automatically be set to FALSE if class effects are modelled.

Examples

# Write model code for a model with an exponential dose-response function,
# with random treatment effects
model <- mbnma.write(fun=dexp(),
             method="random",
             likelihood="binomial",
             link="logit"
             )
names(model) <- NULL
print(model)
#>  [1] "model{ \t\t\t# Begin Model Code"                                                                                                    
#>  [2] "s.beta.1[1] <- 0"                                                                                                                   
#>  [3] "for(i in 1:NS){ # Run through all NS trials"                                                                                        
#>  [4] "w[i,1] <- 0"                                                                                                                        
#>  [5] "delta[i,1] <- 0"                                                                                                                    
#>  [6] "mu[i] ~ dnorm(0,0.0001)"                                                                                                            
#>  [7] "for (k in 1:narm[i]){ # Run through all arms within a study"                                                                        
#>  [8] "rhat[i,k] <- psi[i,k] * n[i,k]"                                                                                                     
#>  [9] "resdev[i,k] <- 2 * (r[i,k] * (log(r[i,k]) - log(rhat[i,k])) + (n[i,k] - r[i,k]) * (log(n[i,k] - r[i,k]) - log(n[i,k] - rhat[i,k])))"
#> [10] "r[i,k] ~ dbin(psi[i,k], n[i,k])"                                                                                                    
#> [11] "logit(psi[i,k]) <- theta[i,k]"                                                                                                      
#> [12] "theta[i,k] <- mu[i] + delta[i,k]"                                                                                                   
#> [13] "DR[i,k] <- (s.beta.1[agent[i,k]] * (1 - exp(- dose[i,k]))) - (s.beta.1[agent[i,1]] * (1 - exp(- dose[i,1])))"                       
#> [14] "}"                                                                                                                                  
#> [15] "resstudydev[i] <- sum(resdev[i, 1:narm[i]])"                                                                                        
#> [16] "for(k in 2:narm[i]){ # Treatment effects"                                                                                           
#> [17] "delta[i,k] ~ dnorm(md[i,k], taud[i,k])"                                                                                             
#> [18] "md[i,k] <- DR[i,k] + sw[i,k]"                                                                                                       
#> [19] "taud[i,k] <- tau * 2*(k-1)/k"                                                                                                       
#> [20] "w[i,k] <- delta[i,k] - DR[i,k]"                                                                                                     
#> [21] "sw[i,k] <- sum(w[i,1:(k-1)])/(k-1)"                                                                                                 
#> [22] "}"                                                                                                                                  
#> [23] "}"                                                                                                                                  
#> [24] "for (k in 2:Nagent){ # Priors on relative agent effects"                                                                            
#> [25] "emax[k] ~ dnorm(0,0.0001)"                                                                                                          
#> [26] "s.beta.1[k] <- emax[k]"                                                                                                             
#> [27] "}"                                                                                                                                  
#> [28] "totresdev <- sum(resstudydev[])"                                                                                                    
#> [29] ""                                                                                                                                   
#> [30] "sd ~ dunif(0, 5)"                                                                                                                   
#> [31] "tau <- pow(sd, -2)"                                                                                                                 
#> [32] "# Model ends"                                                                                                                       
#> [33] "}"                                                                                                                                  

# Write model code for a model with an Emax dose-response function,
# relative effects modelled on Emax with a random effects model,
# a single parameter estimated for ED50 with a common effects model
model <- mbnma.write(fun=demax(emax="rel", ed50="common"),
             likelihood="normal",
             link="identity"
             )
names(model) <- NULL
print(model)
#>  [1] "model{ \t\t\t# Begin Model Code"                                                                                                                                 
#>  [2] "s.beta.2[1] <- 0.00001"                                                                                                                                          
#>  [3] "s.beta.1[1] <- 0"                                                                                                                                                
#>  [4] "for(i in 1:NS){ # Run through all NS trials"                                                                                                                     
#>  [5] "delta[i,1] <- 0"                                                                                                                                                 
#>  [6] "mu[i] ~ dnorm(0,0.0001)"                                                                                                                                         
#>  [7] "for (k in 1:narm[i]){ # Run through all arms within a study"                                                                                                     
#>  [8] "resdev[i,k] <- pow((y[i,k] - psi[i,k]),2) * prec[i,k] # residual deviance for normal likelihood"                                                                 
#>  [9] "y[i,k] ~ dnorm(psi[i,k], prec[i,k])"                                                                                                                             
#> [10] "prec[i,k] <- pow(se[i,k], -2)"                                                                                                                                   
#> [11] "psi[i,k] <- theta[i,k]"                                                                                                                                          
#> [12] "theta[i,k] <- mu[i] + delta[i,k]"                                                                                                                                
#> [13] "DR[i,k] <- ((s.beta.1[agent[i,k]] * dose[i,k]) / (s.beta.2[agent[i,k]] + dose[i,k])) - ((s.beta.1[agent[i,1]] * dose[i,1]) / (s.beta.2[agent[i,1]] + dose[i,1]))"
#> [14] "}"                                                                                                                                                               
#> [15] "resstudydev[i] <- sum(resdev[i, 1:narm[i]])"                                                                                                                     
#> [16] "for(k in 2:narm[i]){ # Treatment effects"                                                                                                                        
#> [17] "delta[i,k] <- DR[i,k]"                                                                                                                                           
#> [18] "}"                                                                                                                                                               
#> [19] "}"                                                                                                                                                               
#> [20] "for (k in 2:Nagent){ # Priors on relative agent effects"                                                                                                         
#> [21] "s.beta.2[k] <- ed50"                                                                                                                                             
#> [22] "emax[k] ~ dnorm(0,0.0001)"                                                                                                                                       
#> [23] "s.beta.1[k] <- emax[k]"                                                                                                                                          
#> [24] "}"                                                                                                                                                               
#> [25] "totresdev <- sum(resstudydev[])"                                                                                                                                 
#> [26] ""                                                                                                                                                                
#> [27] "ed50 ~ dnorm(0,0.0001) T(0,)"                                                                                                                                    
#> [28] "# Model ends"                                                                                                                                                    
#> [29] "}"                                                                                                                                                               

# Write model code for a model with an Emax dose-response function,
# relative effects modelled on Emax and ED50.
# Class effects modelled on ED50 with common effects
model <- mbnma.write(fun=demax(),
             likelihood="normal",
             link="identity",
             class.effect=list("ed50"="common")
             )
names(model) <- NULL
print(model)
#>  [1] "model{ \t\t\t# Begin Model Code"                                                                                                                                 
#>  [2] "s.beta.2[1] <- 0.00001"                                                                                                                                          
#>  [3] "s.beta.1[1] <- 0"                                                                                                                                                
#>  [4] "for(i in 1:NS){ # Run through all NS trials"                                                                                                                     
#>  [5] "delta[i,1] <- 0"                                                                                                                                                 
#>  [6] "mu[i] ~ dnorm(0,0.0001)"                                                                                                                                         
#>  [7] "for (k in 1:narm[i]){ # Run through all arms within a study"                                                                                                     
#>  [8] "resdev[i,k] <- pow((y[i,k] - psi[i,k]),2) * prec[i,k] # residual deviance for normal likelihood"                                                                 
#>  [9] "y[i,k] ~ dnorm(psi[i,k], prec[i,k])"                                                                                                                             
#> [10] "prec[i,k] <- pow(se[i,k], -2)"                                                                                                                                   
#> [11] "psi[i,k] <- theta[i,k]"                                                                                                                                          
#> [12] "theta[i,k] <- mu[i] + delta[i,k]"                                                                                                                                
#> [13] "DR[i,k] <- ((s.beta.1[agent[i,k]] * dose[i,k]) / (s.beta.2[agent[i,k]] + dose[i,k])) - ((s.beta.1[agent[i,1]] * dose[i,1]) / (s.beta.2[agent[i,1]] + dose[i,1]))"
#> [14] "}"                                                                                                                                                               
#> [15] "resstudydev[i] <- sum(resdev[i, 1:narm[i]])"                                                                                                                     
#> [16] "for(k in 2:narm[i]){ # Treatment effects"                                                                                                                        
#> [17] "delta[i,k] <- DR[i,k]"                                                                                                                                           
#> [18] "}"                                                                                                                                                               
#> [19] "}"                                                                                                                                                               
#> [20] "for (k in 2:Nagent){ # Priors on relative agent effects"                                                                                                         
#> [21] "ed50[k]  <- ED50[class[k]]"                                                                                                                                      
#> [22] "s.beta.2[k] <- ed50[k]"                                                                                                                                          
#> [23] "emax[k] ~ dnorm(0,0.0001)"                                                                                                                                       
#> [24] "s.beta.1[k] <- emax[k]"                                                                                                                                          
#> [25] "}"                                                                                                                                                               
#> [26] "for (k in 2:Nclass){ # Priors on relative class effects"                                                                                                         
#> [27] "ED50[k] ~ dnorm(0,0.0001) T(0,)"                                                                                                                                 
#> [28] "}"                                                                                                                                                               
#> [29] "totresdev <- sum(resstudydev[])"                                                                                                                                 
#> [30] ""                                                                                                                                                                
#> [31] "# Model ends"                                                                                                                                                    
#> [32] "}"                                                                                                                                                               

# Write model code for a model with an Emax dose-response function,
# relative effects modelled on Emax and ED50 with a
# random effects model that automatically models a correlation between
# both parameters.
model <- mbnma.write(fun=demax(),
             method="random",
             likelihood="normal",
             link="identity",
             )
names(model) <- NULL
print(model)
#>  [1] "model{ \t\t\t# Begin Model Code"                                                                                                                                 
#>  [2] "s.beta.2[1] <- 0.00001"                                                                                                                                          
#>  [3] "s.beta.1[1] <- 0"                                                                                                                                                
#>  [4] "for(i in 1:NS){ # Run through all NS trials"                                                                                                                     
#>  [5] "w[i,1] <- 0"                                                                                                                                                     
#>  [6] "delta[i,1] <- 0"                                                                                                                                                 
#>  [7] "mu[i] ~ dnorm(0,0.0001)"                                                                                                                                         
#>  [8] "for (k in 1:narm[i]){ # Run through all arms within a study"                                                                                                     
#>  [9] "resdev[i,k] <- pow((y[i,k] - psi[i,k]),2) * prec[i,k] # residual deviance for normal likelihood"                                                                 
#> [10] "y[i,k] ~ dnorm(psi[i,k], prec[i,k])"                                                                                                                             
#> [11] "prec[i,k] <- pow(se[i,k], -2)"                                                                                                                                   
#> [12] "psi[i,k] <- theta[i,k]"                                                                                                                                          
#> [13] "theta[i,k] <- mu[i] + delta[i,k]"                                                                                                                                
#> [14] "DR[i,k] <- ((s.beta.1[agent[i,k]] * dose[i,k]) / (s.beta.2[agent[i,k]] + dose[i,k])) - ((s.beta.1[agent[i,1]] * dose[i,1]) / (s.beta.2[agent[i,1]] + dose[i,1]))"
#> [15] "}"                                                                                                                                                               
#> [16] "resstudydev[i] <- sum(resdev[i, 1:narm[i]])"                                                                                                                     
#> [17] "for(k in 2:narm[i]){ # Treatment effects"                                                                                                                        
#> [18] "delta[i,k] ~ dnorm(md[i,k], taud[i,k])"                                                                                                                          
#> [19] "md[i,k] <- DR[i,k] + sw[i,k]"                                                                                                                                    
#> [20] "taud[i,k] <- tau * 2*(k-1)/k"                                                                                                                                    
#> [21] "w[i,k] <- delta[i,k] - DR[i,k]"                                                                                                                                  
#> [22] "sw[i,k] <- sum(w[i,1:(k-1)])/(k-1)"                                                                                                                              
#> [23] "}"                                                                                                                                                               
#> [24] "}"                                                                                                                                                               
#> [25] "for (k in 2:Nagent){ # Priors on relative agent effects"                                                                                                         
#> [26] "ed50[k] ~ dnorm(0,0.0001) T(0,)"                                                                                                                                 
#> [27] "s.beta.2[k] <- ed50[k]"                                                                                                                                          
#> [28] "emax[k] ~ dnorm(0,0.0001)"                                                                                                                                       
#> [29] "s.beta.1[k] <- emax[k]"                                                                                                                                          
#> [30] "}"                                                                                                                                                               
#> [31] "totresdev <- sum(resstudydev[])"                                                                                                                                 
#> [32] ""                                                                                                                                                                
#> [33] "sd ~ dunif(0, 5)"                                                                                                                                                
#> [34] "tau <- pow(sd, -2)"                                                                                                                                              
#> [35] "# Model ends"                                                                                                                                                    
#> [36] "}"