Skip to contents

predict() gives, for each row of newdata (or of the data the model was fit to), the survival, hazard, or cumulative hazard curve, quantiles of the survival time, the restricted mean survival time, or the linear predictor \(x^\top \beta\).

Usage

# S3 method for class 'royston_parmar'
predict(
  object,
  newdata,
  type = c("survival", "hazard", "cumhaz", "quantile", "expectation", "lp"),
  times,
  p = 0.5,
  tau,
  conf_level = object$conf_level,
  ...
)

Arguments

object

A royston_parmar() 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), "hazard", "cumhaz", "quantile", "expectation" (the restricted mean), or "lp".

times

For "survival", "hazard", and "cumhaz", the times to read the curves at.

p

For "quantile", the proportions of subjects who have had the event, between 0 and 1. The default, 0.5, gives the median.

tau

For "expectation", the end of the window for the restricted mean.

conf_level

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

...

Unused.

Value

For "lp", a numeric vector with one value per row of newdata. Otherwise a data frame with one row per subject (and per time or proportion): subject (the row of newdata), then time, p, or tau, then estimate, std_error, conf_low, and conf_high.

Details

Standard errors use the delta method with the variance of all the parameters. The limits for survival and the cumulative hazard are built on the scale of \(\eta\), so survival stays within 0 and 1. The limits for the hazard, the quantiles, and the restricted mean are built on the log scale. A quantile is the time at which the curve reaches \(1 - p\), found by root finding on the spline within 5 units of log time beyond the boundary knots, and NA when it's not reached there. The restricted mean is \(\int_0^\tau S(t) dt\), by numerical integration.

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, 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, 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 <- royston_parmar(Surv(time, status) ~ age + sex, data = lung, df = 2)
newdata <- data.frame(age = c(55, 70), sex = c(1, 2))

predict(fit, newdata = newdata, type = "hazard", times = c(200, 400))
#>   subject time    estimate   std_error     conf_low   conf_high
#> 1       1  200 0.003518058 0.001663834 0.0013923068 0.008889371
#> 2       1  400 0.003572567 0.001450787 0.0016118145 0.007918550
#> 3       2  200 0.002073797 0.001127461 0.0007144858 0.006019202
#> 4       2  400 0.002105928 0.001090823 0.0007630281 0.005812282
predict(fit, newdata = newdata, type = "quantile", p = c(0.25, 0.5))
#>   subject    p estimate std_error  conf_low conf_high
#> 1       1 0.25 146.4901  46.85853  78.25823  274.2120
#> 2       1 0.50 262.4321  84.02552 140.11329  491.5353
#> 3       2 0.25 205.8446  77.48014  98.43424  430.4599
#> 4       2 0.50 394.8610 169.47903 170.25446  915.7777
predict(fit, newdata = newdata, type = "expectation", tau = 365)
#>   subject tau estimate std_error conf_low conf_high
#> 1       1 365 246.5947  38.09555 182.1733  333.7974
#> 2       2 365 286.0785  35.50357 224.3094  364.8573