residuals.coxph(object, type="martingale", collapse=F, weighted=F)This is a method for the function
residuals
for objects inheriting from class
"coxph"
.
However, as several types of residuals are available for
coxph
objects,
there is an additional optional argument
type
.
coxph
,
representing a fitted Cox regression model.
Typically this is the output from the
coxph
function.
"martingale"
,
"deviance"
,
"score"
,
"schoenfeld"
,
"dfbeta"
,
"dfbetas"
,
and
"scaledsch"
.
Only enough of the string to determine a unique match is required.
collapse=c(1,1,1, 2, 3,3, 4,4,4,4)
could be used to obtain per subject rather than per observation residuals.
TRUE
and the model was fit with case weights,
then the weighted residuals are returned.
collapse
).
For score residuals it is a matrix
with one row per subject and one column per variable.
The row order will match the input data for the original fit.
For Schoenfeld residuals, the returned object is a matrix with one row
for each event and one column per variable.
The rows are ordered by time within strata,
and an attribute
strata
is attached that contains the number of observations in each strata.
The scaled Schoenfeld residuals are used
in the
cox.zph
function.
dfbeta
is the approximate change in the
coefficient vector if that observation were dropped,
and
dfbetas
is the
approximate change in the coefficients,
scaled by the standard error for the coefficients.
For deviance residuals, the status variable may need to be reconstructed. For score and Schoenfeld residuals, the X matrix will need to be reconstructed.
Therneau, T., Grambsch, P., and Fleming. T. (1990). Martingale based residuals for survival models. Biometrika 77, 147-160.
fit <- coxph(Surv(start, stop, event) ~ (age + surgery) * transplant, data=heart) mresid <- resid(fit, collapse=heart$id)