In my opinion, the heterogeneity P value is used to determine whether a variable has a differential effect on survival in the first 5 years versus the latter 5 years. But I don’t know how to calculate it.

# How to calculate the heterogeneity P value for a variable in two Cox regression models

**f2harrell**#2

It is extremely unlikely that something magical happens at exactly 5 years, so the researchers should have tested for a smooth departure from a constant hazard ratio. This is readily done with the smoothed scaled Schoenfeld residual “correlation with time” test as implemented in the R `survival`

package `cox.zph`

function. As for getting the test with the artificial dichotomization represented by the table, if we can assume conditional independence and you can the the standard errors of the log HRs, you can get the test by computing the difference in log hazard ratios divided by its standard error, where the SE is the square root of the sum of squares of the two SEs. This provides a z-test. Note that this should not be labeled ‘heterogeneity’ but instead ‘non-proportional hazards’ or ‘non-constant effect over time’.

**Lin_Caijin**#3

Thank you, professor. But I just want to know if a variable has a different effect on survival in the two dichotomized time periods. What can I do?

**f2harrell**#4

Don’t do anything until you confirm with the smooth scaled Schoenfeld residual plot that the change in effect can be well approximated by two piecewise flat relationships where the point of discontinuity happens to be at 5y. Then you can do a time-stratified analysis, i.e., two separate Cox model analyses with “fake censoring” of the first and a landmark analysis for the second where follow-up starts over at the original 5y point.

What is often better is to choose an accelerated failure time parametric survival model that makes a different assumption than proportional hazards, if its new assumptions are well-enough satisfied. And don’t discretize time.