Skip to contents

predict() gives the cumulative incidence of one cause, averaged over the trees of a competing_risk_forest(), or a risk score for it: the average over the trees of the leaf's cumulative incidence summed over the event times, larger for a higher incidence.

Usage

# S3 method for class 'competing_risk_forest'
predict(object, newdata, type = c("cif", "risk"), cause = 1, times, ...)

Arguments

object

A competing_risk_forest() fit.

newdata

A data frame with the covariates of the subjects to predict for. The default is the data the forest was grown on. Rows with a missing covariate get NA.

type

What to predict: "cif" (the default) or "risk".

cause

The cause, a level of event or its number among the causes. The default is the first cause.

times

For "cif", the times to evaluate at. The default is the event times of the fit.

...

Unused.

Value

For "risk", a numeric vector with one value per row of newdata. For "cif", a data frame with one row per subject and time: subject (the row of newdata), time, and estimate.

Examples

mgus <- data.frame(
  time = c(30, 45, 60, 72, 80, 95, 110, 120, 130, 150, 160, 180, 200, 210, 220, 240, 45, 95,
    50, 100, 140, 170, 190, 230),
  status = c(1, 2, 0, 2, 1, 2, 0, 1, 2, 2, 0, 1, 1, 2, 0, 2, 0, 1, 2, 1, 0, 2, 1, 2),
  age = c(62, 75, 58, 80, 66, 71, 59, 64, 77, 82, 60, 68, 55, 79, 63, 74, 70, 61, 78, 57, 69,
    81, 65, 73)
)
mgus$event <- factor(mgus$status, levels = 0:2, labels = c("censor", "pcm", "death"))

set.seed(1)
forest <- competing_risk_forest(Surv(time, event) ~ age, data = mgus, n_estimators = 25)
newdata <- data.frame(age = c(60, 80))
predict(forest, newdata = newdata, cause = "pcm", times = c(100, 200))
#>   subject time  estimate
#> 1       1  100 0.2909524
#> 2       1  200 0.4006667
#> 3       2  100 0.0000000
#> 4       2  200 0.0000000
predict(forest, newdata = newdata, type = "risk", cause = "death")
#> [1] 0.000 9.004