Learn R Programming

survex (version 1.2.0)

predict.surv_explainer: Model Predictions for Survival Models

Description

This function allows for calculating model prediction in a unified way.

Usage

# S3 method for surv_explainer
predict(object, newdata = NULL, output_type = "survival", times = NULL, ...)

Value

A vector or matrix containing the prediction.

Arguments

object

an explainer object - model preprocessed by the explain() function

newdata

data used for the prediction

output_type

character, either "risk", "survival" or "chf" depending on the desired output

times

a numeric vector of times for the survival and cumulative hazard function predictions to be evaluated at. If "output_type == "risk" this argument is ignored, if left NULL then it is extracted from object$times.

...

other arguments, currently ignored

Examples

Run this code
library(survival)
library(survex)


cph <- coxph(Surv(time, status) ~ ., data = veteran, model = TRUE, x = TRUE, y = TRUE)
rsf_ranger <- ranger::ranger(Surv(time, status) ~ .,
    data = veteran,
    respect.unordered.factors = TRUE,
    num.trees = 100,
    mtry = 3,
    max.depth = 5
)

cph_exp <- explain(cph)

rsf_ranger_exp <- explain(rsf_ranger,
    data = veteran[, -c(3, 4)],
    y = Surv(veteran$time, veteran$status)
)


predict(cph_exp, veteran[1, ], output_type = "survival")[, 1:10]

predict(cph_exp, veteran[1, ], output_type = "risk")

predict(rsf_ranger_exp, veteran[1, ], output_type = "chf")[, 1:10]

Run the code above in your browser using DataLab