Skip to contents

augment() adds a column of predictions, .fitted, to a data frame, and for the data the model was fit to a column of residuals, .resid.

Usage

# S3 method for class 'cox_ph'
augment(
  x,
  data = NULL,
  newdata = NULL,
  type_predict = c("lp", "risk"),
  type_residuals = c("martingale", "deviance"),
  ...
)

Arguments

x

A cox_ph() fit.

data

The data frame the model was fit to.

newdata

A data frame to predict for, instead of data.

type_predict

The prediction: "lp" (the default, the linear predictor centered at the means of the covariates) or "risk" (its exponential).

type_residuals

The residual: "martingale" (the default) or "deviance".

...

Unused.

Value

data or newdata with .fitted, and for data also .resid.

Details

With data, the rows are those the model was fit to. Rows that na.action dropped from the fit get NA, so data can be the frame that was passed to cox_ph(). With newdata, the predictions are for its rows and there are no residuals.

See also

residuals.cox_ph() and predict.cox_ph() for the other residuals and predictions.

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)
head(augment(fit, data = lung))
#>   time status age sex     .fitted     .resid
#> 1  306      2  74   1 -0.45266214  0.6875518
#> 2  455      2  68   1 -0.22992590  0.3037075
#> 3 1010      1  56   1  0.21554657 -2.2751122
#> 4  210      2  57   1  0.17842387  0.6490068
#> 5  883      2  60   1  0.06705575 -0.9611647
#> 6 1022      1  74   1 -0.45266214 -1.1662817
augment(fit, newdata = data.frame(age = c(55, 70), sex = 1), type_predict = "risk")
#>   age sex   .fitted
#> 1  55   1 1.2874574
#> 2  70   1 0.7377345