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
ggcoxzph
output shows a value forPower:stop
instead of forPower:DurationStay
. Note that the plots provided byggcoxzph
, 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 usingunfold
; comments are easy to overlook. $\endgroup$unfold()
function and how you invoked it. This page suggests that there can be unexpected errors. $\endgroup$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 $\endgroup$