weightedsurv-package: Weighted Survival Analysis Tools

weightedsurv-packageR Documentation

Weighted Survival Analysis Tools

Description

Provides functions for weighted and stratified survival analysis, including Cox proportional hazards models, weighted log-rank tests, Kaplan-Meier curves, and RMST calculations with various weighting schemes.

Main Functions

  • df_counting: Main function for weighted survival analysis

  • KM_diff: Kaplan-Meier difference calculations

  • cox_rhogamma: Weighted Cox model with flexible weights

  • plot_weight_schemes: Visualize weighting schemes

  • cumulative_rmst_bands: RMST analysis with confidence bands

Weighting Schemes

The package supports multiple weighting schemes for log-rank tests:

  • Fleming-Harrington (fh): Emphasizes early or late differences

  • Magirr-Burman (MB): Modest downweighting after cutoff time

  • Schemper: Adjusts for censoring distribution

  • Xu-O'Quigley (XO): Adjusts for risk set size

  • Custom time-based weights

Typical Workflow

  1. Prepare data with treatment (0/1), time-to-event, and event indicator

  2. Run df_counting() for comprehensive analysis

  3. Use plot_weighted_km() to visualize survival curves

  4. Calculate survival differences with KM_diff()

  5. Perform weighted Cox regression with cox_rhogamma()

  6. Compute RMST with cumulative_rmst_bands()

Key Features

  • Flexible weighting schemes for hypothesis testing

  • Resampling-based inference for improved small-sample properties

  • Simultaneous confidence bands for survival curves

  • Stratified analysis support

  • Weighted observations

  • Comprehensive diagnostic checks

Author(s)

Maintainer: Larry Leon larry.leon.05@post.harvard.edu

References

Fleming, T. R. and Harrington, D. P. (1991). Counting Processes and Survival Analysis. Wiley.

Magirr, D. and Burman, C. F. (2019). Modestly weighted logrank tests. Statistics in Medicine, 38(20), 3782-3790.

See Also

Useful links:

Examples

library(survival)
str(veteran)
veteran$treat <- as.numeric(veteran$trt) - 1

# Basic analysis
result <- df_counting(
  df = veteran,
  tte.name = "time",
  event.name = "status",
  treat.name = "treat"
)

# Plot results
plot_weighted_km(result)

# Weighted log-rank emphasizing late differences
result_fh <- df_counting(
  df = veteran,
  tte.name = "time",
  event.name = "status",
  treat.name = "treat",
  scheme = "fh",
  scheme_params = list(rho = 0, gamma = 1)
)


weightedsurv documentation built on Dec. 23, 2025, 1:07 a.m.