Skip to contents

Overview

This article describes the weighted Cox model estimation methodology implemented in the weightedsurv package. Weighted Cox models extend the standard Cox proportional hazards framework by incorporating time-dependent weight functions into the partial likelihood. These weights allow the analyst to emphasize treatment effects at different points on the survival distribution — for example, weighting later time-points more heavily in late-separation scenarios common in immunotherapy trials.

The methodological foundations draw on the work of Lin (1991) and Sasieni (1993) who developed the theory for weighted partial-likelihood estimation, and León et al. (2020) who proposed companion weighted Cox estimators linked to weighted log-rank combination tests.

The weightedsurv package provides a unified interface for computing weighted Cox model estimates across multiple weighting schemes, with variance estimation based on both asymptotic and synthetic-martingale resampling approaches.

Background: Non-Proportional Hazards and the Standard Cox Model

The Two-Sample Setting

Consider the standard two-sample random censorship model used in clinical trials. For i=1,…,ni = 1, \ldots, n let Zi=jZ_i = j if observation ii is from group j∈{0,1}j \in \{0, 1\} with n=n0+n1n = n_0 + n_1. Let TT denote the survival time and CC the censoring time. We observe X=min⁡(T,C)X = \min(T, C) and Δ=I(T≤C)\Delta = I(T \le C). Survival times are assumed independent of censoring conditional on treatment.

The at-risk and counting processes are Yi(t)=I(Xi≥t),Ni(t)=I(Xi≤t,Δi=1).Y_i(t) = I(X_i \ge t), \quad N_i(t) = I(X_i \le t,\, \Delta_i = 1).

The standard Cox model assumes λ(t∣Z)=λ0(t)exp⁡(βZ)\lambda(t \mid Z) = \lambda_0(t) \exp(\beta Z), yielding a constant hazard ratio exp⁡(β)\exp(\beta). The maximum partial-likelihood estimator β̂\hat{\beta} solves the score equation

U(β)=∑i=1n∫0∞{Zi−S(1)(t,β)S(0)(t,β)}dNi(t)=0,U(\beta) = \sum_{i=1}^{n} \int_0^\infty \left\{ Z_i - \frac{S^{(1)}(t, \beta)}{S^{(0)}(t, \beta)} \right\} dN_i(t) = 0,

where S(p)(t,β)=n−1∑i=1nZipYi(t)exp⁡(Ziβ)S^{(p)}(t, \beta) = n^{-1} \sum_{i=1}^{n} Z_i^p\, Y_i(t)\, \exp(Z_i \beta) for p=0,1p = 0, 1.

Why Weighted Cox Models?

Under non-proportional hazards the true model is λ(t∣Z)=λ0(t)exp⁡(β(t)Z)\lambda(t \mid Z) = \lambda_0(t) \exp(\beta(t) Z) with a time-varying coefficient β(t)\beta(t). In this case the standard Cox estimator converges to a weighted average of β(t)\beta(t) that depends on the censoring distribution, risk-set composition, and the pattern of non-proportional hazards. The resulting “average hazard ratio” may not accurately reflect the treatment effect at clinically relevant time periods.

For example, in a late-separation scenario where β(t)=0\beta(t) = 0 for t≤τcpt \le \tau_{cp} and β(t)=log⁡(θ)\beta(t) = \log(\theta) for t>τcpt > \tau_{cp}, the standard Cox estimator attenuates the true later-term effect toward the null because it gives substantial weight to the early period where there is no treatment difference.

Weighted Cox models address this by introducing a time-dependent weight function w(t)w(t) into the partial likelihood, allowing the analyst to emphasize contributions from specific time regions.

Weighted Partial Likelihood

Definition

The ww-weighted partial likelihood is

ℓw(β)=∑i=1n∫0∞w(t)βZidNi(t)−∫0∞w(t)log⁡(S(0)(t,β))∑i=1ndNi(t),\ell_w(\beta) = \sum_{i=1}^{n} \int_0^\infty w(t)\, \beta\, Z_i\, dN_i(t) - \int_0^\infty w(t) \log\!\bigl(S^{(0)}(t, \beta)\bigr) \sum_{i=1}^{n} dN_i(t),

where w(t)≥0w(t) \ge 0 is a predictable weight function. The weighted Cox estimator β̂w\hat{\beta}_w maximizes ℓw(β)\ell_w(\beta) and solves

Uw(β)=∑i=1n∫0∞w(t){Zi−S(1)(t,β)S(0)(t,β)}dNi(t)=0.U_w(\beta) = \sum_{i=1}^{n} \int_0^\infty w(t) \left\{ Z_i - \frac{S^{(1)}(t, \beta)}{S^{(0)}(t, \beta)} \right\} dN_i(t) = 0.

Note that for w(t)≡1w(t) \equiv 1 this reduces to the standard Cox score equation, and in the two-sample setting Uw(0)U_w(0) evaluated at β=0\beta = 0 is the weighted log-rank statistic.

Weighting Schemes and Their Rationale

