Learn R Programming

PSsurvival (version 0.2.0)

var_marginalcox_bootstrap: Bootstrap Variance Estimation for Marginal Cox Model

Description

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.

Usage

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
)

Value

A list containing:

boot_samples

List of length B with hr_estimates from each iteration.

boot_allocation

Matrix (B x n_levels) of group sample sizes per trial.

n_used_boot

Matrix (B x n_levels) of sample sizes used in Cox model per trial (after trimming).

events_used_boot

Matrix (B x n_levels) of event counts used in Cox model per trial (after trimming).

n_success_by_group

Named integer vector of successful estimates per group (non-NA across B trials).

B

Number of bootstrap iterations.

boot_level

Bootstrap method used.

treatment_levels

Treatment levels used.

reference_level

Reference level used.

Arguments

data

A data.frame containing the complete-case analysis data.

treatment_var

Character string specifying the treatment variable name.

time_var

Character string specifying the time variable name.

event_var

Character string specifying the event variable name.

ps_formula

A formula object for the propensity score model.

treatment_levels

Vector of treatment levels (from main fit_marginal_cox).

reference_level

Reference treatment level (from main fit_marginal_cox).

estimand

Character string: "ATE", "ATT", or "overlap".

att_group

For ATT, which group to target. NULL otherwise.

trim

Trimming method: NULL, "symmetric", or "asymmetric".

delta

Symmetric trimming threshold (NULL uses defaults).

alpha

Asymmetric trimming threshold (NULL uses defaults).

boot_level

Bootstrap sampling level: "full" (default) samples from entire dataset, "strata" samples within each treatment group preserving group sizes.

B

Integer number of bootstrap iterations. Default 100.

robust

Logical. Use robust variance in Cox model? Default TRUE.

parallel

Logical. If TRUE, use parallel computation via mclapply. Default FALSE.

mc.cores

Integer number of cores for parallel processing. Default 2.

seed

Optional random seed for reproducibility. Default NULL.

Details

Bootstrap Workflow: For each bootstrap iteration:

  1. Resample data with replacement (full or stratified by treatment)

  2. Estimate propensity scores on bootstrap sample

  3. Calculate weights (with optional trimming)

  4. Fit marginal Cox model using fit_marginal_cox with functionality="boot"

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