Introduction
This document describes how to use the main functions of
NMA
to run a single network meta-analysis with non-survival
data.
Example
First load the required packages.
Settings
Define the BUGS parameters for MCMC. This is not necessary, but recommended, because there are default values for these.
bugs_params <-
list(
PROG = "openBugs", # which version of BUGS to use to run the MCMC
N.BURNIN = 10,#00, # number of steps to throw away
N.SIMS = 150,#0, # total number of simulations
N.CHAINS = 2, # number of chains
N.THIN = 1, # thinning rate
PAUSE = TRUE)
Define the scenario we will use for the analysis.
RANDOM <- FALSE # is this a random effects model?
REFTX <- "X" # reference treatment
data_type <- "bin_data" # which type of data to use
label_name <- "label_name"
Read in datasets
Lets read in the each data set. In another article we will show how to do this in one function call by including a Reference file in the data folder which contains the meta data of how to read in the study data.
file_name <- here::here(file.path("inst", "extdata"))
binData <-
read.csv(paste0(file_name, "/bin_data_test.csv"),
header = TRUE,
as.is = TRUE)
The format of the data should be fairly self-explanatory and looks like the following. For the hazard ratio data
study | treatment | n | r | prob |
---|---|---|---|---|
A | X | 224 | 171 | 76.3 |
A | Y | 225 | 168 | 74.7 |
B | X | 45 | 33 | 73.3 |
More information about these data is available in the help
documentation which can be accessed with
e.g. help(binData)
.
Build model
Now we can create the NMA object to use in the modelling. The workflow is to first create this separately to actually doing the fitting. This then means that we can perform modified fits but we don’t have to redo any of the preparatory work.
nma_model <-
new_NMA(binData = binData,
bugs_params = bugs_params,
is_random = RANDOM,
data_type = data_type,
refTx = REFTX ,
label = "",
endpoint = "")
nma_model
#> $dat
#> $dat$inits
#> function() {
#> list(
#> beta = c(NA, rnorm(nTx - 1, 0, 2)),
#> sd = 0.1,
#> alpha = rnorm(nStudies),
#> d = c(NA, rnorm(nTx - 1, 0, 2)), ##TODO: can we remove duplication?
#> mu = rnorm(nStudies),
#> baseLod = 0) %>%
#> .[param_names] # filter redundant
#> }
#> <bytecode: 0x00000000135aaad0>
#> <environment: 0x00000000135b4590>
#>
#> $dat$binData
#> study treatment n r prob
#> 1 A X 224 171 76.3
#> 2 A Y 225 168 74.7
#> 3 B X 45 33 73.3
#>
#> $dat$bugsData
#> $dat$bugsData$mu_beta
#> [1] 0
#>
#> $dat$bugsData$prec_beta
#> [1] 1e-06
#>
#> $dat$bugsData$mu_alpha
#> [1] 0
#>
#> $dat$bugsData$prec_alpha
#> [1] 1e-06
#>
#> $dat$bugsData$t
#> [,1] [,2]
#> [1,] 1 NA
#> [2,] 1 2
#>
#> $dat$bugsData$r
#> [,1] [,2]
#> [1,] 33 NA
#> [2,] 171 168
#>
#> $dat$bugsData$n
#> [,1] [,2]
#> [1,] 45 NA
#> [2,] 224 225
#>
#> $dat$bugsData$nt
#> [1] 2
#>
#> $dat$bugsData$na
#> [1] 1 2
#>
#> $dat$bugsData$ns
#> [1] 2
#>
#> $dat$bugsData$baseR
#> [1] 33 171 NA
#>
#> $dat$bugsData$baseN
#> [1] 45 224 1
#>
#> $dat$bugsData$nBase
#> [1] 3
#>
#> $dat$bugsData$baseTx
#> [1] 1
#>
#> $dat$bugsData$refTx
#> [1] 1
#>
#>
#> $dat$txList
#> [1] "X" "Y"
#>
#>
#> $data_type
#> [1] "bin_data"
#>
#> $bugs_params
#> $bugs_params$PROG
#> [1] "openBugs"
#>
#> $bugs_params$N.BURNIN
#> [1] 10
#>
#> $bugs_params$N.SIMS
#> [1] 150
#>
#> $bugs_params$N.CHAINS
#> [1] 2
#>
#> $bugs_params$N.THIN
#> [1] 1
#>
#> $bugs_params$PAUSE
#> [1] TRUE
#>
#> $bugs_params$run_bugs
#> [1] TRUE
#>
#>
#> $bugs_fn
#> function(...)
#> R2OpenBUGS::bugs(...)
#> <bytecode: 0x0000000016bae4e0>
#> <environment: 0x0000000016bb5938>
#>
#> $is_random
#> [1] FALSE
#>
#> $refTx
#> [1] "X"
#>
#> $effectParam
#> [1] NA
#>
#> $modelParams
#> bin_data
#> "totresdev"
#>
#> $label
#> [1] ""
#>
#> $endpoint
#> [1] ""
#>
#> attr(,"class")
#> [1] "nma"
#> attr(,"CALL")
#> attr(,"CALL")$binData
#> binData
#>
#> attr(,"CALL")$bugs_params
#> bugs_params
#>
#> attr(,"CALL")$is_random
#> RANDOM
#>
#> attr(,"CALL")$data_type
#> data_type
#>
#> attr(,"CALL")$refTx
#> REFTX
#>
#> attr(,"CALL")$label
#> [1] ""
#>
#> attr(,"CALL")$endpoint
#> [1] ""
We can view the network graph.
library(sna)
plotNetwork(nma_model)
Run MCMC
The NMA MCMC function calls the appropriate BUGS model.
nma_res <- NMA_run(nma_model, save = FALSE)
#> ====== RUNNING BUGS MODEL
nma_res
#> Inference for Bugs model at "C:/Users/n8tha/Documents/R/NMA/inst/FE_bin.txt",
#> 2 chains, each with 160 iterations (first 10 discarded)
#> n.sims = 300 iterations saved
#> mean sd 2.5% 25% 50% 75% 97.5% Rhat n.eff
#> totresdev 3.5 2.8 0.2 1.3 2.8 4.9 10.1 1 150
#> deviance 29.4 3.2 25.5 27.1 28.6 31.1 36.6 1 170
#>
#> For each parameter, n.eff is a crude measure of effective sample size,
#> and Rhat is the potential scale reduction factor (at convergence, Rhat=1).
#>
#> DIC info (using the rule, pD = Dbar-Dhat)
#> pD = 4.5 and DIC = 33.9
#> DIC is an estimate of expected predictive error (lower deviance is better).
Plot and tables
BUGS plots are available for diagnosing the performance.
diagnostics(nma_res, save = TRUE)
Different NMA tables can be created. They can provide a record of the analysis.
write_data_to_file(nma_model)
write_results_table(nma_model, nma_res)
pairwiseTable(nma_model, nma_res)
Currently available NMA plots are a treatment effect forest plot of posterior samples and a rank probability grid.
txEffectPlot(nma_model, nma_res)
rankProbPlot(nma_model, nma_res)
It’s also possible to create all of the BUGS and output plots and table functions together and write to an analysis folder.
nma_outputs(nma_res2, save = TRUE)