Given suitable data (i.e. data with all columns used for estimation of the model), this functions adds a column surv_prob containing survival probabilities for the specified covariate and follow-up information (and CIs surv_lower, surv_upper if ci=TRUE).

add_surv_prob(
  newdata,
  object,
  ci = TRUE,
  se_mult = 2,
  overwrite = FALSE,
  time_var = NULL,
  interval_length = "intlen",
  ...
)

Arguments

newdata

A data frame or list containing the values of the model covariates at which predictions are required. If this is not provided then predictions corresponding to the original data are returned. If newdata is provided then it should contain all the variables needed for prediction: a warning is generated if not. See details for use with link{linear.functional.terms}.

object

a fitted gam object as produced by gam().

ci

logical. Indicates if confidence intervals should be calculated. Defaults to TRUE.

se_mult

Factor by which standard errors are multiplied for calculating the confidence intervals.

overwrite

Should hazard columns be overwritten if already present in the data set? Defaults to FALSE. If TRUE, columns with names c("hazard", "se", "lower", "upper") will be overwritten.

time_var

Name of the variable used for the baseline hazard. If not given, defaults to "tend" for gam fits, else "interval". The latter is assumed to be a factor, the former numeric.

interval_length

The variable in newdata containing the interval lengths. Can be either bare unquoted variable name or character. Defaults to "intlen".

...

Further arguments passed to predict.gam and get_hazard

See also

predict.gam, add_surv_prob

Examples

ped <- tumor[1:50,] %>% as_ped(Surv(days, status)~ age)
pam <- mgcv::gam(ped_status ~ s(tend)+age, data=ped, family=poisson(), offset=offset)
ped_info(ped) %>% add_surv_prob(pam, ci=TRUE)
#> # A tibble: 22 × 9
#>    tstart  tend intlen intmid interval    age surv_prob surv_upper surv_lower
#>     <dbl> <dbl>  <dbl>  <dbl> <fct>     <dbl>     <dbl>      <dbl>      <dbl>
#>  1      0    27     27   13.5 (0,27]     59.7     0.977      0.989      0.950
#>  2     27    33      6   30   (27,33]    59.7     0.972      0.987      0.939
#>  3     33    55     22   44   (33,55]    59.7     0.954      0.978      0.904
#>  4     55    62      7   58.5 (55,62]    59.7     0.949      0.976      0.893
#>  5     62   139     77  100.  (62,139]   59.7     0.896      0.946      0.803
#>  6    139   209     70  174   (139,209]  59.7     0.854      0.920      0.739
#>  7    209   214      5  212.  (209,214]  59.7     0.851      0.919      0.734
#>  8    214   257     43  236.  (214,257]  59.7     0.828      0.904      0.700
#>  9    257   304     47  280.  (257,304]  59.7     0.805      0.889      0.667
#> 10    304   308      4  306   (304,308]  59.7     0.803      0.888      0.665
#> # ℹ 12 more rows