Plot 2-Dimensional Model Profile for Survival Models
Plot 2-Dimensional Model Profile for Survival Models
This function plots objects of class "model_profile_2d_survival" created using the model_profile_2d() function.
## S3 method for class 'model_profile_2d_survival'plot( x,..., variables =NULL, times =NULL, marginalize_over_time =FALSE, facet_ncol =NULL, title ="default", subtitle ="default", colors =NULL)
Arguments
x: an object of class model_profile_2d_survival to be plotted
...: additional objects of class model_profile_2d_survival to be plotted together
variables: list of character vectors of length 2, names of pairs of variables to be plotted
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.
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
facet_ncol: number of columns for arranging subplots
title: character, title of the plot. 'default' automatically generates either "2D partial dependence survival profiles" or "2D accumulated local effects survival profiles" depending on the explanation type.
subtitle: character, subtitle of the plot, 'default' automatically generates "created for the XXX model", where XXX is the explainer labels, if marginalize_over_time = FALSE, time is also added to the subtitle
colors: character vector containing the colors to be used for plotting variables (containing either hex codes "#FF69B4", or names "blue")
Returns
A collection of ggplot objects arranged with the patchwork package.
Examples
library(survival)library(survex)cph <- coxph(Surv(time, status)~ ., data = veteran, model =TRUE, x =TRUE, y =TRUE)cph_exp <- explain(cph)cph_model_profile_2d <- model_profile_2d(cph_exp, variables = list( c("age","celltype"), c("age","karno")))head(cph_model_profile_2d$result)plot(cph_model_profile_2d, variables = list(c("age","celltype")), times = cph_exp$times[20])cph_model_profile_2d_ale <- model_profile_2d(cph_exp, variables = list(c("age","karno")), type ="accumulated")head(cph_model_profile_2d_ale$result)plot(cph_model_profile_2d_ale, times = cph_exp$times[c(10,20)], marginalize_over_time =TRUE)