Skip to contents

survival_tree() splits the subjects into groups with similar survival. Starting from all of them, it looks for the covariate and the cut-point that best separate the survival of the two groups they make, by the two-sample log-rank statistic, and splits there. It then splits each group in the same way, until a group is too small to split, has no events, or reaches max_depth. A cut-point is the midpoint between two neighboring values of the covariate, and each side of a split keeps at least min_samples_leaf subjects.

Usage

survival_tree(
  formula,
  data,
  subset,
  na.action = stats::na.omit,
  max_depth = NULL,
  min_samples_split = 6,
  min_samples_leaf = 3,
  max_features = NULL,
  splitter = c("best", "random")
)

Arguments

formula

A formula with a right-censored Surv() response on the left and the covariates on the right, such as Surv(time, status) ~ age + sex. Factors are coded with treatment contrasts, and each column is split on separately.

data

A data frame holding the variables in formula.

subset

An optional expression selecting the rows of data to use.

na.action

What to do with rows that have missing values. The default drops them.

max_depth

The largest number of splits from the first group to a leaf, or NULL (the default) for no limit.

min_samples_split

The smallest group that can be split, at least 2. The default is 6.

min_samples_leaf

The fewest subjects on each side of a split, at least 1. The default is 3.

max_features

The number of covariates tried at each split: NULL (all of them, the default), "sqrt" or "log2" (the square root or base-2 logarithm of the number of columns, rounded down), a whole number, or a fraction between 0 and 1 of the columns. At least one is always tried.

splitter

"best" (the default) to try every cut-point, or "random" to try one random cut-point per covariate.

Value

A survival_tree object. Use predict() for risk scores and survival or cumulative hazard curves, and as.data.frame() for the nodes of the tree. The object also holds times (the event times the curves are given at), n, n_event, n_nodes, and n_leaves.

Details

Each final group (a leaf) holds the Nelson-Aalen cumulative hazard and the Kaplan-Meier survival curve of its subjects, at the event times of the whole data. A subject's prediction is the curve of the leaf their covariates lead to. The risk score is the leaf's cumulative hazard summed over those event times (the ensemble mortality of Ishwaran et al., 2008), larger for an earlier event. No proportional hazards or other form for the effects of the covariates is assumed.

With splitter = "random", each covariate gets a single cut-point drawn at random between its smallest and largest values in the group, and the best of those is used. With max_features smaller than the number of covariates, each split looks at a random subset of them. Both use R's random number generator, so call set.seed() first for results that can be repeated. A single tree is mostly useful to read. For prediction, the forests average many of them (see random_survival_forest()).

References

Ishwaran, H., Kogalur, U. B., Blackstone, E. H., and Lauer, M. S. (2008). Random survival forests. The Annals of Applied Statistics, 2(3), 841-860.

See also

random_survival_forest() and extra_survival_trees() for forests of these trees.

Examples

lung <- data.frame(
  time = c(306, 455, 1010, 210, 883, 1022, 310, 361, 218, 166, 170, 654, 728, 71, 567, 144,
    613, 707, 61, 88, 301, 81, 624, 371, 394, 520, 574, 118, 390, 12),
  status = c(2, 2, 1, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
    2, 2, 2),
  age = c(74, 68, 56, 57, 60, 74, 68, 71, 53, 61, 57, 68, 68, 60, 57, 67, 70, 63, 56, 57, 67,
    49, 50, 58, 72, 70, 60, 70, 53, 74),
  ph.ecog = c(1, 0, 0, 1, 0, 1, 2, 2, 1, 2, 1, 2, 2, 1, 1, 2, 1, 0, 1, 1, 2, 0, 0, 1, 1, 1, 1,
    2, 1, 1)
)

tree <- survival_tree(Surv(time, status) ~ age + ph.ecog, data = lung, max_depth = 2)
tree
#> <survival_tree> Surv(time, status) ~ age + ph.ecog
#> Log-rank splits, 7 nodes, 4 leaves. n = 30, events = 26, features = 2

# The splits and the leaves
as.data.frame(tree)
#>   node depth    term threshold left right  n n_event
#> 1    1     0 ph.ecog       0.5    2     5 30      26
#> 2    2     1     age      58.0    3     4  6       5
#> 3    3     2    <NA>        NA   NA    NA  3       2
#> 4    4     2    <NA>        NA   NA    NA  3       3
#> 5    5     1     age      67.5    6     7 24      21
#> 6    6     2    <NA>        NA   NA    NA 13      12
#> 7    7     2    <NA>        NA   NA    NA 11       9

# Survival curves for two new subjects
predict(tree, newdata = data.frame(age = c(55, 72), ph.ecog = c(0, 2)), type = "survival",
  times = c(100, 300, 500)
)
#>   subject time  estimate
#> 1       1  100 0.6666667
#> 2       1  300 0.6666667
#> 3       1  500 0.6666667
#> 4       2  100 0.9090909
#> 5       2  300 0.8181818
#> 6       2  500 0.4545455