Skip to contents

cox_zph() tests whether each coefficient of a cox_ph() fit is constant over time, the assumption behind proportional hazards (Grambsch and Therneau, 1994). For each term it is the score test of adding an interaction between the term and a function \(g(t)\) of time, and the global test adds all of them at once. A small p-value suggests the term's effect changes over time.

Usage

cox_zph(fit, transform = c("km", "rank", "identity", "log"), breaks = NULL)

Arguments

fit

A cox_ph() fit.

transform

The function of time: "km" (the default), "rank", "identity", or "log".

breaks

Optional times at which to split the follow-up into windows.

Value

A cox_zph object. Its table has one row per term and a final "GLOBAL" row, with the columns term, statistic (a chi-squared statistic), df, and p_value. It also holds time and x (the event times and their transformed values) and y (the scaled Schoenfeld residuals) for plotting each term's coefficient over time, and transform. With breaks, windows is a data frame with the columns window, start, end, n_event, term, statistic, df, and p_value. as.data.frame() gives the table.

Details

The time function is set by transform: "km" (the default) uses \(1 - \hat{S}(t^-)\), one minus the Kaplan-Meier estimate of the pooled sample just before each time, "rank" uses the ranks of the times, "identity" the times themselves, and "log" their logarithms. The function is centered at its mean over the events.

With breaks, the follow-up is also split into windows at those times, and the tests are repeated within each window that holds at least 2 events. This shows where in time a departure from proportional hazards arises.

Examples

lung <- data.frame(
  time = c(306, 455, 1010, 210, 883, 1022, 310, 361, 218, 166, 170, 654, 728, 71, 567),
  status = c(2, 2, 1, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2),
  age = c(74, 68, 56, 57, 60, 74, 68, 71, 53, 61, 57, 68, 68, 60, 57),
  sex = c(1, 1, 1, 1, 1, 1, 2, 2, 1, 1, 1, 2, 2, 1, 1)
)
fit <- cox_ph(Surv(time, status) ~ age + sex, data = lung)
cox_zph(fit)
#> <cox_zph> Surv(time, status) ~ age + sex
#> Transform: km
#> 
#>        statistic df p_value
#> age        1.363  1 0.24304
#> sex        4.399  1 0.03597
#> GLOBAL     4.433  2 0.10898
cox_zph(fit, transform = "identity", breaks = 300)
#> <cox_zph> Surv(time, status) ~ age + sex
#> Transform: identity
#> 
#>        statistic df p_value
#> age       0.8558  1  0.3549
#> sex       4.0261  1  0.0448
#> GLOBAL    4.0328  2  0.1331
#> 
#> By window:
#>      window n_event   term statistic df p_value
#>    (0, 300]       5    age   0.60171  1  0.4379
#>    (0, 300]       5    sex   0.02604  1  0.8718
#>    (0, 300]       5 GLOBAL   0.71822  2  0.6983
#>  (300, Inf]       8    age   0.96831  1  0.3251
#>  (300, Inf]       8    sex   0.20844  1  0.6480
#>  (300, Inf]       8 GLOBAL   1.75264  2  0.4163