Re: conflicting results for a time-varying coefficient in a Cox model
Dear Dr. Therneau,
Thank you very much for your exhaustive answer!
I now see the issue. Perhaps even more important was your confirmation that my approach with karno:ns(time, df=4) is theoretically correct. (I knew that plot.cox.zph is sound, so I was afraid that the difference can be attributed to some fundamental mistake in my approach.)
Thank you again,
2019. augusztus 8., 18:17:38, írtad:
This is an excellent question.
The answer, in this particular case, mostly has to do with the outlier time values. (I've never been convinced that the death at time 999 isn't really a misplaced code for "missing", actually). If you change the knots used by the spline you can get quite different values.
For instance, using a smaller data set:
fit1 <- coxph(Surv(tstart, time, status) ~ trt + prior + karno, veteran)
zph1 <- cox.zph(fit1, transform='identity')
dtime <- unique(veteran$time[veteran$status ==1]) # all of the death times
veteran2 <- survSplit( Surv(time, status) ~ ., data=veteran, cut=dtime)
fit2 <- coxph(Surv(tstart, time, status) ~ trt + prior + karno +
karno:ns(time, df=4), data=veteran2)
tx <- 0:100 * 10 # x positions for plot
ncall <- attr(terms(fit2), "predvars")[]
ty <- eval(ncall, data.frame(time = tx)) %*% coef(fit2)[4:7] + coef(fit2)
lines(tx, ty, col=2)
Now it looks even worse! The only difference is that the ns() function has chosen a different set of knots.
The test used by the cox.zph function is based on a score test and is solid. The plot that it produces uses a smoothed approximation to the variance matrix and is approximate. So the diagnostic plot will never exactly match an actual fit. In this data set the outliers exacerbate the issue. To see this try a different time scale.
The right tail is now better behaved. Eliminating the points >900 makes things even better behaved.
On 8/8/19 9:07 AM, Ferenci Tamas wrote:
I was thinking of two possible ways to
plot a time-varying coefficient in a Cox model.
One is simply to use survival::plot.cox.zph which directly produces a
beta(t) vs t diagram.
The other is to transform the dataset to counting process format and
manually include an interaction with time, expanded with spline (to be
similar to plot.cox.zph). Plotting the coefficient produces the needed
beta(t) vs t diagram.
I understand that they're slightly different approaches, so I don't
expect totally identical results, but nevertheless, they approximate
the very same thing, so I do expect that the results are more or less