Skip to contents

plot_schoenfeld() checks the proportional hazards assumption of a cox_ph() fit by plotting each coefficient's scaled Schoenfeld residuals against a function of time, one panel per coefficient. Under proportional hazards the residuals scatter around the coefficient (the dashed line), and the loess smooth through them is flat. A smooth that trends shows the effect changing over time. With show_zph = TRUE, each panel also shows the p-value of its term's cox_zph() test.

Usage

plot_schoenfeld(
  fit,
  transform = c("identity", "km", "rank", "log"),
  show_zph = TRUE,
  title = NULL
)

Arguments

fit

A cox_ph() fit.

transform

The function of time on the x axis, as in cox_zph(): "identity" (the default), "km", "rank", or "log".

show_zph

Show the cox_zph() p-value of each term.

title

An optional plot title.

Value

A ggplot object.

Examples

fit <- cox_ph(Surv(time, status) ~ age + sex, data = lung)
plot_schoenfeld(fit)

plot_schoenfeld(fit, transform = "km", show_zph = FALSE)