plot.predict_profile_survival {survex}R Documentation

Plot Predict Profile for Survival Models

Description

This function plots objects of class "predict_profile_survival" created using the predict_profile() function.

Usage

## S3 method for class 'predict_profile_survival'
plot(
  x,
  ...,
  geom = "time",
  variables = NULL,
  variable_type = NULL,
  facet_ncol = NULL,
  numerical_plot_type = "lines",
  times = NULL,
  marginalize_over_time = FALSE,
  title = "default",
  subtitle = "default",
  colors = NULL,
  rug = "all",
  rug_colors = c("#dd0000", "#222222")
)

Arguments

x

an object of class predict_profile_survival to be plotted

...

additional objects of class "predict_profile_survival" to be plotted together. Only available for geom = "time".

geom

character, either "time" or "variable". Selects the type of plot to be prepared. If "time" then the x-axis represents survival times, and variable is denoted by colors, if "variable" then the x-axis represents the variable values, and y-axis represents the predictions at selected time points.

variables

character, names of the variables to be plotted. When geom = "variable" it needs to be a name of a single variable, when geom = "time" it can be a vector of variable names. If NULL (default) then first variable (for geom = "variable") or all variables (for geom = "time") are plotted.

variable_type

character, either "numerical", "categorical" or NULL (default), select only one type of variable for plotting, or leave NULL for all. Only used when geom = "time".

facet_ncol

number of columns for arranging subplots. Only used when geom = "time".

numerical_plot_type

character, either "lines", or "contours" selects the type of numerical variable plots. Only used when geom = "time".

times

numeric vector, times for which the profile should be plotted, the times must be present in the 'times' field of the explainer. If NULL (default) then the median survival time (if available) or the median time from the explainer object is used. Only used when geom = "variable" and marginalize_over_time = FALSE.

marginalize_over_time

logical, if TRUE then the profile is calculated for all times and then averaged over time, if FALSE (default) then the profile is calculated for each time separately. Only used when geom = "variable".

title

character, title of the plot

subtitle

character, subtitle of the plot, 'default' automatically generates "created for XXX, YYY models", where XXX and YYY are the explainer labels

colors

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

rug

character, one of "all", "events", "censors", "none" or NULL. Which times to mark on the x axis in geom_rug().

rug_colors

character vector containing two colors (containing either hex codes "#FF69B4", or names "blue"). The first color (red by default) will be used to mark event times, whereas the second (grey by default) will be used to mark censor times.

Value

A collection of ggplot objects arranged with the patchwork package.

Examples


library(survival)
library(survex)

model <- randomForestSRC::rfsrc(Surv(time, status) ~ ., data = veteran)
exp <- explain(model)

p_profile <- predict_profile(exp, veteran[1, -c(3, 4)])

plot(p_profile)

p_profile_with_cat <- predict_profile(
    exp,
    veteran[1, -c(3, 4)],
    categorical_variables = c("trt", "prior")
)

plot(p_profile_with_cat)



[Package survex version 1.2.0 Index]