Skip to contents

predict() gives, for each row of newdata, the survival curve (type = "survival", the default) or the linear predictor, the predicted location of the log time (type = "lp"). With no distribution assumed for the errors, the survival curve is the Kaplan-Meier curve of the fitted residuals, moved by the subject's linear predictor: \(S(t \mid x) = \hat S_e(\log t - x^\top \hat\beta)\). It's a step function, only as reliable as the number of residuals behind it.

Usage

# S3 method for class 'buckley_james'
predict(object, newdata, type = c("survival", "lp"), times, ...)

# S3 method for class 'buckley_james'
as.data.frame(
  x,
  row.names = NULL,
  optional = FALSE,
  ...,
  conf_level = x$conf_level
)

Arguments

object, x

A buckley_james() fit.

newdata

A data frame with the covariates of the subjects to predict for. The default is the data the model was fit to.

type

What to predict: "survival" (the default) or "lp".

times

For "survival", the times to read the curves at.

...

Unused.

row.names, optional

Unused. They're part of the as.data.frame() generic.

conf_level

The confidence level. The default is the level the model was fit with.

Value

For type = "lp", a numeric vector with one value per row. For type = "survival", a data frame with the columns subject (the row of newdata), time, and estimate. as.data.frame() gives a data frame with the columns term, estimate, std_error, statistic, p_value, conf_low, and conf_high.

Details

as.data.frame() gives the coefficients, with bootstrap standard errors and Wald tests and limits when the model was fit with n_boot (NA otherwise).

Examples

lung <- data.frame(
  time = c(306, 455, 1010, 210, 883, 1022, 310, 361, 218, 166, 170, 654, 728, 71, 567, 144,
    613, 707, 61, 88),
  status = c(2, 2, 1, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 1, 2, 2, 2, 2),
  age = c(74, 68, 56, 57, 60, 74, 68, 71, 53, 61, 57, 68, 68, 60, 57, 67, 70, 63, 56, 57),
  sex = c(1, 1, 1, 1, 1, 1, 2, 2, 1, 1, 1, 2, 2, 1, 1, 1, 1, 1, 1, 1)
)
fit <- buckley_james(Surv(time, status) ~ age + sex, data = lung)
newdata <- data.frame(age = c(55, 70), sex = c(1, 2))
predict(fit, newdata = newdata, type = "survival", times = c(100, 300, 500))
#>   subject time  estimate
#> 1       1  100 0.7941176
#> 2       1  300 0.3176471
#> 3       1  500 0.1588235
#> 4       2  100 1.0000000
#> 5       2  300 0.7941176
#> 6       2  500 0.5823529
predict(fit, newdata = newdata, type = "lp")
#> [1] 5.297508 6.462999