Add cumulative incidence function to data

add_cif(newdata, object, ...)

# Default S3 method
add_cif(
  newdata,
  object,
  ci = TRUE,
  overwrite = FALSE,
  alpha = 0.05,
  nsim = 500L,
  cause_var = "cause",
  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.

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.

alpha

The alpha level for confidence/credible intervals.

nsim

Number of simulations (draws from posterior of estimated coefficients) on which estimation of CIFs and their confidence/credible intervals will be based on.

cause_var

Character. Column name of the 'cause' variable.

time_var

Name of the variable used for the baseline hazard. Defaults to "tend".

interval_length

Character, defaults to "intlen". contains the interval length in newdata.

Details

When computing cumulative incidence for multiple groups, the input data must be grouped via group_by() before calling this function. Omitting group_by() will not produce an error or warning but will return silently incorrect results, as the cumulative incidence will be accumulated over the entire dataset rather than within each group.

Examples

# \donttest{
if (require("etm")) {
  data("fourD", package = "etm")
  ped_stacked <- fourD |>
    dplyr::select(-medication, -treated) |>
    as_ped(Surv(time, status) ~., id = "id") |>
    dplyr::mutate(cause = as.factor(cause))
  pam <- pamm(
    ped_status ~ s(tend, by = cause) + sex + sex:cause + age + age:cause,
    data = ped_stacked)
  ped_stacked |>
    make_newdata(tend = unique(tend), cause = unique(cause)) |>
    group_by(cause) |>
    add_cif(pam)
}
#> Loading required package: etm
#> # A tibble: 656 × 9
#> # Groups:   cause [2]
#>       tend    id sex     age cause  intlen      cif cif_lower cif_upper
#>      <dbl> <dbl> <chr> <dbl> <fct>   <dbl>    <dbl>     <dbl>     <dbl>
#>  1 0.00821 5889. Male   65.2 1     0.00821 0.000884  0.000662   0.00116
#>  2 0.0301  5889. Male   65.2 1     0.0219  0.00324   0.00243    0.00426
#>  3 0.0520  5889. Male   65.2 1     0.0219  0.00560   0.00421    0.00734
#>  4 0.0602  5889. Male   65.2 1     0.00821 0.00648   0.00488    0.00849
#>  5 0.0684  5889. Male   65.2 1     0.00821 0.00736   0.00554    0.00965
#>  6 0.0767  5889. Male   65.2 1     0.00821 0.00824   0.00621    0.0108 
#>  7 0.110   5889. Male   65.2 1     0.0329  0.0118    0.00889    0.0154 
#>  8 0.156   5889. Male   65.2 1     0.0465  0.0168    0.0127     0.0219 
#>  9 0.164   5889. Male   65.2 1     0.00821 0.0176    0.0134     0.0230 
#> 10 0.175   5889. Male   65.2 1     0.0110  0.0188    0.0143     0.0245 
#> # ℹ 646 more rows
# }