The weightedsurv package implements several weighting schemes through the wt.rg.S() function and the cox_rhogamma() interface. Each scheme corresponds to a different emphasis on the survival time scale:

Fleming-Harrington FH(ρ\rho, γ\gamma): The weight function is w(t)=[F‾̂(t−)]ρ[1−F‾̂(t−)]γ,w(t) = \bigl[\hat{\bar{F}}(t^-)\bigr]^\rho \bigl[1 - \hat{\bar{F}}(t^-)\bigr]^\gamma, where F‾̂(t−)\hat{\bar{F}}(t^-) is the left-continuous pooled Kaplan-Meier estimator and ρ≥0\rho \ge 0, γ≥0\gamma \ge 0. The standard log-rank / Cox model corresponds to FH(0, 0). Increasing γ\gamma (with ρ=0\rho = 0) emphasizes late differences; increasing ρ\rho (with γ=0\gamma = 0) emphasizes early differences.

Magirr-Burman (MB): w(t)=1max⁡(F‾̂(t−),F‾̂(t⋆)),w(t) = \frac{1}{\max\bigl(\hat{\bar{F}}(t^-),\, \hat{\bar{F}}(t^\star)\bigr)}, which provides modest downweighting of early time-points relative to the user-specified cutoff t⋆t^\star.

Schemper: w(t)=F‾̂(t−)G‾̂(t−),w(t) = \frac{\hat{\bar{F}}(t^-)}{\hat{\bar{G}}(t^-)}, where G‾̂(t−)\hat{\bar{G}}(t^-) is the left-continuous pooled Kaplan-Meier censoring survivor function (the weight is 0 where G‾̂(t−)=0\hat{\bar{G}}(t^-) = 0). This scheme produces an “average hazard ratio” estimator that is approximately free of the censoring distribution.

Xu-O’Quigley (XO): w(t)=F‾̂(t−)Y‾(t),w(t) = \frac{\hat{\bar{F}}(t^-)}{\bar{Y}(t)}, where Y‾(t)\bar{Y}(t) is the pooled number at risk (with subject weights, the weighted number at risk; the weight is 0 where Y‾(t)=0\bar{Y}(t) = 0), which also yields a censoring-independent average hazard ratio estimator.

Custom time-based: Step-function weights of the form w(t)=w0I(t≤τ)+w1I(t>τ)w(t) = w_0\, I(t \le \tau) + w_1\, I(t > \tau), which allow the analyst to zero-out contributions before or after a pre-specified time-point.

Variance Estimation

The variance of β̂w\hat{\beta}_w is estimated through the weighted observed information and the variance of the weighted score. The weighted information is

Iw(β)=∫0∞w(t){Y‾0(t)exp⁡(β)Y‾1(t)(Y‾0(t)+exp⁡(β)Y‾1(t))2}dN‾(t),I_w(\beta) = \int_0^\infty w(t) \left\{ \frac{\bar{Y}_0(t)\, \exp(\beta)\, \bar{Y}_1(t)}{\bigl(\bar{Y}_0(t) + \exp(\beta)\, \bar{Y}_1(t)\bigr)^2} \right\} d\bar{N}(t),

and the standard error of β̂w\hat{\beta}_w is σ̂w=σ̂(Uw(β̂w))/Iw(β̂w)\hat{\sigma}_w = \hat{\sigma}(U_w(\hat{\beta}_w)) / I_w(\hat{\beta}_w). The estimate of the score variance σ̂2(Uw(β))\hat{\sigma}^2(U_w(\beta)) depends on whether there are subject-specific (case) weights.

No subject weights, or all subject weights equal. The score variance is estimated (evaluated at β̂w\hat{\beta}_w) following the martingale-based approach of Fleming and Harrington (1991):

σ̂2(Uw(β))=∫0∞{K(t,β)2Y‾0(t)+K(t,β)2exp⁡(β)Y‾1(t)}{1−ΔN‾(t)−1Y‾0(t)+exp⁡(β)Y‾1(t)−1}dN‾(t)Y‾0(t)+exp⁡(β)Y‾1(t),\hat{\sigma}^2(U_w(\beta)) = \int_0^\infty \left\{ \frac{K(t, \beta)^2}{\bar{Y}_0(t)} + \frac{K(t, \beta)^2}{\exp(\beta)\, \bar{Y}_1(t)} \right\} \left\{1 - \frac{\Delta\bar{N}(t) - 1}{\bar{Y}_0(t) + \exp(\beta)\bar{Y}_1(t) - 1} \right\} \frac{d\bar{N}(t)}{\bar{Y}_0(t) + \exp(\beta)\bar{Y}_1(t)},

where K(t,β)=w(t)Y‾0(t)exp⁡(β)Y‾1(t)/{Y‾0(t)+exp⁡(β)Y‾1(t)}K(t, \beta) = w(t)\, \bar{Y}_0(t)\, \exp(\beta)\, \bar{Y}_1(t) / \{\bar{Y}_0(t) + \exp(\beta)\, \bar{Y}_1(t)\}. At β=0\beta = 0 the score statistic and its variance reduce to the weighted log-rank statistic and its standard variance estimator.

