I am running a cox regression for survival analysis using the coxph() function in R for a very large dataset. My model is set up as:

Surv(time,event) ~ age + race + sex +...

The study period is 1 year. We found that age had a different effect in the first six months (phase 1) than it did in the last 6 months (phase 2). Age's effect being time dependent violates our PH assumption. To account for this, we thought of adding a time-dependent interaction term. The term is:

Agephase2 = (if time < 6 months ~ 0, if time >= 6 months ~ age)

The idea was to add this in the model as follows:

Surv(time,event) ~ Age + Agephase2 + race+ sex+...

Where the Age coefficient would represent the effect of age in phase 1, while Agephase2 would represent the effect of of age in phase 2. However, the output of our model is showing very large effects that are opposite than we anticipated, and the effects of all other covariates are severely altered.

Is there something wrong with this approach? How else could we account for time-dependent covariates in our model, where their effects differ in two periods? Should we just create two different models? When I researched time-dependent covariates for cox models, I didn't find much and what I did find was pretty complex.


1 Answer 1


The way to handle step changes in Cox model coefficients over time is discussed in Section 4.1 of the R time-dependence vignette. It's not immediately clear about what is wrong with your approach, but the accepted way to handle this is to reformat the data into strata based on values prior to and after 6 months, then fit a model with an interaction between the predictor of interest (age, here) and the time-group strata.

  • $\begingroup$ Thanks for pointing me to this. I restructured my data and now have the formula model <- coxph(tstart, tstop, event) ~ agegroup:strata(phase) +sex +... . One thing I noticed though is that it changed my reference group for the age categories. Do you know if there is a way to avoid this (it is a factor variable and ref group was previously defined). Also, this method doesn't use an id variable, so does this model give patients in both phases double the weight compared to patients only in phase 1? $\endgroup$
    – Matt
    Commented Apr 17, 2023 at 17:25
  • $\begingroup$ @Matt I don't know why the reference level of agegroup changed; perhaps there was some re-setting of the reference when you restructured the data. If you have actual ages those would be preferable to agegroup anyway, and you could model age with a regression spline so that the data could tell you the association between age and outcome without arbitrary boundaries between age groups. See this page and its links. $\endgroup$
    – EdM
    Commented Apr 17, 2023 at 19:44
  • $\begingroup$ I will do that, but I would like to know if I can use this method with time-dependent categorical variables, not just continuous ones. When I run the model without the interaction, my reference groups are fine. But when I add the interaction term, it changes it to the last category alphabetically (including that category in the output with all NA values, which I thought was weird since it usually excludes the reference category). Additionally, R will not let me stratify multiple variables by phase, which I wanted to do. $\endgroup$
    – Matt
    Commented Apr 17, 2023 at 23:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.