Learn R Programming

pammtools (version 0.8.1)

add_surv_prob: Add survival probability estimates

Description

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

Usage

add_surv_prob(newdata, object, ...)

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

# S3 method for pamm_ic add_surv_prob( newdata, object, ci = TRUE, alpha = 0.05, nsim = 500L, time_var = NULL, interval_length = "intlen", check_grouping = TRUE, ... )

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

check_grouping

Logical. If TRUE (default), the function checks that newdata is grouped so that the time variable is unique within each group and stops otherwise, guarding against silently accumulating cumulative quantities across distinct covariate profiles (a forgotten group_by()). Set to FALSE to skip the check (e.g.\ for internal calls on already-validated data).

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(), so that the cumulative quantity is accumulated within each covariate profile rather than across the whole dataset. If newdata still contains several profiles per group (i.e.\ repeated time_var values within a group, typically a forgotten group_by()), the functions now stop with an error rather than returning silently incorrect results. Set check_grouping = FALSE to skip this safeguard. Note the check detects the common mis-grouping cases -- in particular any grid built with make_newdata, where profiles share time values -- but cannot catch hand-built grids that stack profiles with disjoint time grids, as these are indistinguishable from a single profile with time-varying covariates. 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

Run this code
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)

Run the code above in your browser using DataLab