Learn R Programming

pammtools (version 0.8.1)

stop_if_undergrouped_for_cumulation: Guard against silently-wrong cumulative results from mis-grouped newdata

Description

The cumulative post-processing functions (add_cumu_hazard, add_surv_prob, add_cif, add_trans_prob) accumulate hazards over the rows of each group of newdata. If several covariate profiles (or causes / transitions) share a group -- typically a forgotten group_by() -- the accumulation silently runs across them and returns wrong curves. A correctly grouped prediction grid has a unique time_var value per group, so a duplicate within a group signals this situation. (The converse does not hold: profiles stacked with disjoint time grids have unique time_var values and pass undetected -- such input is indistinguishable from a legitimate single profile with time-varying covariates, so it cannot be guarded against. Grids built with make_newdata() always share time values across profiles and are therefore always caught.) This generalises the stopifnot() guard used for the RMST helper to the whole add_* family, turning a silent numerical error into an explicit one.

Usage

stop_if_undergrouped_for_cumulation(newdata, time_var, fun = "add_*")

Arguments