knitr::opts_chunk$set(prompt = TRUE, comment = "", collapse = TRUE)

In this vignette, we demonstrate how to use the rocTree() function in rocTree package to fit the ensemble method.

Simulated data

We will demonstrate fitting ensembles with a simulated data prepared by the simu function. ```{R load} library(rocTree) set.seed(2019) dat <- simu(n = 100, cen = 0.25, sce = 2.1, summary = TRUE)

## The ensembles

The ensemble method can be easily called by setting `ensemble = TRUE` (default) when fitting a `rocTree()`.
Ensemble method improve the variance reduction of bagging
by reducing the correlation between the trees via random selection of predictors in the tree-
growing process.
In the following, we apply the ensemble method with fully grown trees with small terminal nodes and without pruning.
We first load the `survival` package to enable `Surv`.
A total of 500 survival trees can be grown as follow:
```{R tree, tidy = TRUE, cache = TRUE}
library(survival)
system.time(fit <- rocTree(Surv(Time, death) ~ z1 + z2, id = id, data = dat, ensemble = TRUE))

Some of the important parameters can be printed directly. ```{R print, tidy = TRUE} fit

The function `rocTree` returns an object of S3 class.
The 500 survival trees are stored in `fit$trees`.
These survival trees can be printed and plotted with the generic function `print` and `plot`, respectively.
For example, the first of the 500 survival trees can be printed/plotted as below.
```{R tree1}
print(fit, tree = 1)
plot(fit, tree = 1)

The other trees can be printed/plotted similarly by specifying the tree argument. Users are referred to the Package vignette on fitting time-invariant survival tree for different printing/plotting options.

Prediction

Suppose we have a new data that is generated as below: ```{R newDat} newdat <- dplyr::tibble(Time = sort(unique(dat$Time)), z1 = 1 * (Time < median(Time)), z2 = runif(1)) newdat

The predicted survival curve can be plotted with the following codes.
```{R pred}
pred <- predict(fit, newdat)
pred
plot(pred)


stc04003/rocTree documentation built on Sept. 25, 2020, 11:51 a.m.