Learn R Programming

BART (version 1.6)

crisk.bart: BART for competing risks

Description

Here we have implemented a simple and direct approach to utilize BART for competing risks that is very flexible, and is akin to discrete-time survival analysis. Following the capabilities of BART, we allow for maximum flexibility in modeling the dependence of competing failure times on covariates. In particular, we do not impose proportional hazards.

To elaborate, consider data in the usual form: \((t_i, \delta_i, {x}_i)\) where \(t_i\) is the event time, \(\delta_i\) is an indicator distinguishing events (\(\delta=1\)) from right-censoring (\(\delta=0\)), \({x}_i\) is a vector of covariates, and \(i=1, ..., N\) indexes subjects.

We denote the \(K\) distinct event/censoring times by \(0<t_{(1)}<...<t_{(K)}<\infty\) thus taking \(t_{(j)}\) to be the \(j^{th}\) order statistic among distinct observation times and, for convenience, \(t_{(0)}=0\). Now consider event indicators \(y_{ij}\) for each subject \(i\) at each distinct time \(t_{(j)}\) up to and including the subject's observation time \(t_i=t_{(n_i)}\) with \(n_i=\sum_j I[t_{(j)}\leq t_i]\). This means \(y_{ij}=0\) if \(j<n_i\) and \(y_{in_i}=\delta_i\).

We then denote by \(p_{ij}\) the probability of an event at time \(t_{(j)}\) conditional on no previous event. We now write the model for \(y_{ij}\) as a nonparametric probit regression of \(y_{ij}\) on the time \(t_{(j)}\) and the covariates \({x}_i\), and then utilize BART for binary responses. Specifically, \( y_{ij}\ =\ \delta_i I[t_i=t_{(j)}],\ j=1, ..., n_i \); we have \(p_{ij} = F(\mu_{ij}),\ \mu_{ij} = \mu_0+f(t_{(j)}, {x}_i)\) where \(F\) denotes the standard normal cdf (probit link). As in the binary response case, \(f\) is the sum of many tree models.

Usage

crisk.bart(x.train=matrix(0, 0L, 0L), y.train=NULL,
           x.train2=x.train, y.train2=NULL,
           times=NULL, delta=NULL, K=NULL,
           x.test=matrix(0.0,0,0), x.test2=x.test, cond=NULL,
           sparse=FALSE, a=0.5, b=1, augment=FALSE, rho=NULL, rho2=NULL,
           xinfo=matrix(0.0,0,0), xinfo2=matrix(0.0,0,0), usequants=FALSE,
           cont=FALSE, rm.const=TRUE, type='pbart',
           k=2.0, power=2.0, base=.95,
           binaryOffset=NULL, binaryOffset2=NULL,
           ntree=50, numcut=100, ndpost=1000, nskip=250,
           keepevery = 10L,
           nkeeptrain=ndpost,
           nkeeptest=ndpost,
           
           nkeeptreedraws=ndpost,
           printevery=100L, 
           keeptrainfits=TRUE,
           id=NULL,    ## crisk.bart only
           seed=99,    ## mc.crisk.bart only
           mc.cores=2, ## mc.crisk.bart only
           nice=19L    ## mc.crisk.bart only
          )

