residuals_phregr | R Documentation |
Obtains the martingale, deviance, score, or Schoenfeld residuals for a proportional hazards regression model.
residuals_phregr(
fit_phregr,
type = c("martingale", "deviance", "score", "schoenfeld", "dfbeta", "dfbetas",
"scaledsch"),
collapse = FALSE,
weighted = (type %in% c("dfbeta", "dfbetas"))
)
fit_phregr |
The output from the |
type |
The type of residuals desired, with options including
|
collapse |
Whether to collapse the residuals by |
weighted |
Whether to compute weighted residuals. |
For score and Schoenfeld type residuals, the proportional hazards model
must include at least one covariate. The algorithms for deviance
,
dfbeta
, dfbetas
, and scaledsch
residuals follow
the residuals.coxph
function in the survival
package.
For martingale and deviance residuals, the result is a vector
with one element corresponding to each subject (without collapse
).
For score residuals, the result is a matrix where each row represents
a subject and each column corresponds to a variable. The row order
aligns with the input data used in the original fit. For Schoenfeld
residuals, the result is a matrix with one row for each event and
one column per variable. These rows are sorted by time within strata,
with the attributes stratum
and time
included.
Score residuals represent each individual's contribution to the score
vector. Two commonly used transformations of this are dfbeta
,
which represents the approximate change in the coefficient vector
if the observation is excluded, and dfbetas
, which gives the
approximate change in the coefficients scaled by the standard error
of the coefficients.
Kaifeng Lu, kaifenglu@gmail.com
Terry M. Therneau, Patricia M. Grambsch, and Thomas M. Fleming. Martingale based residuals for survival models. Biometrika 1990; 77:147-160.
Patricia M. Grambsch and Terry M. Therneau. Proportional hazards tests and diagnostics based on weighted residuals. Biometrika 1994; 81:515-26.
library(dplyr)
# Example 1 with right-censored data
fit1 <- phregr(data = rawdata %>% filter(iterationNumber == 1) %>%
mutate(treat = 1*(treatmentGroup == 1)),
stratum = "stratum",
time = "timeUnderObservation", event = "event",
covariates = "treat")
ressco <- residuals_phregr(fit1, type = "score")
# Example 2 with counting process data
fit2 <- phregr(data = heart %>% mutate(rx = as.numeric(transplant) - 1),
time = "start", time2 = "stop", event = "event",
covariates = c("rx", "age"), id = "id", robust = TRUE)
resssch <- residuals_phregr(fit2, type = "scaledsch")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.