plot.aggregated_surv_shap {survex}R Documentation

Plot Aggregated SurvSHAP(t) Explanations for Survival Models

Description

This functions plots objects of class aggregated_surv_shap - aggregated time-dependent explanations of survival models created using the model_survshap() function.

Usage

## S3 method for class 'aggregated_surv_shap'
plot(
  x,
  geom = "importance",
  ...,
  title = "default",
  subtitle = "default",
  max_vars = 7,
  colors = NULL
)

Arguments

x

an object of class aggregated_surv_shap to be plotted

geom

character, one of "importance", "beeswarm", "profile" or "curves". Type of chart to be plotted; "importance" shows the importance of variables over time and aggregated, "beeswarm" shows the distribution of SurvSHAP(t) values for variables and observations, "profile" shows the dependence of SurvSHAP(t) values on variable values, "curves" shows all SurvSHAP(t) curves for selected variable colored by its value or with functional boxplot if boxplot = TRUE.

...

additional parameters passed to internal functions

title

character, title of the plot

subtitle

character, subtitle of the plot, 'default' automatically generates "created for the XXX model (n = YYY)", where XXX is the explainer label and YYY is the number of observations used for calculations

max_vars

maximum number of variables to be plotted (least important variables are ignored), by default 7

colors

character vector containing the colors to be used for plotting variables (containing either hex codes "#FF69B4", or names "blue")

Value

An object of the class ggplot.

Plot options

plot.aggregated_surv_shap(geom = "importance")

plot.aggregated_surv_shap(geom = "beeswarm")

plot.aggregated_surv_shap(geom = "profile")

plot.aggregated_surv_shap(geom = "curves")

Examples


veteran <- survival::veteran
rsf_ranger <- ranger::ranger(
    survival::Surv(time, status) ~ .,
    data = veteran,
    respect.unordered.factors = TRUE,
    num.trees = 100,
    mtry = 3,
    max.depth = 5
)
rsf_ranger_exp <- explain(
    rsf_ranger,
    data = veteran[, -c(3, 4)],
    y = survival::Surv(veteran$time, veteran$status),
    verbose = FALSE
)

ranger_global_survshap <- model_survshap(
    explainer = rsf_ranger_exp,
    new_observation = veteran[
        c(1:4, 17:20, 110:113, 126:129),
        !colnames(veteran) %in% c("time", "status")
    ],
    y_true = survival::Surv(
        veteran$time[c(1:4, 17:20, 110:113, 126:129)],
        veteran$status[c(1:4, 17:20, 110:113, 126:129)]
    ),
    aggregation_method = "integral",
    calculation_method = "kernelshap",
)
plot(ranger_global_survshap)
plot(ranger_global_survshap, geom = "beeswarm")
plot(ranger_global_survshap, geom = "profile",
     variable = "age", color_variable = "karno")
plot(ranger_global_survshap, geom = "curves",
     variable = "age")
plot(ranger_global_survshap, geom = "curves",
     variable = "age", boxplot = TRUE)



[Package survex version 1.2.0 Index]