ceteris_paribus: Ceteris Paribus

Description Usage Arguments Value Examples

View source: R/ceteris_paribus.R

Description

The ceteris_paribus() function computes the predictions for the neighbor of our chosen observation. The neighbour is defined as the observations with changed value of one of the variable.

Usage

1
2
3
4
5
6
ceteris_paribus(
  explainer,
  observation,
  grid_points = 5,
  selected_variables = NULL
)

Arguments

explainer

a model to be explained, preprocessed by the 'survxai::explain' function

observation

a new observation for which predictions need to be explained

grid_points

grid_points number of points used for response path

selected_variables

if specified, then only these variables will be explained

Value

An object of the class surv_ceteris_paribus_explainer. It's a data frame with calculated average responses.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
library(survxai)
library(rms)
data("pbcTrain")
data("pbcTest")
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)
cp_cph <- ceteris_paribus(surve_cph, pbcTest[1,-c(1,5)])

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