# Cox survival PH violated variable is part of an interaction

One of my main predictors violates the PH assumption. I've been reading different ways to deal with this for a while and have decided on an interaction with time after making a person-period file (using something like the unfold function, so a separate line for each individual for each at-risk time), as suggested by other questions on here.

Now, this fixes the PH issues in my model, but the issue I have is that this variable is also part of an interaction term with another variable. This interaction term does NOT violate the PH assumption (see this similar question of a few years ago: Violation of proportional hazard for covariate but not for interaction it's part of in a Cox Proportional Hazards model). Can I continue as planned or do I need to make a three-way interaction with var1:var2:Time? Is there any literature on this?

test2 <- coxph(Surv(Newcomers$$DurationStay, Newcomers$$Censoring) ~ Newcomers$$Gender + Newcomers$$Power + Newcomers$$Gender:Newcomers$$Power , method = "efron")
summary(test2)
print(zph <- cox.zph(test2))

chisq df       p
Newcomers$$Gender 0.93 1 0.33496 Newcomers$$Power                  14.09  1 0.00017
Newcomers$$Gender:Newcomers$$Power  5.88  1 0.01529
GLOBAL                           18.55  3 0.00034

ggcoxzph(zph)
plot(zph[2],lwd=2)
abline(0,0,col=1,lty=3,lwd=2)
abline(h=test2\$coef[2],col=3,lwd=2,lty=2)
legend("topright", legend=c('Reference line null effect', "Average hazard over time", "Time-varying hazard"), lty=c(3,2,1), col=c(1,3,1), lwd=2)


SURV2 <- survSplit(data = Newcomers, cut = c(1:135), end = "DurationStay", start = "time0", event = "Censoring")

#1-135 as the max survival time is 135. For ID with survivaltime = 3, makes 3 rows with time0 and Durationstay [0,1], [1,2], [2,3].

modelsurv3 <- coxph(Surv(time0,DurationStay,Censoring)~ Gender + Power + Power:DurationStay + Power:Gender, data=SURV2)

print(zphsurv3 <- cox.zph(modelsurv3))

chisq df    p
Gender             1.18e+00  1 0.28
Power              4.62e-02  1 0.83
Power:DurationStay 3.21e-01  1 0.57
Gender:Power       4.38e-01  1 0.51
GLOBAL             1.04e+01 17 0.89

• It's not completely clear to me which term in the model is the one that posed the problem with PH, which term represents the interaction with "time," or why the ggcoxzph output shows a value for Power:stop instead of for Power:DurationStay. Note that the plots provided by ggcoxzph, last I knew, has a serious unfixed error, which makes me wonder if the function has other problems as well. Please edit the question to provide those details and just how you coded the time interaction after using unfold; comments are easy to overlook.
– EdM
Aug 9, 2022 at 14:53
• Also, in your editing, please provide details of the package from which you obtained the unfold() function and how you invoked it. This page suggests that there can be unexpected errors.
– EdM
Aug 9, 2022 at 15:18
• @EdM Thank you for your comment, I edited my question to show more of my code. Also, I did not use unfold, as my set has no time-dependent variables I can use to unfold my set on. This way of using the cut off points was used in an article I cannot seem to find anymore. It seems to do the trick though
– KHT
Aug 12, 2022 at 8:03

First, as Power seems to be a continuous predictor, see if modeling it more flexibly, for example with a regression spline, fixes your proportional hazards (PH) problem. Mis-specification of the functional form of a continuous predictor can show up as a violation of proportional hazards. See this page, for example.

Second, make sure that your approach to setting up the time-varying covariate is OK. It seems to be similar to what's done by the tt() function in the survival package, described in Section 4.2 of the R survival time-dependence vignette. In your case you define a time-varying covariate with the Power:DurationStay product/interaction term to match the linear trend in your coefficient over time.

I would recommend, however, using the tt() function directly instead. That will correctly set up the time-varying covariate for each event time, versus just at all integer times as you do. Also, in the answer on the page you link, the recommendation was to set up the interaction with the start time rather than the stop time as you are doing. That would avoid potential problems with using values subsequent to event times to evaluate risks at any event times that occur between your integer cutoffs.

When I briefly tried to compare your approach against that used on the veteran data set in that section of the vignette I got different results, but I can't rule out some coding error on my part. For your approach you might consider splitting on the actual set of event times instead, and compare against what you get with tt().

Third, if you do use tt() note that cox.zph() can't be used on the resulting model; it used to accept such models, but it was giving incorrect results. See this answer for several issues related to time-varying covariates and coefficients.

Fourth, to answer your question, if your approach is correctly addressing the PH problem for Power, then I see no need to include an additional time-dependent interaction with Gender. It's quite possible that the moderation of the Power effect by Gender (the interaction coefficient) is constant over time even as the association between outcome and Power changes over time. That's a reasonably simple argument/explanation, although I don't have a specific literature reference on hand. I suppose it wouldn't hurt to try both, just to be sure.

• Thank you once again for your extensive and insightful reply. Your replies have proved helpful to me many many times now, thank you so much for taking time to answer!
– KHT
Aug 15, 2022 at 7:56