Variable importance
Source:R/boosting.R, R/competing-risk-forest.R, R/survival-tree.R
variable_importance.Rdvariable_importance() measures how much each covariate contributes to a tree model's
predictions.
Usage
# S3 method for class 'gradient_boosting_survival_analysis'
variable_importance(object, ...)
# S3 method for class 'competing_risk_forest'
variable_importance(object, cause = 1, n_repeats = 5, ...)
variable_importance(object, ...)
# S3 method for class 'survival_forest'
variable_importance(object, n_repeats = 5, ...)Arguments
- object
A
random_survival_forest(),extra_survival_trees(),competing_risk_forest(), orgradient_boosting_survival_analysis()fit.- ...
Unused.
- cause
For a
competing_risk_forest(), the cause whose out-of-bag concordance is used, a level ofeventor its number among the causes. The default is the first cause.- n_repeats
For forests, the number of shuffles of each covariate. The default is
5.
Value
A data frame with one row per covariate (column of the design), from the most to the
least important: term and importance.
Details
For random_survival_forest(), extra_survival_trees(), and competing_risk_forest() fits,
it's the permutation importance: the values of one covariate are shuffled among the subjects,
the out-of-bag error (one minus the out-of-bag concordance) is computed again, and the
importance is how much it went up, averaged over n_repeats shuffles. Shuffling a covariate
the forest doesn't use changes nothing, so its importance is about 0, and it can come out a
little below. The forest must be grown on bootstrap samples. For a competing-risks forest, the
concordance is that of one cause's risk score, with the other causes as censoring. The shuffles
use R's random number generator, so call set.seed() first for results that can be repeated.
For gradient_boosting_survival_analysis() fits, it's the impurity importance: the total
reduction in squared error of the splits on each covariate, over all of the trees, as a share
of the total over all covariates.
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)
)
set.seed(1)
forest <- random_survival_forest(Surv(time, status) ~ age + ph.ecog,
data = lung, n_estimators = 50
)
variable_importance(forest, n_repeats = 3)
#> term importance
#> 1 ph.ecog 0.02614379
#> 2 age -0.07924837
boosted <- gradient_boosting_survival_analysis(Surv(time, status) ~ age + ph.ecog,
data = lung, n_estimators = 50, max_depth = 2
)
variable_importance(boosted)
#> term importance
#> 1 age 0.5226388
#> 2 ph.ecog 0.4773612