knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
This document describes how to use the main functions of NMA
to run a single network meta-analysis with survival data.
First load the required packages.
library(NMA) library(dplyr) library(purrr)
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 <- c("hr_data", "surv_bin_data", "med_data") # which type of data to use label_name <- "label_name"
The trials data consist of up to 3 separate data frames.
A main table, subData
, and optional tables for median event time and binary data, survDataMed
and survDataBin
respectively.
Lets read in the each data set separately.
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.
If there is no binary or median data used in the NMA then the variables survDataBin
and survDataMed
are assigned NA
.
file_name <- here::here(file.path("inst", "extdata", "survdata_")) survDataHR <- read.csv(paste0(file_name, "hr_test.csv"), header = TRUE, as.is = TRUE) survDataBin <- tryCatch( read.csv(paste0(file_name, "bin_test.csv"), header = TRUE, as.is = TRUE), error = function(e) NA) survDataMed <- tryCatch( read.csv(paste0(file_name, "med_test.csv"), header = TRUE, as.is = TRUE) %>% mutate(medR = floor(medR)), error = function(e) NA)
The format of the data should be fairly self-explanatory and looks like the following. For the hazard ratio data
knitr::kable(survDataHR)
For the binary data
knitr::kable(survDataBin)
and for the median time data
knitr::kable(survDataMed)
More information about these data is available in the help documentation which can be accessed with e.g. help(subData)
.
The package uses the model in @Woods2010 for NMA combining count and hazard ratio statistics in multi-arm trials. For count data, the cumulative count of subjects who have experienced an event in arm $k$ of study $s$
$$ r_{s,k} \sim Bin(F_{s,k}, n_{s,k}) $$
A log cumulative hazard for each trial arm
$$ \ln (H_{s,k}) = \ln ( - \ln (1 - F_{s,k}))) $$
where
$$ \ln (H_{s,k}) = \alpha_s + \beta_k - \beta_b $$
Under an assumption of proportional hazards, the $\beta_k$ coefficient is equal to the log hazard ratio.
The counts and hazard ratio data can then be used together, placing a normal distribution error on the log HR.
A random effect is included in the model as follows.
$$ \ln (H_{s,k}) = \alpha_s + \beta_k - \beta_b + re_{s,k} - re_{s,b} $$
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(survDataHR = survDataHR, survDataMed = survDataMed, survDataBin = survDataBin, bugs_params = bugs_params, is_random = RANDOM, data_type = data_type, refTx = REFTX , effectParam = "beta", label = "", endpoint = "") nma_model
We can view the network graph.
library(sna) plotNetwork(nma_model)
The NMA MCMC function calls the appropriate BUGS model.
nma_res <- NMA_run(nma_model, save = FALSE) nma_res
http://127.0.0.1:34255/graphics/plot_zoom_png?width=1121&height=900
It is simple to modify an existing analysis without repeating the previous steps. For example, we can run the NMA for a random effects rather than a fixed effects model version of the same model.
nma_model2 <- NMA_update(nma_model, is_random = TRUE)
nma_res2 <- NMA_run(nma_model2, save = FALSE) nma_res2
BUGS plots are available for diagnosing the performance.
diagnostics(nma_res2, 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.