explain: Create Survival Model Explainer

Description Usage Arguments Value Examples

View source: R/explain.R

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
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:

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
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)

survxai documentation built on Aug. 28, 2020, 5:07 p.m.