Skip to contents

plot_predicted_survival() draws one step curve per row of newdata, from any model whose predict() method gives per-subject curves as a data frame with the columns subject, time, and estimate, such as cox_ph(), survival_tree(), random_survival_forest(), royston_parmar(), or aft(). It shows how the predicted survival differs between subjects, where plot_survival() shows the curves of groups.

Usage

plot_predicted_survival(
  model,
  newdata,
  type = c("survival", "cumhaz"),
  times = NULL,
  labels = NULL,
  xlab = "Time",
  ylab = NULL
)

Arguments

model

A fitted model with per-subject survival predictions.

newdata

A data frame of the subjects to predict for.

type

"survival" (the default) or "cumhaz", passed on to predict().

times

Optional times at which to predict, passed on to predict(). Models that predict at their own event times by default don't need them.

labels

Optional labels for the subjects, one per row of newdata. The default is the row numbers.

xlab, ylab

The axis labels. The default ylab depends on type.

Value

A ggplot object.

Examples

fit <- cox_ph(Surv(time, status) ~ age + sex, data = lung)
subjects <- data.frame(age = c(50, 70, 70), sex = c(1, 1, 2))
plot_predicted_survival(fit, subjects, labels = c("50, male", "70, male", "70, female"))

plot_predicted_survival(fit, subjects, type = "cumhaz")