Subject weights that are not all equal (score-residual variance). Let subject ii have time XiX_i, event indicator Δi\Delta_i, arm ZiZ_i and subject weight aia_i (for example a propensity-score weight), and write

S0(s,β)=∑jajYj(s)eβZj,z‾(s,β)=∑jajYj(s)ZjeβZjS0(s,β),dΛ̂(s,β)=∑jajΔjI(Xj=s)S0(s,β).S_0(s, \beta) = \sum_j a_j\, Y_j(s)\, e^{\beta Z_j}, \qquad \bar{z}(s, \beta) = \frac{\sum_j a_j\, Y_j(s)\, Z_j\, e^{\beta Z_j}}{S_0(s, \beta)}, \qquad d\hat{\Lambda}(s, \beta) = \frac{\sum_j a_j\, \Delta_j\, I(X_j = s)}{S_0(s, \beta)}.

The score is a sum of per-subject contributions, Uw(β)=−∑iψi(β)U_w(\beta) = -\sum_i \psi_i(\beta) in the sign convention of the package, with

ψi(β)=ai[Δiw(Xi){Zi−z‾(Xi,β)}−eβZi∑s≤Xiw(s){Zi−z‾(s,β)}dΛ̂(s,β)],\psi_i(\beta) = a_i \left[ \Delta_i\, w(X_i) \bigl\{Z_i - \bar{z}(X_i, \beta)\bigr\} - e^{\beta Z_i} \sum_{s \le X_i} w(s) \bigl\{Z_i - \bar{z}(s, \beta)\bigr\}\, d\hat{\Lambda}(s, \beta) \right],

the sum over ss running over the distinct event times. The variance of the score is estimated by the sum of squared contributions,

σ̂2(Uw(β))=∑i=1nψi(β)2.\hat{\sigma}^2(U_w(\beta)) = \sum_{i=1}^{n} \psi_i(\beta)^2 .

The weighted log-rank z-score is Uw(0)/{∑iψi(0)2}1/2U_w(0) / \{\sum_i \psi_i(0)^2\}^{1/2} and the standard error of the log hazard ratio is {∑iψi(β̂w)2}1/2/Iw(β̂w)\{\sum_i \psi_i(\hat{\beta}_w)^2\}^{1/2} / I_w(\hat{\beta}_w). For FH(0, 0) weights these are the robust score test and the robust standard error of survival::coxph(weights = , robust = TRUE, ties = "breslow"). They do not depend on how the subject weights are scaled. The point estimate, the score and the information are the same under both variance estimates.

Estimated subject weights. The formulas above treat the subject weights as fixed, known numbers (weight_variance = "known", the default). Propensity-score weights are estimated; the section “Estimated weights” below describes what weight_variance = "estimated" adds.

Synthetic-Martingale Resampling

In addition to asymptotic standard errors, weightedsurv implements synthetic-martingale resampling for variance estimation (draws > 0 in cox_rhogamma()). Without subject weights (or with all subject weights equal) the idea (Dobler et al. (2017)) is to replace the unobservable martingale increments dMidM_i with independent standard normal variates multiplied by the observable counting-process increments:

Uw†(β̂w)=∑i=1n∫0∞w(t){Zi−S(1)(t,β̂w)S(0)(t,β̂w)}GidNi(t),U_w^\dagger(\hat{\beta}_w) = \sum_{i=1}^{n} \int_0^\infty w(t) \left\{ Z_i - \frac{S^{(1)}(t, \hat{\beta}_w)}{S^{(0)}(t, \hat{\beta}_w)} \right\} G_i\, dN_i(t),

where Gi∼iidN(0,1)G_i \stackrel{\text{iid}}{\sim} N(0, 1) are independent of the data. With subject weights that are not all equal, each resampled score is built from the per-subject score contributions of the previous section,

Uw†(β̂w)=−∑i=1nGiψi(β̂w),U_w^\dagger(\hat{\beta}_w) = -\sum_{i=1}^{n} G_i\, \psi_i(\hat{\beta}_w),

so that its variance over draws is the score-residual variance and the resampling standard error estimates the same quantity as the asymptotic one.

In both cases the resampled distribution of Iw(β̂w)−1Uw†(β̂w)I_w(\hat{\beta}_w)^{-1} U_w^\dagger(\hat{\beta}_w) approximates the sampling distribution of β̂w−βw*\hat{\beta}_w - \beta_w^*. From the draws resampled values cox_rhogamma() takes the resampling standard error (their standard deviation) and a de-biased estimate (β̂w\hat{\beta}_w minus their mean); the resampling-based confidence interval (hr_ci_star) is the de-biased estimate plus and minus the normal quantile times the resampling standard error.

