Let’s see a Cox model:
model <- coxph(Surv(time = start, time2 = stop, event = death) ~ sex + treatment + age + year + deprivation + num_drugs + smoking_status, data = colon)
Now let’s test the assumption for the proportional hazards:
Here is the output:
We can see that sexF, year, deprivation1, num_drug20+, smoking_status1 and smoking_status 2 don’t satisfy the assumption. So we need include an interaction with time for the variables.
Here are my questions.
- For a categorical variable with ≥ 3 levels (deprivation, for example), how to know if the whole variable satisfies the proportional hazards assumption if there is only 1 level of the variable doesn’t satisfy the assumption (deprivation1).
- How to include an interaction with time for the variables? Which variable can be considered as the time variable. In SPSS, there is a auto-generated time variable T_ in the Compute Time-Dependent Covariate menu. But how can we include the interaction with time using R?