mc.crisk.bart(x.train=matrix(0, 0L, 0L), y.train=NULL, x.train2=x.train, y.train2=NULL, times=NULL, delta=NULL, K=NULL, x.test=matrix(0.0,0,0), x.test2=x.test, cond=NULL, sparse=FALSE, a=0.5, b=1, augment=FALSE, rho=NULL, rho2=NULL, xinfo=matrix(0.0,0,0), xinfo2=matrix(0.0,0,0), usequants=FALSE, cont=FALSE, rm.const=TRUE, type='pbart', k=2.0, power=2.0, base=.95, binaryOffset=NULL, binaryOffset2=NULL, ntree=50, numcut=100, ndpost=1000, nskip=250, keepevery = 10L, nkeeptrain=ndpost, nkeeptest=ndpost, nkeeptreedraws=ndpost, printevery=100L, keeptrainfits=TRUE, id=NULL, ## crisk.bart only seed=99, ## mc.crisk.bart only mc.cores=2, ## mc.crisk.bart only nice=19L ## mc.crisk.bart only )

Arguments

x.train

Explanatory variables for training (in sample) data of cause 1. Must be a matrix with (as usual) rows corresponding to observations and columns to variables. crisk.bart will generate draws of \(f(t, x)\) for each \(x\) which is a row of x.train (note that the definition of x.train is dependent on whether y.train has been specified; see below).

y.train

Cause 1 binary response for training (in sample) data. If y.train is NULL, then y.train (x.train and x.test, if specified) are generated by a call to crisk.pre.bart (which require that times and delta be provided: see below); otherwise, y.train (x.train and x.test, if specified) are utilized as given assuming that the data construction has already been performed.

x.train2

Explanatory variables for training (in sample) data of cause 2.

y.train2

Cause 2 binary response for training (in sample) data, i.e., failure from any cause besides the cause of interest which is cause 1. Similar to y.train above.

times

The time of event or right-censoring. If y.train is NULL, then times (and delta) must be provided.

delta

The event indicator: 1 is a cause 1 event, 2 a cause 2 event while 0 is censored. If y.train is NULL, then delta (and times) must be provided.

K

If provided, then coarsen times per the quantiles \(1/K, 2/K, ..., K/K\).

x.test

Explanatory variables for test (out of sample) data of cause 1. Must be a matrix and have the same structure as x.train. crisk.bart will generate draws of \(f(t, x)\) for each \(x\) which is a row of x.test.

x.test2

Explanatory variables for test (out of sample) data of cause 2.

cond

A vector of indices of y.train indicating censored subjects.

sparse

Whether to perform variable selection based on a sparse Dirichlet prior rather than simply uniform; see Linero 2016.

a

Sparse parameter for \(Beta(a, b)\) prior: \(0.5<=a<=1\) where lower values inducing more sparsity.

b

Sparse parameter for \(Beta(a, b)\) prior; typically, \(b=1\).

rho

Sparse parameter: typically \(rho=p\) where \(p\) is the number of covariates in x.train.

rho2

Sparse parameter: typically \(rho2=p\) where \(p\) is the number of covariates in x.train2.

augment

Whether data augmentation is to be performed in sparse variable selection.

xinfo

You can provide the cutpoints to BART or let BART choose them for you. To provide them, use the xinfo argument to specify a list (matrix) where the items (rows) are the covariates and the contents of the items (columns) are the cutpoints.

xinfo2

Cause 2 cutpoints.

usequants

If usequants=FALSE, then the cutpoints in xinfo are generated uniformly; otherwise, if TRUE, uniform quantiles are used for the cutpoints.

cont

Whether or not to assume all variables are continuous.

rm.const

Whether or not to remove constant variables.

type

Whether to employ Albert-Chib, 'pbart', or Holmes-Held, 'lbart'.

k

k is the number of prior standard deviations \(f(t, x)\) is away from +/-3. The bigger k is, the more conservative the fitting will be.

power

Power parameter for tree prior.

base

Base parameter for tree prior.

binaryOffset

Cause 1 binary offset.

binaryOffset2

Cause 2 binary offset.

ntree

The number of trees in the sum.

numcut

The number of possible values of c (see usequants). If a single number if given, this is used for all variables. Otherwise a vector with length equal to ncol(x.train) is required, where the \(i^{th}\) element gives the number of c used for the \(i^{th}\) variable in x.train. If usequants is false, numcut equally spaced cutoffs are used covering the range of values in the corresponding column of x.train. If usequants is true, then min(numcut, the number of unique values in the corresponding columns of x.train - 1) c values are used.

ndpost

The number of posterior draws returned.

nskip

Number of MCMC iterations to be treated as burn in.

keepevery

Every keepevery draw is kept to be returned to the user.

nkeeptrain

Number of MCMC iterations to be returned for train data.

nkeeptest

Number of MCMC iterations to be returned for test data.

nkeeptreedraws

Number of MCMC iterations to be returned for tree draws.

printevery

As the MCMC runs, a message is printed every printevery draws.

keeptrainfits

Whether to keep yhat.train or not.

id

crisk.bart only: unique identifier added to returned list.

seed

mc.crisk.bart only: seed required for reproducible MCMC.

mc.cores

mc.crisk.bart only: number of cores to employ in parallel.

nice

mc.crisk.bart only: set the job niceness. The default niceness is 19: niceness goes from 0 (highest) to 19 (lowest).

Value

crisk.bart returns an object of type criskbart which is essentially a list. Besides the items listed below, the list has a binaryOffset component giving the value used, a times component giving the unique times, K which is the number of unique times, tx.train and tx.test, if any.

yhat.train

A matrix with ndpost rows and nrow(x.train) columns. Each row corresponds to a draw \(f^*\) from the posterior of \(f\) and each column corresponds to a row of x.train. The \((i,j)\) value is \(f^*(t, x)\) for the \(i^{th}\) kept draw of \(f\) and the \(j^{th}\) row of x.train. Burn-in is dropped.

yhat.test

Same as yhat.train but now the x's are the rows of the test data.

surv.test

test data fits for survival probability.

surv.test.mean

mean of surv.test over the posterior samples.

prob.test

The probability of suffering cause 1 which is occasionally useful, e.g., in calculating the concordance.

prob.test2

The probability of suffering cause 2 which is occasionally useful, e.g., in calculating the concordance.

cif.test

The cumulative incidence function of cause 1, \(F_1(t, x)\), where x's are the rows of the test data.

cif.test2

The cumulative incidence function of cause 2, \(F_2(t, x)\), where x's are the rows of the test data.

%\item{yhat.train.mean}{train data fits = mean of yhat.train columns.}
yhat.test.mean

test data fits = mean of yhat.test columns.

cif.test.mean

mean of cif.test columns for cause 1.

cif.test2.mean

mean of cif.test2 columns for cause 2.

varcount

a matrix with ndpost rows and nrow(x.train) columns. Each row is for a draw. For each variable (corresponding to the columns), the total count of the number of times that variable is used for cause 1 in a tree decision rule (over all trees) is given.

varcount2

For each variable the total count of the number of times that variable is used for cause 2 in a tree decision rule is given.

References

Sparapani, R., Logan, B., McCulloch, R., and Laud, P. (2016) Nonparametric survival analysis using Bayesian Additive Regression Trees (BART). Statistics in Medicine, 16:2741-53 <doi:10.1002/sim.6893>.

Linero, A.R. (2016) Bayesian regression trees for high dimensional prediction and variable selection. JASA, http://dx.doi.org/10.1080/01621459.2016.1264957

See Also

crisk.pre.bart, predict.criskbart, mc.crisk.pwbart

Examples

Run this code
# NOT RUN {
data(transplant)

pfit <- survfit(Surv(futime, event) ~ abo, transplant)

# competing risks for type O
plot(pfit[4,], xscale=30.5, xmax=735, col=1:3, lwd=2, ylim=c(0, 1),
       xlab='t (months)', ylab='Aalen-Johansen (AJ) CI(t)')
    legend(450, .4, c("Death", "Transplant", "Withdrawal"), col=1:3, lwd=2)

delta <- (as.numeric(transplant$event)-1)

delta[delta==1] <- 4
delta[delta==2] <- 1
delta[delta>1] <- 2
table(delta, transplant$event)

table(1+floor(transplant$futime/30.5)) ## months
times <- 1+floor(transplant$futime/30.5)

typeO <- 1*(transplant$abo=='O')
typeA <- 1*(transplant$abo=='A')
typeB <- 1*(transplant$abo=='B')
typeAB <- 1*(transplant$abo=='AB')
table(typeA, typeO)

x.train <- cbind(typeO, typeA, typeB, typeAB)

N <- nrow(x.train)

x.test <- x.train

x.test[1:N, 1:4] <- matrix(c(1, 0, 0, 0), nrow=N, ncol=4, byrow=TRUE)

##test BART with token run to ensure installation works
set.seed(99)
post <- crisk.bart(x.train=x.train, times=times, delta=delta, x.test=x.test,
                   nskip=1, ndpost=1, keepevery=1)

# }
# NOT RUN {
## run one long MCMC chain in one process
## set.seed(99)
## post <- crisk.bart(x.train=x.train, times=times, delta=delta, x.test=x.test)

## in the interest of time, consider speeding it up by parallel processing
## run "mc.cores" number of shorter MCMC chains in parallel processes
post <- mc.crisk.bart(x.train=x.train, times=times, delta=delta, x.test=x.test,
                      seed=99, mc.cores=8)

K <- post$K

typeO.cif.mean <- apply(post$cif.test, 2, mean)
typeO.cif.025 <- apply(post$cif.test, 2, quantile, probs=0.025)
typeO.cif.975 <- apply(post$cif.test, 2, quantile, probs=0.975)

plot(pfit[4,], xscale=7, xmax=735, col=1:3, lwd=2, ylim=c(0, 0.8),
       xlab='t (weeks)', ylab='CI(t)')
points(c(0, post$times)*7, c(0, typeO.cif.mean), col=4, type='s', lwd=2)
points(c(0, post$times)*7, c(0, typeO.cif.025), col=4, type='s', lwd=2, lty=2)
points(c(0, post$times)*7, c(0, typeO.cif.975), col=4, type='s', lwd=2, lty=2)
     legend(450, .4, c("Transplant(BART)", "Transplant(AJ)",
                       "Death(AJ)", "Withdrawal(AJ)"),
            col=c(4, 2, 1, 3), lwd=2)
## plot(pfit[4,], xscale=30.5, xmax=735, col=1:3, lwd=2, ylim=c(0, 0.8),
##        xlab='t (months)', ylab='CI(t)')
## points(c(0, post$times)*30.5, c(0, typeO.cif.mean), col=4, type='s', lwd=2)
## points(c(0, post$times)*30.5, c(0, typeO.cif.025), col=4, type='s', lwd=2, lty=2)
## points(c(0, post$times)*30.5, c(0, typeO.cif.975), col=4, type='s', lwd=2, lty=2)
##      legend(450, .4, c("Transplant(BART)", "Transplant(AJ)",
##                        "Death(AJ)", "Withdrawal(AJ)"),
##             col=c(4, 2, 1, 3), lwd=2)

# }

Run the code above in your browser using DataLab