0

I am a performing Cox regression. The output of such regression is a hazard ratio. In my case, the HR changes over time, so I want period-specific HRs in specific time intervals. I am unsure how to implement this in R. As an example:

library(survival)
library(dplyr)

fit <- coxph( Surv(time, status) ~ sex, data = lung ) %>% broom::tidy(exp=T)

Here I just obtain an overall HR, but I am interested in period-specific HRs, eg. 0-30 days, 31-365 days, 365+ days after time 0.

epiNS
  • 103

1 Answers1

0

This is perhaps the simplest case of time-dependent Cox regression coefficients. The time-dependent vignette for the R survival package shows how to do this, in Section 4.1 on "Step Functions." The trick is to start by splitting the data into each of your separate epochs, coded into the (Start,Stop,Status) form of the Surv() object, with an indicator for each of the 3 time periods. Then you fit a Cox model stratified by the time-period indicator. A stratified model calculates different regression coefficients/hazard ratios for each of the strata.

For example in your case, for an individual who survives for 500 days and then has the event, there would be 3 rows of data: one showing Start of 0 and Stop at 30 days (censored) for TimePeriod 1, another showing Start at 30 days and Stop at 365 (censored) for TimePeriod 2, and a third with Start of 365 and Stop at 500 (event) for TimePeriod 3.

In R then there are functions to turn your original data into the form required, explained in the vignette. Once the data are in the above form any survival software that allows for time-dependence and stratified models should be able to do the analysis.

EdM
  • 92,183
  • 10
  • 92
  • 267
  • Please be aware of the problems of period specific hazards, see https://thestatsgeek.com/2020/06/24/the-hazards-of-period-specific-and-weighted-hazard-ratios/ – Daniel Nov 11 '22 at 13:37
  • @Daniel thanks for the link. There certainly are dangers with period-specific hazard ratios, or period-specific covariate values more generally (as period-specific hazard ratios are effectively modeled as interactions between covariate values and functions of time). There's a big risk of survivorship bias. In your link, the problem is trying to use a Cox model when a cure model would be more appropriate, as a proportional-hazards assumption is unrealistic. It's critical to apply understanding of the subject matter in such analysis. – EdM Nov 11 '22 at 17:30