The same multipliers GiG_i can be used for several weighting schemes (they are generated from the same seed in every call), which preserves the correlation between the schemes; this is what is needed for simultaneous confidence intervals across multiple weighting schemes when the weighting scheme is selected via a combination test (see León et al. (2020)).

Estimated weights

Propensity-score weights are estimated from the data. ps_weights() fits a logistic regression for the treatment (or takes a fitted one) and returns an object holding the weights (inverse-probability weights, or stabilized weights with type = "stabilized"), the fitted probabilities, the influence IFiIF_i of each subject on the fitted coefficients, and the derivative dwidw_i of each subject’s weight in those coefficients.

Passed as weight_model to df_counting() with weight_variance = "estimated", the object lets the score contributions carry the estimation of the weights:

ψiew(β)=ψi(β)+IFi⊤B(β),B(β)=∑j=1nψj(β)ajdwj,σ̂2(Uw(β))=∑i=1nψiew(β)2.\psi^{ew}_i(\beta) = \psi_i(\beta) + IF_i^\top B(\beta), \qquad B(\beta) = \sum_{j=1}^{n} \frac{\psi_j(\beta)}{a_j}\, dw_j, \qquad \hat{\sigma}^2(U_w(\beta)) = \sum_{i=1}^{n} \psi^{ew}_i(\beta)^2 .

The log-rank z-score, the standard error of the log hazard ratio and the resampled scores are formed as above with ψiew\psi^{ew}_i in place of ψi\psi_i. cox_rhogamma() takes the option from the df_counting() result it is given. No estimate changes: only standard errors, intervals and tests do. The derivation and the statistical properties of this option are in the article estimated_weights_methodology (“Estimated propensity-score weights: statistical details and properties”).

Limits of this version: the model must be a logistic glm fitted on exactly the rows analysed; the dependence of the time weights w(t)w(t) on the estimated subject weights (through the weighted pooled Kaplan-Meier curve) is ignored; and the resampling-based pointwise variance of the Kaplan-Meier curves (draws > 0 in df_counting(), KM_diff() and plotKM.band_subgroups()) is not available with "estimated", while the resampling of cox_rhogamma() and the simultaneous bands (draws.band) are. Neither option repairs concentrated weights: when the effective sample size of an arm (df_counting()$ess) is a small fraction of its size, intervals and tests can be too optimistic under both. The evaluation is in the section “Simulation results by time” of the article estimated_weights_methodology.

Asymptotic Properties Under Misspecification

The Estimand: What Does β̂w\hat{\beta}_w Estimate?

Under regularity conditions (Lin (1991)), β̂w\hat{\beta}_w converges in probability to βw*\beta_w^*, the solution to uw(β)=0u_w(\beta) = 0 where

uw(β)=∫0∞w†(t){s(1)(t)s(0)(t)−s(1)(t,β)s(0)(t,β)}s(0)(t)dt,u_w(\beta) = \int_0^\infty w^\dagger(t) \left\{ \frac{s^{(1)}(t)}{s^{(0)}(t)} - \frac{s^{(1)}(t, \beta)}{s^{(0)}(t, \beta)} \right\} s^{(0)}(t)\, dt,

with w†(t)w^\dagger(t) the probability limit of w(t)w(t), and s(p)(t)=E[S(p)(t)]s^{(p)}(t) = E[S^{(p)}(t)], s(p)(t,β)=E[S(p)(t,β)]s^{(p)}(t, \beta) = E[S^{(p)}(t, \beta)].

This shows that βw*\beta_w^* is a weighted average (on the log-hazard scale) of the time-varying β(t)\beta(t), with weights determined jointly by w(t)w(t), the censoring distribution, and the risk-set dynamics.

Late-Separation Scenario

To build intuition, consider the change-point model β(t)=log⁡(θ)I(t>τcp)\beta(t) = \log(\theta)\, I(t > \tau_{cp}) with equal randomization (Pr⁡(Z=1)=1/2\Pr(Z = 1) = 1/2) and censoring independent of treatment. Then βw*\beta_w^* satisfies

0=∫0τcpw†(t){12−exp⁡(βw*)1+exp⁡(βw*)}λ0(t)G‾(t)F‾0(t)dt+∫τcp∞w†(t){exp(βw*)a(t,βw*)−θ}12λ0(t)G‾(t)F‾1(t)dt,0 = \int_0^{\tau_{cp}} w^\dagger(t) \left\{ \frac{1}{2} - \frac{\exp(\beta_w^*)}{1 + \exp(\beta_w^*)} \right\} \lambda_0(t)\, \bar{G}(t)\, \bar{F}_0(t)\, dt + \int_{\tau_{cp}}^\infty w^\dagger(t) \left\{ \exp(\beta_w^*)\, a(t, \beta_w^*) - \theta \right\} \tfrac{1}{2}\, \lambda_0(t)\, \bar{G}(t)\, \bar{F}_1(t)\, dt,

