In this vignette, we describe how to run a Bayesian network meta-analysis model using this package. First we’ll need to load the package.
#install.packages("bnma")
#or devtools::install_github("MikeJSeo/bnma")
library(bnma)
It is essential to specify the input data in a correct format. We have chosen to use arm-level data with following input variable names: Outcomes, N or SE, Study, and Treat. Outcomes is the trial results. N is the number of respondents used for binary or multinomial model. SE is the standard error used for normal model. Study is the study indicator for the meta analysis. Lastly, Treat is the treatment indicator for each arm. We will use a dataset parkinsons
for illustration.
parkinsons
#> $Outcomes
#> [1] -1.22 -1.53 -0.70 -2.40 -0.30 -2.60 -1.20 -0.24 -0.59 -0.73 -0.18 -2.20
#> [13] -2.50 -1.80 -2.10
#>
#> $SE
#> [1] 0.504 0.439 0.282 0.258 0.505 0.510 0.478 0.265 0.354 0.335 0.442 0.197
#> [13] 0.190 0.200 0.250
#>
#> $Treat
#> [1] "Placebo" "Ropinirole" "Placebo" "Pramipexole"
#> [5] "Placebo" "Pramipexole" "Bromocriptine" "Ropinirole"
#> [9] "Bromocriptine" "Ropinirole" "Bromocriptine" "Bromocriptine"
#> [13] "Cabergoline" "Bromocriptine" "Cabergoline"
#>
#> $Study
#> [1] 1 1 2 2 3 3 3 4 4 5 5 6 6 7 7
#>
#> $Treat.order
#> [1] "Placebo" "Pramipexole" "Ropinirole" "Bromocriptine"
#> [5] "Cabergoline"
In order to run network meta analysis in JAGS, we need to relabel study names into to a numeric sequence, i.e. 1 to total number of studies, and relabel the treatment into a numeric sequence according to treatment order specified. If treatment order is not specified, default is to use alphabetical order. In the example below, we set placebo as the baseline treatment followed by Pramipexole, Ropinirole, Bromocriptine, and Cabergoline as the treatment order.
network <- with(parkinsons, network.data(Outcomes = Outcomes, Study = Study, Treat = Treat, SE = SE, response = "normal", Treat.order = Treat.order))
network$Treat.order
#> 1 2 3 4 5
#> "Placebo" "Pramipexole" "Ropinirole" "Bromocriptine" "Cabergoline"
network$Study.order
#> 1 2 3 4 5 6 7
#> 1 2 3 4 5 6 7
Another important preprocessing step that is done through network.data
function is to change the arm-level data into study-level data. We store the study-level data of Outcomes as r, Treat as t, N or SE as n or se. We can see how Outcomes changed into a matrix given below. Similarly, if the Outcomes are multinomial, it will change to a 3 dimensional array.
network$r
#> [,1] [,2] [,3]
#> [1,] -1.22 -1.53 NA
#> [2,] -0.70 -2.40 NA
#> [3,] -0.30 -2.60 -1.2
#> [4,] -0.24 -0.59 NA
#> [5,] -0.73 -0.18 NA
#> [6,] -2.20 -2.50 NA
#> [7,] -1.80 -2.10 NA
Priors can be set in the network.data
function. Please take a look at the function description for the prior specifications. For heterogeneity parameters of the random effects model, we follow the data format from a similar Bayesian network meta-analysis R package gemtc
. It should be a list of length 3 where first element should be the distribution (one of dunif, dgamma, dhnorm, dwish) and the next two are the parameters associated with the distribution. Here is an example.
network <- with(smoking, network.data(Outcomes = Outcomes, Study = Study, Treat = Treat, N = N, response = "binomial", mean.d = 0.1, hy.prior = list("dhnorm", 0, 5)))
Now to run the network, we use the function network.run
. There are many parameters that can be modified, but the most important is the parameter n.run
which determines how many final observations the user wants. Gelman-Rubin statitics is checked automatically every setsize
number of iterations and once the series have converged we store the last half of the sequence. If the number of iteration is less than the number of observations user wanted (n.runs
), it will sample more to fill the requirement. One of the nice feature of this package is that it checks for convergence automatically and will give an error if the sequence has not converged. The parameters tested for convergence are the relative treatment effects, baseline effect, and heterogeneity parameter. The number that is printed during the running of the model is the point estimate of the Gelman-Rubin statistics.
result <- network.run(network, n.run = 30000)
#> Compiling model graph
#> Resolving undeclared variables
#> Allocating nodes
#> Graph information:
#> Observed stochastic nodes: 50
#> Unobserved stochastic nodes: 54
#> Total graph size: 1129
#>
#> Initializing model
#>
#> NOTE: Stopping adaptation
#>
#>
#> [1] 1.004027
#> [1] 1.002172
Package includes many summary tools that can be used. One of the more useful summary might be the forest plot. Please look over the R package guide for more possible options.
network.forest.plot(result)
# draw.network.graph(network)
# network.autocorr.diag(result)
# network.autocorr.plot(result)
# network.cumrank.tx.plot(result)
# network.deviance.plot(result)
# network.gelman.plot(result)
Another nice feature of this package is that multinomial outcome dataset can be analyzed. Here is an example.
network <- with(cardiovascular, network.data(Outcomes, Study, Treat, N, response = "multinomial"))
result <- network.run(network)
#> Compiling model graph
#> Resolving undeclared variables
#> Allocating nodes
#> Graph information:
#> Observed stochastic nodes: 34
#> Unobserved stochastic nodes: 37
#> Total graph size: 1301
#>
#> Initializing model
#>
#> NOTE: Stopping adaptation
#>
#>
#> [1] 1.007242
#> [1] 1.002173
summary(result)
#> $summary.samples
#>
#> Iterations = 1:50000
#> Thinning interval = 1
#> Number of chains = 3
#> Sample size per chain = 50000
#>
#> 1. Empirical mean and standard deviation for each variable,
#> plus standard error of the mean:
#>
#> Mean SD Naive SE Time-series SE
#> d[1,1] 0.000000 0.00000 0.000e+00 0.0000000
#> d[2,1] -0.104674 0.15261 3.940e-04 0.0011630
#> d[3,1] -0.046890 0.11262 2.908e-04 0.0007079
#> d[1,2] 0.000000 0.00000 0.000e+00 0.0000000
#> d[2,2] -0.187270 0.15328 3.958e-04 0.0011135
#> d[3,2] -0.270766 0.11238 2.902e-04 0.0006733
#> sigma[1,1] 0.114936 0.05077 1.311e-04 0.0002453
#> sigma[2,1] 0.004613 0.03440 8.881e-05 0.0001620
#> sigma[1,2] 0.004613 0.03440 8.881e-05 0.0001620
#> sigma[2,2] 0.114358 0.05034 1.300e-04 0.0002431
#>
#> 2. Quantiles for each variable:
#>
#> 2.5% 25% 50% 75% 97.5%
#> d[1,1] 0.00000 0.00000 0.000000 0.000000 0.00000
#> d[2,1] -0.40375 -0.20472 -0.105453 -0.005514 0.19848
#> d[3,1] -0.27069 -0.12058 -0.046521 0.026790 0.17511
#> d[1,2] 0.00000 0.00000 0.000000 0.000000 0.00000
#> d[2,2] -0.49310 -0.28755 -0.185594 -0.085904 0.11160
#> d[3,2] -0.49487 -0.34371 -0.270023 -0.197226 -0.05051
#> sigma[1,1] 0.05195 0.08065 0.103866 0.136225 0.24338
#> sigma[2,1] -0.06346 -0.01433 0.003861 0.022728 0.07665
#> sigma[1,2] -0.06346 -0.01433 0.003861 0.022728 0.07665
#> sigma[2,2] 0.05183 0.08014 0.103304 0.135678 0.24196
#>
#>
#> $Treat.order
#> 1 2 3
#> 1 2 3
#>
#> $deviance
#> Dbar pD DIC
#> 31.17295 60.41655 91.58951
#>
#> $total_n
#> [1] 34
#>
#> attr(,"class")
#> [1] "summary.network.result"
We can add continuous or discrete covariates to fit a network meta regression. If the covariate is continuous, it is centered. Discrete variables need to be 0-1 dummy format. There are three different assumptions for covariate effect: “common”, “independent”, and “exchangeable”.
network <- with(statins, network.data(Outcomes, Study, Treat, N=N, response = "binomial", Treat.order = c("Placebo", "Statin"), covariate = covariate, covariate.type = "discrete", covariate.model = "common"))
result <- network.run(network)
#> Compiling model graph
#> Resolving undeclared variables
#> Allocating nodes
#> Graph information:
#> Observed stochastic nodes: 38
#> Unobserved stochastic nodes: 41
#> Total graph size: 877
#>
#> Initializing model
#>
#> NOTE: Stopping adaptation
#>
#>
#> [1] 1.008697
#> [1] 1.00874
summary(result)
#> $summary.samples
#>
#> Iterations = 1:50000
#> Thinning interval = 1
#> Number of chains = 3
#> Sample size per chain = 50000
#>
#> 1. Empirical mean and standard deviation for each variable,
#> plus standard error of the mean:
#>
#> Mean SD Naive SE Time-series SE
#> beta1[1] 0.00000 0.0000 0.0000000 0.000000
#> beta1[2] -0.29681 0.2652 0.0006848 0.003555
#> d[1] 0.00000 0.0000 0.0000000 0.000000
#> d[2] -0.06898 0.2092 0.0005401 0.002626
#> sd 0.24437 0.2113 0.0005457 0.005935
#>
#> 2. Quantiles for each variable:
#>
#> 2.5% 25% 50% 75% 97.5%
#> beta1[1] 0.000000 0.00000 0.00000 0.00000 0.0000
#> beta1[2] -0.888860 -0.42489 -0.27605 -0.14883 0.1918
#> d[1] 0.000000 0.00000 0.00000 0.00000 0.0000
#> d[2] -0.479454 -0.17981 -0.07414 0.03424 0.3767
#> sd 0.007239 0.08962 0.18958 0.33895 0.7949
#>
#>
#> $Treat.order
#> 1 2
#> "Placebo" "Statin"
#>
#> $deviance
#> Dbar pD DIC
#> 42.63374 25.12265 67.75640
#>
#> $total_n
#> [1] 38
#>
#> attr(,"class")
#> [1] "summary.network.result"
Covariate plot shows you how the relative effect changes as the covariate varies.
network.covariate.plot(result, base.treatment = "Placebo", comparison.treatment = "Statin")
Another useful addition to this network package is the ability to add baseline risk. We can have “common”, “independent”, or “exchangeable” assumption on the baseline slopes and “independenet” and “exchangeable” assumption on the baseline risk. Here we demonstrate a common slope and exchangeable baseline risk model.
network <- with(certolizumab, network.data(Outcomes = Outcomes, Treat = Treat, Study = Study, N = N, response = "binomial", Treat.order = Treat.order, baseline = "common", baseline.risk = "exchangeable"))
result <- network.run(network)
#> Compiling model graph
#> Resolving undeclared variables
#> Allocating nodes
#> Graph information:
#> Observed stochastic nodes: 24
#> Unobserved stochastic nodes: 34
#> Total graph size: 670
#>
#> Initializing model
#>
#> NOTE: Stopping adaptation
#>
#>
#> [1] 1.01313
#> [1] 1.051768
summary(result)
#> $summary.samples
#>
#> Iterations = 1:50000
#> Thinning interval = 1
#> Number of chains = 3
#> Sample size per chain = 50000
#>
#> 1. Empirical mean and standard deviation for each variable,
#> plus standard error of the mean:
#>
#> Mean SD Naive SE Time-series SE
#> B -0.7791 0.2927 0.0007558 0.003959
#> b_bl[1] 0.0000 0.0000 0.0000000 0.000000
#> b_bl[2] -0.7791 0.2927 0.0007558 0.003959
#> b_bl[3] -0.7791 0.2927 0.0007558 0.003959
#> b_bl[4] -0.7791 0.2927 0.0007558 0.003959
#> b_bl[5] -0.7791 0.2927 0.0007558 0.003959
#> b_bl[6] -0.7791 0.2927 0.0007558 0.003959
#> b_bl[7] -0.7791 0.2927 0.0007558 0.003959
#> d[1] 0.0000 0.0000 0.0000000 0.000000
#> d[2] 1.8640 0.2615 0.0006751 0.001863
#> d[3] 2.1338 0.2259 0.0005832 0.002010
#> d[4] 2.0206 0.4537 0.0011715 0.005449
#> d[5] 1.6344 0.2207 0.0005699 0.001900
#> d[6] 0.3057 0.5967 0.0015407 0.009141
#> d[7] 2.1505 0.3181 0.0008214 0.002861
#> sd 0.1990 0.2232 0.0005762 0.007746
#>
#> 2. Quantiles for each variable:
#>
#> 2.5% 25% 50% 75% 97.5%
#> B -1.299294 -0.92472 -0.7875 -0.6384 -0.2208
#> b_bl[1] 0.000000 0.00000 0.0000 0.0000 0.0000
#> b_bl[2] -1.299294 -0.92472 -0.7875 -0.6384 -0.2208
#> b_bl[3] -1.299294 -0.92472 -0.7875 -0.6384 -0.2208
#> b_bl[4] -1.299294 -0.92472 -0.7875 -0.6384 -0.2208
#> b_bl[5] -1.299294 -0.92472 -0.7875 -0.6384 -0.2208
#> b_bl[6] -1.299294 -0.92472 -0.7875 -0.6384 -0.2208
#> b_bl[7] -1.299294 -0.92472 -0.7875 -0.6384 -0.2208
#> d[1] 0.000000 0.00000 0.0000 0.0000 0.0000
#> d[2] 1.396522 1.75121 1.8627 1.9785 2.3249
#> d[3] 1.738849 2.01360 2.1271 2.2440 2.5770
#> d[4] 1.193555 1.76900 2.0168 2.2668 2.8844
#> d[5] 1.240827 1.52373 1.6324 1.7396 2.0481
#> d[6] -0.904529 -0.04753 0.3256 0.6840 1.3827
#> d[7] 1.594836 1.99408 2.1465 2.2970 2.7452
#> sd 0.008791 0.07374 0.1499 0.2572 0.6653
#>
#>
#> $Treat.order
#> 1 2 3 4 5
#> "Placebo" "CZP" "Adalimumab" "Etanercept" "Infliximab"
#> 6 7
#> "Rituximab" "Tocilizumab"
#>
#> $deviance
#> Dbar pD DIC
#> 27.91516 18.55096 46.46612
#>
#> $total_n
#> [1] 24
#>
#> attr(,"class")
#> [1] "summary.network.result"
We included another inconsistency model that can be used to test consistency assumption. Here we can specify a pair where we want to nodesplit and test the inconsistency assumptions. For instance if we specify treatment pair = c(3, 9), we are finding the difference in the direct and indirect evidence of treatment 3 and 9. Inconsistency estimate and the corresponding p-value are reported in the summary. If the p-value is small, it means that we can reject the null hypothesis that direct and indirect evidence agree. We can repeat for all the pairs in the network and identify pairs that might be inconsistent. Refer to Dias et al. 2010 (i.e. Checking consistency in mixed treatment comparison meta-analysis) for more details.
network <- with(thrombolytic, nodesplit.network.data(Outcomes, Study, Treat, N, response = "binomial", pair = c(3,9), type = "fixed"))
result <- nodesplit.network.run(network)
#> Compiling model graph
#> Resolving undeclared variables
#> Allocating nodes
#> Graph information:
#> Observed stochastic nodes: 102
#> Unobserved stochastic nodes: 59
#> Total graph size: 2263
#>
#> Initializing model
#>
#> NOTE: Stopping adaptation
#>
#>
#> [1] 1.002946
#> [1] 1.000417
summary(result)
#> $summary.samples
#>
#> Iterations = 1:50000
#> Thinning interval = 1
#> Number of chains = 3
#> Sample size per chain = 50000
#>
#> 1. Empirical mean and standard deviation for each variable,
#> plus standard error of the mean:
#>
#> Mean SD Naive SE Time-series SE
#> d[1] 0.0000000 0.00000 0.000e+00 0.0000000
#> d[2] -0.0015963 0.03012 7.777e-05 0.0001840
#> d[3] -0.1604129 0.04325 1.117e-04 0.0003544
#> d[4] -0.0442432 0.04677 1.208e-04 0.0002442
#> d[5] -0.1127774 0.06001 1.549e-04 0.0004670
#> d[6] -0.1546198 0.07718 1.993e-04 0.0005737
#> d[7] -0.4644528 0.10064 2.599e-04 0.0005742
#> d[8] -0.1987703 0.22032 5.689e-04 0.0012597
#> d[9] 0.0035793 0.03708 9.574e-05 0.0002175
#> diff 1.2363826 0.41603 1.074e-03 0.0039086
#> direct 1.4003748 0.41189 1.063e-03 0.0038881
#> oneminusprob 0.0007333 0.02707 6.990e-05 0.0001153
#> prob 0.9992667 0.02707 6.990e-05 0.0001153
#>
#> 2. Quantiles for each variable:
#>
#> 2.5% 25% 50% 75% 97.5%
#> d[1] 0.00000 0.00000 0.000000 0.00000 0.000000
#> d[2] -0.06110 -0.02168 -0.001580 0.01863 0.057376
#> d[3] -0.24572 -0.18947 -0.160013 -0.13130 -0.076128
#> d[4] -0.13602 -0.07572 -0.044110 -0.01273 0.047142
#> d[5] -0.23007 -0.15347 -0.112657 -0.07226 0.004435
#> d[6] -0.30625 -0.20684 -0.154752 -0.10262 -0.003026
#> d[7] -0.66319 -0.53217 -0.463915 -0.39695 -0.267910
#> d[8] -0.63290 -0.34653 -0.198217 -0.05064 0.232463
#> d[9] -0.06943 -0.02138 0.003501 0.02865 0.076170
#> diff 0.46371 0.95065 1.222174 1.50627 2.094969
#> direct 0.63733 1.11777 1.385766 1.66642 2.253635
#> oneminusprob 0.00000 0.00000 0.000000 0.00000 0.000000
#> prob 1.00000 1.00000 1.000000 1.00000 1.000000
#>
#>
#> $deviance
#> NULL
#>
#> $`Inconsistency estimate`
#> [1] 1.236383
#>
#> $p_value
#> [1] 0.001466667
#>
#> attr(,"class")
#> [1] "summary.nodesplit.network.result"
We estimate odds ratios using our NMA model, and then we apply these odds ratios to a baseline risk (i.e. risk in placebo) to estimate absolute event rates for all treatments. Using these absolute event rates, we are then able to find number needed to treat, risk difference, and relative risk.
#Using metaprop function from meta package, we meta-analyze placebo event proportion.
#library(meta)
#placebo_index <- which(certolizumab$Treat == "Placebo")
#meta.pla <- metaprop(event = certolizumab$Outcomes[placebo_index], n = certolizumab$N[placebo_index], method = "GLMM", sm = "PLOGIT")
#mean.A = meta.pla$TE.random; prec.A = 1/meta.pla$tau^2
network <- with(certolizumab, network.data(Outcomes = Outcomes, Treat = Treat, Study = Study, N = N, response = "binomial", mean.A = -2.27, prec.A = 2.53))
result <- network.run(network)
#> Compiling model graph
#> Resolving undeclared variables
#> Allocating nodes
#> Graph information:
#> Observed stochastic nodes: 24
#> Unobserved stochastic nodes: 32
#> Total graph size: 649
#>
#> Initializing model
#>
#> NOTE: Stopping adaptation
#>
#>
#> [1] 1.052281
#> [1] 1.004855
#> [1] 1.033242
summary(result, extra.pars = c("RD", "RR"))
#> $summary.samples
#>
#> Iterations = 1:50000
#> Thinning interval = 1
#> Number of chains = 3
#> Sample size per chain = 50000
#>
#> 1. Empirical mean and standard deviation for each variable,
#> plus standard error of the mean:
#>
#> Mean SD Naive SE Time-series SE
#> RD[1] 0.000000 0.00000 0.0000000 0.0000000
#> RD[2] 0.069974 0.14478 0.0003738 0.0009013
#> RD[3] 0.264297 0.27909 0.0007206 0.0024122
#> RD[4] 0.007705 0.12482 0.0003223 0.0010736
#> RD[5] -0.085809 0.05506 0.0001422 0.0002372
#> RD[6] -0.068181 0.09464 0.0002443 0.0005270
#> RD[7] -0.011367 0.10515 0.0002715 0.0006460
#> RR[1] 1.000000 0.00000 0.0000000 0.0000000
#> RR[2] 1.767481 1.74945 0.0045171 0.0108563
#> RR[3] 4.086763 4.06913 0.0105064 0.0309418
#> RR[4] 1.128489 1.49171 0.0038516 0.0125592
#> RR[5] 0.194134 0.28364 0.0007324 0.0021752
#> RR[6] 0.378558 0.99072 0.0025580 0.0057825
#> RR[7] 0.927518 1.20386 0.0031084 0.0076569
#> d[1] 0.000000 0.00000 0.0000000 0.0000000
#> d[2] 0.356631 1.09470 0.0028265 0.0064195
#> d[3] 1.503419 1.86689 0.0048203 0.0158827
#> d[4] -0.236938 1.04514 0.0026985 0.0079657
#> d[5] -1.991291 0.69636 0.0017980 0.0052266
#> d[6] -1.997013 1.48820 0.0038425 0.0089390
#> d[7] -0.486880 1.08371 0.0027981 0.0066458
#> sd 0.926878 0.62896 0.0016240 0.0093735
#>
#> 2. Quantiles for each variable:
#>
#> 2.5% 25% 50% 75% 97.5%
#> RD[1] 0.000000 0.00000 0.00000 0.000000 0.0000
#> RD[2] -0.099721 -0.01265 0.02943 0.106251 0.4965
#> RD[3] -0.092715 0.02940 0.18733 0.467032 0.8516
#> RD[4] -0.127729 -0.04834 -0.02037 0.017316 0.3863
#> RD[5] -0.214252 -0.11186 -0.07628 -0.050513 -0.0191
#> RD[6] -0.215423 -0.10647 -0.06906 -0.041123 0.1192
#> RD[7] -0.145176 -0.05735 -0.02689 0.003628 0.2676
#> RR[1] 1.000000 1.00000 1.00000 1.000000 1.0000
#> RR[2] 0.179859 0.84480 1.34195 2.092665 6.1280
#> RR[3] 0.171169 1.34627 2.91630 5.483107 14.8144
#> RR[4] 0.144971 0.47835 0.73367 1.199708 4.8295
#> RR[5] 0.036490 0.10726 0.15211 0.212044 0.5808
#> RR[6] 0.007671 0.06673 0.14997 0.333122 2.2221
#> RR[7] 0.072351 0.39175 0.65489 1.043474 3.6384
#> d[1] 0.000000 0.00000 0.00000 0.000000 0.0000
#> d[2] -1.807327 -0.18698 0.33878 0.883041 2.6304
#> d[3] -1.857326 0.34402 1.37033 2.541602 5.5668
#> d[4] -2.022832 -0.79873 -0.34300 0.206577 2.1654
#> d[5] -3.419504 -2.33267 -1.98160 -1.646716 -0.5970
#> d[6] -4.985617 -2.81426 -1.99692 -1.178860 0.9701
#> d[7] -2.732457 -1.00970 -0.46504 0.048326 1.6667
#> sd 0.137532 0.51119 0.78163 1.168909 2.6152
#>
#>
#> $Treat.order
#> 1 2 3 4 5
#> "Adalimumab" "CZP" "Etanercept" "Infliximab" "Placebo"
#> 6 7
#> "Rituximab" "Tocilizumab"
#>
#> $deviance
#> Dbar pD DIC
#> 26.99643 22.63831 49.63474
#>
#> $total_n
#> [1] 24
#>
#> attr(,"class")
#> [1] "summary.network.result"