Predictions from gradient boosting for the Cox model
Source:R/boosting.R
predict.gradient_boosting_survival_analysis.Rdpredict() 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.
Arguments
- object
- 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 relative hazard \(e^{F(x)}\), the default),"lp"(the score \(F(x)\)),"survival", or"cumhaz".- times
For
"survival"and"cumhaz", the times to evaluate at. The default is the event times of the fit.- ...
Unused.
Value
For "risk" and "lp", 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.
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)
)
fit <- gradient_boosting_survival_analysis(Surv(time, status) ~ age + ph.ecog,
data = lung, n_estimators = 50, max_depth = 2
)
# The scores of the first five subjects
predict(fit, type = "lp")[1:5]
#> [1] -0.4797150 -1.0877302 -1.0080899 0.6161180 -0.9717041
predict(fit, newdata = data.frame(age = 65, ph.ecog = 1), type = "cumhaz",
times = c(100, 200, 400)
)
#> subject time estimate
#> 1 1 100 0.2215458
#> 2 1 200 0.3874463
#> 3 1 400 1.2168691