Solved – How to assess the functional form of covariates in the Cox model with martingale residuals in R

cox-modelmartingalerresiduals

I want to find if the functional forms of covariates in my Cox model are linear. I understand the way to do this is to plot the Martingale residuals against the covariate of interest.

I have found two ways of doing this in R –

Option 1:
http://www.math.wustl.edu/~jmding/math434/R_model_diag.R

data(hodg)
fit2 = coxph(Surv(time,delta)~wtime+factor(dtype)+factor(gtype)+score, data=hodg, 
             method='breslow')
resid(fit2,type='martingale')
plot(hodg$wtime, resid(fit2), xlab="Waiting Time to Transplant (months)",
     ylab="Martingale Residuals", main='Figure 11.4 on page 361')
lines(lowess(hodg$wtime, resid(fit2)),col='red')

Option 2:
Modeling Survival Data: Extending the Cox Model

fit <- coxph(Surv(pgtime,pgstat) ~ 1, data = prostate)
plot(prostate$g2, resid(fit))
smooth <- mlowess(prostate$g2, resid(fit), iter=0)
lines(smooth)

In Option 1, the Cox model is created using all the covariates. In Option 2, the formula object in the coxph function just has ~ 1, instead of a list of covariates.

What does this ~ 1 mean, and which method should I be using?

Best Answer

Option 2, as noted by @gung, is a null model. So, unlike Option 1, it will not provide any adjustment for relations among the predictor variables. As Therneau cautions in the 1996 Technical Report Extending the Cox Model, "This method works well when the data are uncorrelated, but fails when correlations are present. The same failure occurs for ordinary scatter plots in uncensored data..." (page 19). That Report includes S-Plus code for several other ways to judge functional forms of relations of covariates to outcome, which should almost directly be useable as R code.

Related Question