where a(t,βw*)=[F‾1(t)θ+F‾0(t)]/[F‾1(t)exp⁡(βw*)+F‾0(t)]a(t, \beta_w^*) = [\bar{F}_1(t)\, \theta + \bar{F}_0(t)] / [\bar{F}_1(t)\, \exp(\beta_w^*) + \bar{F}_0(t)].

The first integral covers the null period (t≤τcpt \le \tau_{cp}) where the contribution pushes βw*\beta_w^* toward zero; the second integral covers the treatment-effect period (t>τcpt > \tau_{cp}) and pushes βw*\beta_w^* toward log⁡(θ)\log(\theta). Weighting schemes that downweight the first integral (e.g., FH(0,1)) therefore produce estimands closer to the true treatment effect θ\theta.

Using weightedsurv for Weighted Cox Estimation

Workflow

The typical workflow for weighted Cox estimation in weightedsurv involves:

  1. Prepare a counting-process dataset via df_counting() or get_dfcounting()
  2. Fit weighted Cox models via cox_rhogamma() with the desired weighting scheme
  3. Optionally, use resampling (the draws argument) for improved inference

The df_counting() function computes risk sets, event counts, Kaplan-Meier estimates, and the specified weighting scheme. The cox_rhogamma() function then uses this counting-process representation to solve the weighted score equation.

Example: GBSG Trial Data

We illustrate using the GBSG randomized trial data available in the survival package.

library(survival)
library(weightedsurv)
if (has_tables) library(data.table)

# Prepare GBSG data
df_gbsg <- gbsg
df_gbsg$tte <- df_gbsg$rfstime / 30.4375  # Convert days to months
df_gbsg$event <- df_gbsg$status
df_gbsg$treat <- df_gbsg$hormon

tte.name <- "tte"
event.name <- "event"
treat.name <- "treat"
arms <- c("treat", "control")

Step 1: Counting-Process Dataset

The df_counting() function computes the full counting-process representation along with the specified weighting scheme:

# Standard (unweighted) analysis with FH(0,0) = standard log-rank / Cox
dfcount_gbsg <- df_counting(
  df = df_gbsg, 
  tte.name = tte.name, 
  event.name = event.name, 
  treat.name = treat.name, 
  arms = arms,
  by.risk = 12, 
  scheme = "fh", 
  scheme_params = list(rho = 0, gamma = 0)
)

Step 2: Standard Cox Model

With FH(0,0) weights the weighted Cox model reduces to the standard Cox model:

# Standard Cox via cox_rhogamma with FH(0,0)
fit_cox <- cox_rhogamma(
  dfcount = dfcount_gbsg, 
  scheme = "fh", 
  scheme_params = list(rho = 0, gamma = 0), 
  draws = 1000, 
  verbose = FALSE
)

cat("Standard Cox model\n")
## Standard Cox model
cat("  HR:", round(fit_cox$hr_ci_asy$hr, 3), "\n")
##   HR: 0.695
cat("  95% CI (asymptotic):", 
    round(fit_cox$hr_ci_asy$lower, 3), "-", 
    round(fit_cox$hr_ci_asy$upper, 3), "\n")
##   95% CI (asymptotic): 0.544 - 0.888
cat("  95% CI (resampling):", 
    round(fit_cox$hr_ci_star$lower, 3), "-", 
    round(fit_cox$hr_ci_star$upper, 3), "\n")
##   95% CI (resampling): 0.54 - 0.889
cat("  Z-score:", round(fit_cox$z.score, 3), "\n")
##   Z-score: 2.927

Step 3: Weighted Cox Models with Different Schemes

Now we fit weighted Cox models with several weighting schemes to examine how emphasis on different time regions affects the hazard ratio estimate:

# FH(0,1): Late-emphasis weighting
fit_fh01 <- cox_rhogamma(
  dfcount = dfcount_gbsg, 
  scheme = "fh", 
  scheme_params = list(rho = 0, gamma = 1), 
  draws = 1000, 
  verbose = FALSE
)

# FH(1,0): Early-emphasis weighting
fit_fh10 <- cox_rhogamma(
  dfcount = dfcount_gbsg, 
  scheme = "fh", 
  scheme_params = list(rho = 1, gamma = 0), 
  draws = 1000, 
  verbose = FALSE
)

# Magirr-Burman with 12-month cutoff
fit_mb <- cox_rhogamma(
  dfcount = dfcount_gbsg, 
  scheme = "MB", 
  scheme_params = list(mb_tstar = 12), 
  draws = 1000, 
  verbose = FALSE
)

# Custom: Zero weight before 6 months, unit weight after
fit_custom <- cox_rhogamma(
  dfcount = dfcount_gbsg, 
  scheme = "custom_time", 
  scheme_params = list(t.tau = 6, w0.tau = 0, w1.tau = 1), 
  draws = 1000, 
  verbose = FALSE
)

Comparison of Results

The table needs the data.table and gt packages.

library(gt)

