View source: R/add-functions.R
| add_cif | R Documentation |
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",
check_grouping = TRUE,
...
)
## S3 method for class 'pamm_ic'
add_cif(
newdata,
object,
ci = TRUE,
alpha = 0.05,
nsim = 500L,
cause_var = "cause",
time_var = NULL,
interval_length = "intlen",
check_grouping = TRUE,
...
)
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 |
object |
a fitted |
... |
Further arguments passed to |
ci |
|
overwrite |
Should hazard columns be overwritten if already present in
the data set? Defaults to |
alpha |
Significance level for pooled confidence intervals. |
nsim |
Total number of pooled posterior draws used for the interval. |
cause_var |
Character. Column name of the 'cause' variable. |
time_var |
Name of the variable used for the baseline hazard. Defaults
to |
interval_length |
|
check_grouping |
Logical. If |
When computing cumulative incidence for multiple groups, the input data must
be grouped via group_by() (by cause and any covariates) before calling
this function. If newdata still contains several profiles per group
(repeated time_var values within a group, typically a forgotten
group_by()), the function now stops with an error rather than
returning silently incorrect results, as the cumulative incidence would
otherwise be accumulated across profiles rather than within each group.
The returned data contains one boundary row per group at time_var = 0
for plotting cumulative incidence from the time origin. On this row,
cif = 0; if confidence intervals are requested,
cif_lower = cif_upper = 0. If an interval-length column is present,
it is set to 0 on the boundary row. add_cumu_hazard() adds an
analogous boundary row (with cumu_hazard = 0) for continuous-time
models (GAM/SCAM/PAMM), controllable via its boundary argument;
interval-factor models (e.g. PEM via glm) keep the original prediction
grid without a boundary row.
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)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.