predict() gives the risk score of each row of newdata (or of the subjects the model was fit
to), or its survival or cumulative hazard curve. For a forest, these are the averages over the
trees. The risk score is the cumulative hazard summed over the event times of the fit (the
ensemble mortality), larger for an earlier event. as.data.frame() gives the nodes of a
single tree.
Usage
# S3 method for class 'survival_tree'
predict(object, newdata, type = c("risk", "survival", "cumhaz"), times, ...)
# S3 method for class 'survival_forest'
predict(object, newdata, type = c("risk", "survival", "cumhaz"), times, ...)
# S3 method for class 'survival_tree'
as.data.frame(x, row.names = NULL, optional = FALSE, ...)Arguments
- object, x
A
survival_tree(),random_survival_forest(), orextra_survival_trees()fit.- newdata
A data frame with the covariates of the subjects to predict for. The default is the data the model was fit to.
- type
What to predict:
"risk"(the default),"survival", or"cumhaz".- times
For
"survival"and"cumhaz", the times to evaluate at. The default is the event times of the fit.- ...
Unused.
- row.names, optional
Unused. They're part of the
as.data.frame()generic.
Value
For "risk", a numeric vector with one value per row of newdata. For "survival"
and "cumhaz", a data frame with one row per subject and time: subject (the row of
newdata), time, and estimate. A row with a missing covariate gets NA.
as.data.frame() gives one row per node of the tree, in the order they were made: node,
depth, term (the covariate split on, NA for a leaf), threshold (rows with a value at
or below it go left), left and right (the child nodes, NA for a leaf), n, and
n_event.
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)
# The risk scores of the first five subjects
predict(tree)[1:5]
#> [1] 15.254113 5.000000 9.666667 35.291728 5.000000
# Cumulative hazard curves for a new subject
predict(tree, newdata = data.frame(age = 65, ph.ecog = 1), type = "cumhaz",
times = c(100, 200, 400)
)
#> subject time estimate
#> 1 1 100 0.2511655
#> 2 1 200 0.4872766
#> 3 1 400 1.5801338