results <- data.table(
  Scheme = c("FH(0,0) [Standard Cox]", "FH(0,1) [Late emphasis]", 
             "FH(1,0) [Early emphasis]", "MB(12)", "Custom 0/1 at 6 months"),
  HR = c(fit_cox$hr_ci_asy$hr, fit_fh01$hr_ci_asy$hr, 
         fit_fh10$hr_ci_asy$hr, fit_mb$hr_ci_asy$hr, fit_custom$hr_ci_asy$hr),
  Z = c(fit_cox$z.score, fit_fh01$z.score, 
        fit_fh10$z.score, fit_mb$z.score, fit_custom$z.score),
  Lower = c(fit_cox$hr_ci_star$lower, fit_fh01$hr_ci_star$lower,
            fit_fh10$hr_ci_star$lower, fit_mb$hr_ci_star$lower, fit_custom$hr_ci_star$lower),
  Upper = c(fit_cox$hr_ci_star$upper, fit_fh01$hr_ci_star$upper,
            fit_fh10$hr_ci_star$upper, fit_mb$hr_ci_star$upper, fit_custom$hr_ci_star$upper)
)

results %>% 
  gt() %>% 
  fmt_number(columns = c(HR, Z, Lower, Upper), decimals = 3) %>%
  cols_label(
    Scheme = "Weighting Scheme",
    HR = "Hazard Ratio",
    Z = "Z-score",
    Lower = "95% CI Lower",
    Upper = "95% CI Upper"
  ) %>%
  tab_header(
    title = "Weighted Cox Model Estimates: GBSG Trial",
    subtitle = "Resampling-based 95% confidence intervals (1000 draws)"
  ) %>%
  tab_footnote(
    footnote = "FH(rho, gamma) = Fleming-Harrington weights; MB = Magirr-Burman.",
    locations = cells_column_labels(columns = Scheme)
  )
Weighted Cox Model Estimates: GBSG Trial
Resampling-based 95% confidence intervals (1000 draws)
Weighting Scheme1 Hazard Ratio Z-score 95% CI Lower 95% CI Upper
FH(0,0) [Standard Cox] 0.695 2.927 0.540 0.889
FH(0,1) [Late emphasis] 0.721 2.261 0.540 0.952
FH(1,0) [Early emphasis] 0.687 2.952 0.530 0.885
MB(12) 0.696 2.918 0.541 0.890
Custom 0/1 at 6 months 0.691 2.906 0.532 0.890
1 FH(rho, gamma) = Fleming-Harrington weights; MB = Magirr-Burman.

Visualizing Weight Functions

The plot_weight_schemes() function displays the weight profiles over the event time-scale, illustrating how different schemes emphasize different regions:

g <- plot_weight_schemes(dfcount_gbsg)
print(g)

Weighted Cox with Propensity-Score Adjustment

The weightedsurv package supports subject-specific (case) weights in combination with time-dependent weighting. This is particularly useful for observational studies where propensity-score weighting is used to adjust for confounding.

The example uses the node-positive women of the Rotterdam study. With all of them, the stabilized weights are concentrated on a few treated women; the effective sample size table shows it:

fmt <- function(x, digits = 2) formatC(x, format = "f", digits = digits)

# Prepare Rotterdam data (observational study)
gbsg_validate <- within(rotterdam, {
  rfstime <- ifelse(recur == 1, rtime, dtime)
  time_months <- rfstime / 30.4375
  status2 <- ifelse(recur == 1 | (recur == 0 & death == 1 & rtime < dtime), recur, death)
  grade3 <- ifelse(grade == "3", 1, 0)
  treat <- hormon
  event <- status2
  tte <- time_months
})
# node-positive women, as in the GBSG trial
df_rotterdam_np <- subset(gbsg_validate, nodes > 0)

# Propensity score model and stabilized weights, all node-positive women
pw_np <- ps_weights(treat ~ age + meno + size + grade3 + nodes + pgr + chemo + er, 
                    data = df_rotterdam_np, type = "stabilized")
df_rotterdam_np$sw.weights <- pw_np$weights
ess_np <- get_dfcounting(
  df = df_rotterdam_np, 
  tte.name = "tte", event.name = "event", treat.name = "treat", 
  arms = arms, by.risk = 24, weight.name = "sw.weights"
)$ess
knitr::kable(ess_np, digits = c(0, 0, 1, 3))
group n ess ratio
treat 339 105.2 0.310
control 1207 1162.9 0.964

The effective sample size (∑iwi)2/∑iwi2(\sum_i w_i)^2 / \sum_i w_i^2 of the treated arm is 0.31 of its size and the largest weight is 12.9: hormonal therapy went mostly to postmenopausal women without chemotherapy (291 of the 339 treated women). The example is therefore restricted to postmenopausal women without chemotherapy, with the propensity model fitted on those rows. The standard Cox model, FH(0,0), is fitted with the weights treated as estimated; the FH(0,1) model with the weights treated as known.

df_rotterdam <- subset(df_rotterdam_np, meno == 1 & chemo == 0)

# Propensity score model and stabilized weights on the rows analysed
pw <- ps_weights(treat ~ age + size + grade3 + nodes + pgr + er, 
                 data = df_rotterdam, type = "stabilized")
