residuals() gives one of several kinds of residuals for each row the model was fit to.
Arguments
- object
An
aft()fit.- type
The kind of residual. The default is
"martingale".- ...
Unused.
Value
A numeric vector with one value per row, or for "score", "dfbeta", and "dfbetas" a
matrix with one row per row of the data and one column per parameter.
Details
"response": the observed time minus the time predicted by the location, \(t - \gamma - \exp(\eta)\)."cox_snell": \(-\log S(t)\), the fitted cumulative hazard at the observed time."martingale": the event indicator minus the Cox-Snell residual."deviance": the signed square root of twice the gap between the row's log-likelihood and its largest possible value."score": each row's contribution to the gradient of the log-likelihood in the parameters, one column per parameter (the coefficients, the log scale, the generalized gamma's \(Q\), and the threshold)."dfbeta": the approximate change in each parameter when the row is left out, the score residuals times the variance of the parameters."dfbetas": dfbeta divided by the standard errors of the parameters.
With case weights, the score, dfbeta, and dfbetas residuals include the weights.
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 <- aft(Surv(time, status) ~ age + sex, data = lung)
residuals(fit, type = "deviance")
#> [1] -1.1363776 -0.5475019 2.3270399 -1.0311683 0.7253069 1.6346510
#> [7] -0.6457905 -0.5707988 -0.8799307 -1.3489119 -1.2277138 0.3400486
#> [13] 0.5121365 -1.9687850 0.1512311
head(residuals(fit, type = "dfbeta"))
#> (Intercept) age sex log(scale)
#> [1,] 0.7837472 -0.016881613 0.18557926 -0.002368315
#> [2,] 0.2712708 -0.006232998 0.07918672 -0.036099047
#> [3,] 1.5359219 -0.021107486 -0.04986895 0.082290216
#> [4,] -0.3795707 0.004948272 0.02020811 0.007593292
#> [5,] 0.2700656 -0.002175432 -0.05906948 -0.034099306
#> [6,] -1.4249410 0.030469559 -0.33089741 0.028805473