R/plot_model_profile_survival.R
plot.model_profile_survival.Rd
This function plots objects of class "model_profile_survival"
created
using the model_profile()
function.
# S3 method for model_profile_survival
plot(
x,
...,
geom = "time",
variables = NULL,
variable_type = NULL,
facet_ncol = NULL,
numerical_plot_type = "lines",
times = NULL,
marginalize_over_time = FALSE,
plot_type = NULL,
title = "default",
subtitle = "default",
colors = NULL,
rug = "all",
rug_colors = c("#dd0000", "#222222")
)
an object of class model_profile_survival
to be plotted
additional objects of class model_profile_survival
to be plotted together. Only available for geom = "time"
.
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.
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.
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"
.
number of columns for arranging subplots. Only used when geom = "time"
.
character, either "lines"
, or "contours"
selects the type of numerical variable plots. Only used when geom = "time"
.
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
.
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"
.
character, one of "pdp"
, "ice"
, "pdp+ice"
, or NULL
(default). If NULL
then the type of plot is chosen automatically based on the number of variables to be plotted. Only used when geom = "variable"
.
character, title of the plot
character, subtitle of the plot, "default"
automatically generates "created for XXX, YYY models", where XXX and YYY are the explainer labels
character vector containing the colors to be used for plotting variables (containing either hex codes "#FF69B4", or names "blue").
character, one of "all"
, "events"
, "censors"
, "none"
or NULL
. Which times to mark on the x axis in geom_rug()
. Only used when geom = "time"
.
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.
A collection of ggplot
objects arranged with the patchwork
package.
# \donttest{
library(survival)
library(survex)
model <- randomForestSRC::rfsrc(Surv(time, status) ~ ., data = veteran)
exp <- explain(model)
#> Preparation of a new explainer is initiated
#> -> model label : rfsrc ( default )
#> -> data : 137 rows 6 cols ( extracted from the model )
#> -> target variable : 137 values ( 128 events and 9 censored , censoring rate = 0.066 ) ( extracted from the model )
#> -> times : 50 unique time points , min = 1.5 , median survival time = 80 , max = 999
#> -> times : ( generated from y as uniformly distributed survival quantiles based on Kaplan-Meier estimator )
#> -> predict function : sum over the predict_cumulative_hazard_function will be used ( default )
#> -> predict survival function : stepfun based on predict.rfsrc()$survival will be used ( default )
#> -> predict cumulative hazard function : stepfun based on predict.rfsrc()$chf will be used ( default )
#> -> model_info : package randomForestSRC , ver. 3.2.3 , task survival ( default )
#> A new explainer has been created!
m_prof <- model_profile(exp, categorical_variables = "trt")
plot(m_prof)
plot(m_prof, numerical_plot_type = "contours")
plot(m_prof, variables = c("trt", "age"), facet_ncol = 1)
plot(m_prof, geom = "variable", variables = "karno", plot_type = "pdp+ice")
#> Warning: Plot will be prepared for the median survial time. For another time point, set the value of `times`.
plot(m_prof, geom = "variable", times = exp$times[c(5, 10)],
variables = "karno", plot_type = "pdp+ice")
plot(m_prof, geom = "variable", times = exp$times[c(5, 10)],
variables = "trt", plot_type = "pdp+ice")
# }