df_rotterdam$sw.weights <- pw$weights

# Weighted counting-process dataset (propensity-score weighted), weights treated as estimated
dfcount_wtd <- get_dfcounting(
  df = df_rotterdam, 
  tte.name = "tte", event.name = "event", treat.name = "treat", 
  arms = arms, by.risk = 24, weight.name = "sw.weights",
  weight_variance = "estimated", weight_model = pw
)
knitr::kable(dfcount_wtd$ess, digits = c(0, 0, 1, 3))
group n ess ratio
treat 291 270.7 0.930
control 538 529.3 0.984

In the restricted population (829 women; 538 control, 291 treated) both effective sample size ratios are close to 1 and the largest weight is 2.7.

# The same dataset with the weights treated as known (the default)
dfcount_known <- get_dfcounting(
  df = df_rotterdam, 
  tte.name = "tte", event.name = "event", treat.name = "treat", 
  arms = arms, by.risk = 24, weight.name = "sw.weights"
)

# Weighted Cox models with propensity-score adjustment
# FH(0,0): weights treated as estimated, asymptotic interval
fit_ps_cox <- cox_rhogamma(dfcount = dfcount_wtd, scheme = "fh", 
                            scheme_params = list(rho = 0, gamma = 0), 
                            verbose = FALSE)

# FH(0,1): weights treated as known, resampling interval
fit_ps_fh01 <- cox_rhogamma(dfcount = dfcount_known, scheme = "fh", 
                              scheme_params = list(rho = 0, gamma = 1), 
                              draws = 1000, verbose = FALSE)

cat("Rotterdam propensity-score weighted analyses:\n")
## Rotterdam propensity-score weighted analyses:
cat("  Standard Cox HR (weights", fit_ps_cox$weight_variance, "):", round(fit_ps_cox$hr_ci_asy$hr, 3), 
    " 95% CI (asymptotic):", round(fit_ps_cox$hr_ci_asy$lower, 3), "-", 
    round(fit_ps_cox$hr_ci_asy$upper, 3), "\n")
##   Standard Cox HR (weights estimated ): 0.665  95% CI (asymptotic): 0.564 - 0.784
cat("  FH(0,1) Cox HR (weights", fit_ps_fh01$weight_variance, "):", round(fit_ps_fh01$hr_ci_asy$hr, 3), 
    " 95% CI (resampling):", round(fit_ps_fh01$hr_ci_star$lower, 3), "-", 
    round(fit_ps_fh01$hr_ci_star$upper, 3), "\n")
##   FH(0,1) Cox HR (weights known ): 0.763  95% CI (resampling): 0.623 - 0.941

Connection to Weighted Log-Rank Tests

Score-Test Equivalence

The weighted Cox score statistic evaluated at β=0\beta = 0 is algebraically equivalent to the weighted log-rank statistic. That is, Uw(0)=WKU_w(0) = W_K where

WK=∫0∞{K(t)Y‾0(t)dN‾0(t)−K(t)Y‾1(t)dN‾1(t)},W_K = \int_0^\infty \left\{ \frac{K(t)}{\bar{Y}_0(t)}\, d\bar{N}_0(t) - \frac{K(t)}{\bar{Y}_1(t)}\, d\bar{N}_1(t) \right\},

with K(t)=w(t)Y‾0(t)Y‾1(t)Y‾(t)K(t) = w(t) \frac{\bar{Y}_0(t)\, \bar{Y}_1(t)}{\bar{Y}(t)}, as score_calculation() computes it (without a factor (n0+n1)/(n0n1)\sqrt{(n_0 + n_1)/(n_0\, n_1)}). Such a constant factor would multiply the statistic and its standard error alike, so the z-statistic is unchanged by it.

This duality connects hypothesis testing (via the weighted log-rank test) and estimation (via the weighted Cox model) under the same weighting scheme, and justifies referring to the weighted Cox estimator as the “companion” to the weighted log-rank test. In weightedsurv, the check_results() function verifies this equivalence numerically.

Companion Estimators and Combination Tests

When multiple weighted log-rank tests are combined in a max-combo test Zmax=max⁡(Z1,…,Zq)Z_{\max} = \max(Z_1, \ldots, Z_q) (León et al. (2020)), the “companion” Cox estimator β̂max\hat{\beta}_{\max} is the weighted Cox estimate corresponding to the weighting scheme that yielded the largest test statistic. Since β̂max\hat{\beta}_{\max} is selected via a data-dependent process, valid inference requires simultaneous confidence intervals that hold across all qq weighting schemes.

The critical value cmaxc_{\max} is determined such that

Pr⁡{max(|β̂w1σ̂w1|,…,|β̂wqσ̂wq|)≤cmax}≈1−α,\Pr\!\left\{\max\!\left(\left|\frac{\hat{\beta}_{w_1}}{\hat{\sigma}_{w_1}}\right|, \ldots, \left|\frac{\hat{\beta}_{w_q}}{\hat{\sigma}_{w_q}}\right|\right) \le c_{\max}\right\} \approx 1 - \alpha,

