residuals() gives the diagnostic residuals of a cox_ph() fit.
Arguments
- object
A
cox_ph()fit.- type
The type of residual. The default is
"martingale".- ...
Unused.
Value
A numeric vector for "martingale", "deviance", and "leverage", and a matrix with
one column per coefficient for the other types.
Details
"martingale": the event indicator minus the expected number of events (the subject's cumulative hazard over its follow-up). One value per row."deviance": martingale residuals transformed to be more symmetric about 0, \(\mathrm{sign}(m) \sqrt{-2 (m + \delta \log(\delta - m))}\). One value per row."score": each row's contribution to the score at the estimate. One column per coefficient."schoenfeld": at each event, the covariates minus their risk-weighted mean over the risk set. One row per event, ordered by stratum and time, with the event times as row names."scaledsch": Schoenfeld residuals scaled by the number of events times the variance, plus the coefficients. Plotted against time, each column traces the coefficient's drift over time."dfbeta": the approximate change in the coefficients when each row is left out, the weighted score residuals times the variance."dfbetas":"dfbeta"divided by the standard errors."leverage": the quadratic form of each row's score residual in the variance, a measure of its influence on the fit. One value per row.
The variance used is the model-based one, even for a fit with a robust variance.
Examples
lung <- data.frame(
time = c(306, 455, 1010, 210, 883, 1022, 310, 361, 218, 166, 170, 654, 728, 71, 567),
status = c(2, 2, 1, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2),
age = c(74, 68, 56, 57, 60, 74, 68, 71, 53, 61, 57, 68, 68, 60, 57),
sex = c(1, 1, 1, 1, 1, 1, 2, 2, 1, 1, 1, 2, 2, 1, 1)
)
fit <- cox_ph(Surv(time, status) ~ age + sex, data = lung)
residuals(fit)
#> [1] 0.6875518 0.3037075 -2.2751122 0.6490068 -0.9611647 -1.1662817
#> [7] 0.3947602 0.3442109 0.4651047 0.8607034 0.7481796 -0.2426549
#> [13] -0.4963162 0.9303265 -0.2420219
residuals(fit, type = "dfbeta")
#> age sex
#> [1,] 1.907412e-02 -0.26211735
#> [2,] 5.005056e-03 -0.05698094
#> [3,] 2.796244e-02 0.02477863
#> [4,] -5.845248e-03 -0.04056914
#> [5,] 1.576425e-03 0.19167163
#> [6,] -3.716829e-02 0.40207290
#> [7,] -1.296165e-03 0.07269671
#> [8,] 1.164577e-03 0.06967701
#> [9,] -9.671323e-03 -0.00154931
#> [10,] 1.491815e-03 -0.10141539
#> [11,] -5.923350e-03 -0.04108277
#> [12,] 9.031372e-05 -0.08150788
#> [13,] 1.747052e-04 -0.09675623
#> [14,] -6.198507e-04 -0.08546392
#> [15,] 3.984777e-03 0.00654606