Add IPCW weights to competing risks long-format data
Source:R/competing-risks.R
add_ipcw_weights_cr.RdEstimates the probability of remaining uncensored and appends it as column
p_notcens to the dataset. Supports two estimation strategies: a Cox
proportional hazards model (strat = "no") or non-parametric (KM) estimates
within each level of the covariate (strat = "yes").
Usage
add_ipcw_weights_cr(
data_long,
covariate = "z1",
strat = "no",
new_data = NULL,
by.start = TRUE
)Arguments
- data_long
A data frame in long format, as returned by
wide_to_long_cr(). Must contain columnststart,tstop,censor, and the covariate named bycovariate.- covariate
Character string. Name of the covariate column used to model the censoring distribution. Default is
"z1".- strat
Character.
"no"(default) fits a single Cox model for the censoring distribution usingcovariate."yes"estimates the censoring distribution non-parametrically within each stratum ofcovariate.- new_data
Optional data frame to which weights are applied. If
NULL(default), weights are computed fordata_longitself.- by.start
Logical. If
TRUE(default), the weight is P(not censored bytstart). IfFALSE, the weight is P(not censored during the interval fromtstarttotstop).
Examples
set.seed(42)
dat <- sim_data_cr(n = 100, censoring = "baseline")
dat_long <- wide_to_long_cr(dat)
dat_long <- add_ipcw_weights_cr(dat_long, strat = "no")
summary(dat_long$p_notcens)
#> Min. 1st Qu. Median Mean 3rd Qu. Max.
#> 0.0547 0.7641 0.9126 0.8413 0.9757 1.0000