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 -
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?