I am trying to get Schoenfeld residuals for testing data, using the model parameters obtained from training data. However in r, predict.coxph gives only the linear predictors and their exponentials. Could anyone give me some suggestion?
closed as off-topic by Michael M, kjetil b halvorsen, Michael Chernick, jbowman, Peter Flom♦ Jan 13 '18 at 14:22
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "This question appears to be off-topic because EITHER it is not about statistics, machine learning, data analysis, data mining, or data visualization, OR it focuses on programming, debugging, or performing routine operations within a statistical computing platform. If the latter, you could try the support links we maintain." – Michael M, kjetil b halvorsen, Michael Chernick, jbowman, Peter Flom
cox.zph from the
survival package in the format of:
viol <- cox.zph(cox.model)
This will give you a table of hazard assumption test results (if significant, the coefficient is time-varying). You can plot the cox.zph to plot the Schoenfeld residuals, which looks something like:
In my opinion, Yuval nails it quite well.
If you want to get the exact (scaled) Schoenfeld residuals for all covariates, access them from the viol .zph object like that:
viol$x gives you the corresponding time steps that you would need to rebuild Yuval's plot from scratch.
You can also get them out just using the residual function
residual( <coxmodel> , type = "scaledsch")