[R] Why does residuals.coxph use naive.var?

Matthew Burgess matthew.s.burgess at gmail.com
Thu Mar 2 14:46:13 CET 2017

Hi all,

I noticed that the scaled Schoenfeld residuals produced by
residuals.coxph(fit, type="scaledsch") were different from those returned
by cox.zph for a model where robust standard errors have been estimated.
Looking at the source code for both functions suggests this is because
residuals.coxph uses the naive variance to scale the Schoenfeld residuals
whereas cox.zph uses the robust version when it is available.

Lines 20-21 of the version of residuals.coxph currently on github:

vv <- drop(object$naive.var)
if (is.null(vv)) vv <- drop(object$var)

i.e. the naive variance is used even when a robust version is available.

Why is this the case? Have I missed something? Am I right in thinking that
using the robust variance is the better choice if the intention is to check
the proportional hazards assumption?

Here is a reproducible example using the heart data:

fit <- coxph(Surv(start, stop, event) ~ year + age + surgery + cluster(id),
# Should return True since both produce the scaled Schoenfeld residuals
all(residuals(fit, type='scaledsch') == cox.zph(fit)$y)

Thanks for your help.

	[[alternative HTML version deleted]]

More information about the R-help mailing list