In Cox models with time varying coefficients, the effect of covariates on the hazard is allowed to change through time. In cases where a coefficient has a linear relationship with time, I am aware of at least two text books (this one and an Appendix to that one) that advocate for the following model, first in R code:
coxph(Surv(time, death) ~ disease + disease:time)
And now in mathematical notation: $$ h(t|X) = h_0(t) \exp(\beta_1X + \beta_2X_T) $$ Where $h(t|X)$ is the instantaneous hazard rate at time $t$ given covariates $X$; $h_0(t)$ is the baseline hazard rate; and $T$ is the censoring or event times. $\beta_1$ represents the log hazard ratio for individuals with $T=0$ (which is sort of nonsensical since you can't have $T=0$ in the data), while $\beta_2$ is harder to interpret... $\beta_2$ shows how the log hazard ratio depends on censoring/event times, but that is circular because event times are also the response variable (this point is made in Terry Therneau’s vignette “Using Time Dependent Covariates and Time Dependent Coefficients in the Cox Model”).
According to Therneau's vignette, to correctly specify a time varying coefficient, you need to use the following model, first in R code:
coxph(Surv(time, death) ~ disease + tt(disease), tt=function(x,t,...){x*t})
And now in mathematical notation: $$ h(t|X) = h_0(t) \exp(\beta_1X + \beta_2X_T) $$
The difference is that the time interaction is with $t$ in the model rather than with the event times $T$ in the data. The resulting parameters are easy to interpret: they are the intercept and slope of the linear relationship between the log hazard ratio of $X$ and time. This approach seems like the proper way to model a time varying effect.
Can anyone justify or advocate for the first approach to modeling non-proportional hazards in the Cox model? If it is really incorrect (as I suspect it is), what are the practical consequences of using this approach?
basehaz
function to deliver a baseline hazard, he use the hazard for a case with covariates at their mean value. $\endgroup$