knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
To install the most recent update of SurvBART from github, run:
devtools::install_github("nillen0/SurvBART")
Once we have the package installed, we need to load the package:
library(SurvBART)
In this tutorial, we will run fit a survival BART model using simulated data. To simulate data with a sample size of 100 and a censorign rate of $50\%$ run:
set.seed(807) Data = SimulateData(n = 100, censoring.rate = 0.5)
Once we have our data we need to draw from the posterior distribution of the survival probabilities at each time point. Because this is computationally efficient, we recommend parallelizing the process. Using the parallel
and NumCores
statements in the function ObtainPost()
, we can tell R to draw our posterior draws from parallel chains on NumCores
many cores.
PosteriorDraws = ObtainPost(Times = Data$time, Event = Data$event, parallel = T, NumCores = 2)
This function outputs a list with two elements. The first surv
is a matrix of posterior draws, and the second time
is a vector of the unique time points observed in the data.
Using these draws we can find the estimated survival probabilities at each unique time:
SurvEst(PosteriorDraws = PosteriorDraws$surv)
We can plot estimated survival curves with credible interval bounds using:
PlotSurv(PosteriorDraws = PosteriorDraws$surv, UniqueTimes = PosteriorDraws$time, CredLevel = 0.95)
To obtain an estimated quantile with credible interval:
QuantEst(PosteriorDraws = PosteriorDraws$surv, Times = PosteriorDraws$time, Quantiles = c(0.1, 0.25, 0.5, 0.75, 0.9), CredLevel = 0.95)
Note, some values may be NA. This occurs when there is enough censoring in the data that certain quantiles of survival are not observed in the data.
If we want to compare quantile estimates of BART with those of KM or Weibull regression we can run:
Quants = QuantAll(PosteriorDraws = PosteriorDraws$surv, Times = Data$time, Event = Data$event, Quantiles = c(0.1, 0.25, 0.5, 0.75, 0.9), ConfLevel = 0.95) Quants
We can summarise the point estimates of quantiles and coverage of credible/confidence intervals of this output using:
AnalyzeQuants(QuantMatrix = Quants, Quantiles = c(0.1, 0.25, 0.5, 0.75, 0.9), shape = 0.8, scale = 2.5)
To replicate this entire process at once, we provide the wrapper function:
Simulation(n = 100, CensoringRate = 0.5, Parallel = T, NumCores = 2, seed = 807)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.