explain: Create Survival Model Explainer

View source: R/explain.R

explainR Documentation

Create Survival Model Explainer

Description

Survival models may have very different structures. This function creates a unified representation of a survival model, which can be further processed by various survival explainers (see also explain).

Please NOTE, that the model is actually the only required argument. But some survival explainers may require additional arguments.

Usage

explain(
  model,
  data = NULL,
  y,
  times = NULL,
  predict_function = yhat,
  link = I,
  label = tail(class(model), 1),
  ...
)

## Default S3 method:
explain(
  model,
  data = NULL,
  y,
  times = NULL,
  predict_function = yhat,
  link = I,
  label = tail(class(model), 1),
  ...
)

Arguments

model

object - a survival model to be explained

data

data.frame, tibble or matrix - data that will be used by survival explainers. If not provided then will be extracted from the model

y

object of class 'surv', contains event status and times

times

optional argument, the vector of time points on which survival probability will be predicted

predict_function

function that takes three arguments: model, new data, vector with times, and returns numeric vector or matrix with predictions. If not passed, function predictSurvProb is used.

link

function - a transformation/link function that shall be applied to raw model predictions

label

character - the name of the survival model. By default it's extracted from the 'class' attribute of the model.

...

other parameters

Value

An object of the class 'surv_explainer'.

It's a list with following fields:

  • model the explained model

  • data the dataset

  • y event statuses and times

  • times time points on which survival probability is predicted

  • predict_function function that may be used for model predictions, shall return a single numerical value for each time.

  • link function - a transformation/link function that shall be applied to raw model predictions

  • class class/classes of a model

  • label label, by default it's the last value from the class vector, but may be set to any character.

Examples


library(survxai)
library(rms)
library(randomForestSRC)
data(pbc, package = "randomForestSRC")
pbc <- pbc[complete.cases(pbc),]
predict_times <- function(model, data, times){
                  prob <- rms::survest(model, data, times = times)$surv
                  return(prob)
                  }
cph_model <- cph(Surv(days/365, status)~ sex + bili + stage, data=pbc, surv=TRUE, x = TRUE, y=TRUE)
surve_cph <- explain(model = cph_model, data = pbc[,-c(1,2)], y = Surv(pbc$days/365, pbc$status),
             predict_function = predict_times)


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