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, ...)

# Default S3 method
add_surv_prob(
  newdata,
  object,
  ci = TRUE,
  se_mult = 2,
  overwrite = FALSE,
  time_var = NULL,
  interval_length = "intlen",
  boundary = TRUE,
  ...
)

# S3 method for class 'pamm_ic'
add_surv_prob(
  newdata,
  object,
  ci = TRUE,
  alpha = 0.05,
  nsim = 500L,
  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().

...

Further arguments passed to predict.gam and get_hazard

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. Defaults to "tend".

interval_length

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

boundary

Logical. If TRUE (default), a boundary row at time = 0 with cumulative hazard 0 is prepended (per group), so that cumulative hazards start at the natural origin (consistent with add_surv_prob, add_cif and add_trans_prob).

alpha

Significance level for pooled confidence intervals.

nsim

Total number of pooled posterior draws used for the interval.

Details

When computing cumulative hazards or survival probabilities across groups, the input data must be grouped via group_by() prior to calling add_cumu_hazard() or add_surv_prob(). Omitting group_by() will not produce an error or warning but will return silently incorrect results, as the cumulative hazard will be accumulated over the entire dataset rather than within each group. See the workflow vignette for a worked example.

The returned data contains one boundary row per group at time_var = 0 for plotting cumulative quantities from the time origin. On this row, surv_prob = 1; if confidence intervals are requested, surv_lower = surv_upper = 1. If an interval-length column is present, it is set to 0 on the boundary row.

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: 23 × 9
#>    tstart  tend intlen intmid interval    age surv_prob surv_upper surv_lower
#>     <dbl> <dbl>  <dbl>  <dbl> <fct>     <dbl>     <dbl>      <dbl>      <dbl>
#>  1      0     0      0    0   NA         59.7     1          1          1    
#>  2      0    27     27   13.5 (0,27]     59.7     0.977      0.989      0.950
#>  3     27    33      6   30   (27,33]    59.7     0.972      0.987      0.939
#>  4     33    55     22   44   (33,55]    59.7     0.954      0.978      0.904
#>  5     55    62      7   58.5 (55,62]    59.7     0.949      0.976      0.893
#>  6     62   139     77  100.  (62,139]   59.7     0.896      0.946      0.803
#>  7    139   209     70  174   (139,209]  59.7     0.854      0.920      0.739
#>  8    209   214      5  212.  (209,214]  59.7     0.851      0.919      0.734
#>  9    214   257     43  236.  (214,257]  59.7     0.828      0.904      0.700
#> 10    257   304     47  280.  (257,304]  59.7     0.805      0.889      0.667
#> # ℹ 13 more rows