Estimates variance of marginal hazard ratios via bootstrap resampling. Bootstrap Variance for Marginal Cox Model
Performs bootstrap resampling to estimate variance of log hazard ratios from weighted marginal Cox model. Supports full (unstratified) and stratified bootstrap by treatment group.
var_marginalcox_bootstrap(
data,
treatment_var,
time_var,
event_var,
ps_formula,
treatment_levels,
reference_level,
estimand = "ATE",
att_group = NULL,
trim = NULL,
delta = NULL,
alpha = NULL,
boot_level = "full",
B = 100,
robust = TRUE,
parallel = FALSE,
mc.cores = 2,
seed = NULL
)A list containing:
List of length B with hr_estimates from each iteration.
Matrix (B x n_levels) of group sample sizes per trial.
Matrix (B x n_levels) of sample sizes used in Cox model per trial (after trimming).
Matrix (B x n_levels) of event counts used in Cox model per trial (after trimming).
Named integer vector of successful estimates per group (non-NA across B trials).
Number of bootstrap iterations.
Bootstrap method used.
Treatment levels used.
Reference level used.
A data.frame containing the complete-case analysis data.
Character string specifying the treatment variable name.
Character string specifying the time variable name.
Character string specifying the event variable name.
A formula object for the propensity score model.
Vector of treatment levels (from main fit_marginal_cox).
Reference treatment level (from main fit_marginal_cox).
Character string: "ATE", "ATT", or "overlap".
For ATT, which group to target. NULL otherwise.
Trimming method: NULL, "symmetric", or "asymmetric".
Symmetric trimming threshold (NULL uses defaults).
Asymmetric trimming threshold (NULL uses defaults).
Bootstrap sampling level: "full" (default) samples from entire dataset, "strata" samples within each treatment group preserving group sizes.
Integer number of bootstrap iterations. Default 100.
Logical. Use robust variance in Cox model? Default TRUE.
Logical. If TRUE, use parallel computation via mclapply. Default FALSE.
Integer number of cores for parallel processing. Default 2.
Optional random seed for reproducibility. Default NULL.
Bootstrap Workflow: For each bootstrap iteration:
Resample data with replacement (full or stratified by treatment)
Estimate propensity scores on bootstrap sample
Calculate weights (with optional trimming)
Fit marginal Cox model using fit_marginal_cox with functionality="boot"
Record estimates, sample sizes, and event counts
Parallel Processing: Uses parallel::mclapply for parallel bootstrap. Set ncores > 1 to enable. Note: mclapply uses forking (not available on Windows).
Error Handling: Uses fit_marginal_cox(..., functionality="boot") which returns NA for failed estimates instead of throwing errors. This ensures all B trials complete.