prediction_breakdown: BreakDown for survival models

View source: R/prediction_breakdown.R

prediction_breakdownR Documentation

BreakDown for survival models

Description

Function prediction_breakdown is an extension of a broken function from breakDown package. It computes the contribution in prediction for the variables in the model. The contribution is defined as the difference between survival probabilities for model with added specific value of variable and with the random levels of this variable.

Usage

prediction_breakdown(explainer, observation, time = NULL, prob = NULL, ...)

Arguments

explainer

an object of the class 'surv_explainer'

observation

a new observation to explain

time

a time point at which variable contributions are computed. If NULL median time is taken.

prob

a survival probability at which variable contributions are computed

...

other parameters corresponding to arguments from broken function from breakDown package. See https://github.com/pbiecek/breakDown/blob/master/R/break_agnostic.R for details

Value

An object of class surv_prediction_breakdown_explainer

Examples


library(survxai)
library(rms)
data("pbcTest")
data("pbcTrain")
predict_times <- function(model, data, times){
                  prob <- rms::survest(model, data, times = times)$surv
                  return(prob)
                  }
cph_model <- cph(Surv(years, status)~sex + bili + stage, data=pbcTrain, surv=TRUE, x = TRUE, y=TRUE)
surve_cph <- explain(model = cph_model, data = pbcTest[,-c(1,5)],
                    y = Surv(pbcTest$years, pbcTest$status), predict_function = predict_times)
broken_prediction <- prediction_breakdown(surve_cph, pbcTest[1,-c(1,5)])


MI2DataLab/survxai documentation built on Sept. 10, 2022, 12:03 a.m.