which can be computed via the same synthetic-martingale resampling using common GiG_i draws across all qq weighting schemes, thereby preserving the correlation structure. cox_rhogamma() does not return cmaxc_{\max}; it returns, for each scheme, the standardized resampled values (fit_resamples$Z_bstar), which are based on the same multipliers GiG_i in every call (same seed), and cmaxc_{\max} is the 1−α1 - \alpha quantile over draws of the largest absolute value across the schemes.

Interpretation and Estimands

What Does the Weighted Hazard Ratio Mean?

Under non-proportional hazards each weighted Cox estimator converges to a different estimand exp⁡(βw*)\exp(\beta_w^*) that reflects the weighting-specific average of the time-varying hazard ratio. The following interpretive principles apply:

  • FH(0,0) (standard Cox): Estimates an overall average hazard ratio. Under proportional hazards it estimates the true constant HR.
  • FH(0, γ\gamma) with γ>0\gamma > 0 (late emphasis): Estimates a hazard ratio that more heavily reflects later-term treatment effects. Under late-separation, this is closer to the true treatment benefit after the change-point.
  • FH(ρ\rho, 0) with ρ>0\rho > 0 (early emphasis): Estimates a hazard ratio reflecting early treatment effects. Under early-separation, this captures the initial treatment benefit.
  • Schemper / XO: Estimate “average hazard ratios” that are approximately independent of the censoring distribution.

Censoring Dependence

In general, the estimand βw*\beta_w^* depends on the censoring distribution through its influence on the risk-set dynamics and the probability limit of the weights. The Schemper and XO weighting schemes were specifically designed to yield estimands that are (asymptotically) free of the censoring distribution GG. For FH weights, the degree of censoring dependence can be evaluated numerically using the limiting equation described above.

Cautions

As discussed by Hernán (2010), Aalen et al. (2015), and Stensrud et al. (2019), hazard ratios — even under randomization and ideal proportional hazards conditions — are subject to potential selection bias through temporal conditioning on risk sets. Weighted Cox estimators may further complicate these dynamics through the additional time-dependent weighting. The weighted hazard ratio should therefore be interpreted as a complementary summary of treatment effect with careful attention to what the specific weighting pattern emphasizes.

Summary

The weighted Cox model estimation framework in weightedsurv provides:

  • Flexible weighting via multiple schemes (FH, MB, Schemper, XO, custom) through a unified cox_rhogamma() interface
  • Dual inference: Both asymptotic and resampling-based standard errors and confidence intervals
  • Score-test duality: Direct connection between weighted Cox estimation and weighted log-rank testing
  • Propensity-score compatibility: Subject-specific case weights can be combined with time-dependent weighting
  • Simultaneous inference: for each scheme, cox_rhogamma() returns the standardized resampled values (fit_resamples$Z_bstar), based on the same multipliers GiG_i in every call; the critical value cmaxc_{\max} of simultaneous confidence intervals across schemes (needed when the weighting scheme is selected via a combination test) is computed from them and is not returned

The key functions are:

Function Role
df_counting() / get_dfcounting() Prepare counting-process data with weights
cox_rhogamma() Fit weighted Cox models with asymptotic and resampling inference
wt.rg.S() Compute time-dependent weight functions
plot_weight_schemes() Visualize weight profiles
check_results() Verify score-test equivalence
wlr_dhat_estimates() Weighted log-rank with survival-difference estimates

References

Aalen, Odd O., Richard J. Cook, and Kjetil Røysland. 2015. “Does Cox Analysis of a Randomized Survival Study Yield a Causal Treatment Effect?” Lifetime Data Analysis 21 (4): 579–93.
Dobler, D., J. Beyersmann, and M. Pauly. 2017. “Non-Strange Weird Resampling for Complex Survival Data.” Biometrika 104 (3): 699–711.
Fleming, T. R., and D. P. Harrington. 1991. Counting Processes and Survival Analysis. Wiley Series in Probability and Statistics. Wiley.
Hernán, Miguel A. 2010. “The Hazards of Hazard Ratios.” Epidemiology 22 (1): 13–15.
León, Larry F., Ray Lin, and Keaven M. Anderson. 2020. “On Weighted Log-Rank Combination Tests and Companion Cox Model Estimators.” Statistics in Biopharmaceutical Research 12 (4): 467–84.
Lin, D. Y. 1991. “Goodness-of-Fit Analysis for the Cox Regression Model Based on a Class of Parameter Estimators.” Journal of the American Statistical Association 86 (415): 725–28.
Sasieni, Peter. 1993. “Maximum Weighted Partial Likelihood Estimators for the Cox Model.” Journal of the American Statistical Association 88 (421): 144–52.
Stensrud, Mats J., Kjetil Røysland, and Pål C. Ryalen. 2019. “On Null Hypotheses in Survival Analysis.” Biometrics 75 (4): 1276–87.