Skip to contents

Introduction

In clinical trials and observational studies, the Kaplan–Meier (KM) estimator is the most widely used nonparametric method for estimating survival functions from censored time-to-event data. When treatment groups are formed by randomization, the standard KM estimator provides consistent estimation of treatment-specific survival distributions. However, in observational studies—where treatment assignment may depend on baseline covariates—direct KM comparisons can be misleading due to confounding.

Inverse probability of treatment weighting (IPTW) provides a principled approach to address confounding by creating a pseudo-population in which baseline covariates are balanced across treatment groups. The weighted Kaplan–Meier estimator, constructed by applying propensity-score-derived weights to the at-risk and event counting processes, yields consistent estimation of population-level (counterfactual) survival distributions under standard causal assumptions (Cole and Hernán 2004; Austin 2014).

This article reviews the methodology underlying weighted KM estimation as implemented in the weightedsurv package, connecting the classical counting-process framework to the causal inference formulation. We draw extensively on the theoretical foundations established by Deng and Wang (2025) for the adjusted Nelson–Aalen estimator, as well as the martingale resampling approach of Dobler et al. (2017) used in weightedsurv for simultaneous confidence bands.

Notation and Setup

Observed Data

We observe nn independent subjects from two treatment groups (A=0A = 0 for control, A=1A = 1 for active treatment). For each subject ii, the observed data are (Ai,Xi,Ti,Δi)(A_i, X_i, T_i, \Delta_i), where:

  • Ai∈{0,1}A_i \in \{0, 1\}: treatment indicator,
  • XiX_i: vector of baseline covariates,
  • Ti=min⁡(T̃i,Ci)T_i = \min(\tilde{T}_i, C_i): observed follow-up time (the minimum of the event time T̃i\tilde{T}_i and censoring time CiC_i),
  • Δi=I(T̃i≤Ci)\Delta_i = I(\tilde{T}_i \leq C_i): event indicator.

Counting Process Formulation

In the counting process framework (Fleming and Harrington 1991), the individual-level processes are:

  • At-risk process: Yi(t)=I(Ti≥t)Y_i(t) = I(T_i \geq t),
  • Event counting process: Ni(t)=I(Ti≤t,Δi=1)N_i(t) = I(T_i \leq t, \Delta_i = 1).

For two groups j=0,1j = 0, 1, the aggregate processes are:

Y‾j(t)=∑i:Ai=jYi(t),N‾j(t)=∑i:Ai=jNi(t).\bar{Y}_j(t) = \sum_{i: A_i = j} Y_i(t), \qquad \bar{N}_j(t) = \sum_{i: A_i = j} N_i(t).

The Nelson–Aalen estimator of the cumulative hazard for group jj is

Λ̂j(t)=∫0tdN‾j(s)Y‾j(s),\hat{\Lambda}_j(t) = \int_0^t \frac{d\bar{N}_j(s)}{\bar{Y}_j(s)},

and the Kaplan–Meier estimator is obtained via the product-limit transformation:

Ŝj(t)=∏s≤t{1−dN‾j(s)Y‾j(s)}.\hat{S}_j(t) = \prod_{s \leq t} \left\{1 - \frac{d\bar{N}_j(s)}{\bar{Y}_j(s)}\right\}.

Under random censoring within each treatment group, both estimators are consistent for their respective group-specific survival functions.

Standard (Unweighted) Kaplan–Meier Estimator

Definition

The Kaplan–Meier estimator (Kaplan and Meier 1958) is defined at the ordered event times t1<t2<⋯t_1 < t_2 < \cdots as:

Ŝ(t)=∏tk≤t(1−dknk),\hat{S}(t) = \prod_{t_k \leq t} \left(1 - \frac{d_k}{n_k}\right),

where dkd_k denotes the number of events at time tkt_k and nkn_k is the number at risk just before tkt_k.

Martingale Representation

Under the null hypothesis of a common hazard λ(t)\lambda(t) in group jj, the counting process martingale is defined as:

Mi,j(t)=Ni,j(t)−∫0tYi,j(s)λj(s)ds,M_{i,j}(t) = N_{i,j}(t) - \int_0^t Y_{i,j}(s) \lambda_j(s)\, ds,

where Yi,j(s)=I(Ti≥s,Ai=j)Y_{i,j}(s) = I(T_i \geq s, A_i = j) and Ni,j(t)=I(Ti≤t,Δi=1,Ai=j)N_{i,j}(t) = I(T_i \leq t, \Delta_i = 1, A_i = j).

The process Mi,j(t)M_{i,j}(t) is a zero-mean martingale with respect to the natural filtration. This representation is central to deriving the variance of the KM estimator and forms the basis for the resampling methods described below.

Greenwood’s Variance Estimator

The classical variance estimator for Ŝj(t)\hat{S}_j(t) is Greenwood’s formula:

Var̂[Ŝj(t)]=Ŝj(t)2∑tk≤tdknk(nk−dk).\widehat{\text{Var}}\bigl[\hat{S}_j(t)\bigr] = \hat{S}_j(t)^2 \sum_{t_k \leq t} \frac{d_k}{n_k(n_k - d_k)}.

Causal Framework for Weighted Estimation

Potential Outcomes and Causal Estimands

Following the potential outcomes framework, let T̃a\tilde{T}^a denote the potential survival time under treatment a∈{0,1}a \in \{0,1\}. The population-level counterfactual survival function is:

Sa(t)=P(T̃a>t),S^a(t) = P(\tilde{T}^a > t),

which represents the survival probability that would be observed if the entire population were assigned treatment aa. This is the target estimand for weighted KM estimation.

Identifying Assumptions

Identification of Sa(t)S^a(t) from observed data requires the following assumptions, formalized for example by Deng and Wang (2025):

Assumption 1 (Ignorability). A⟂⟂(T̃a,C̃a)∣XA \perp\!\!\!\perp (\tilde{T}^a, \tilde{C}^a) \mid X, for a=0,1a = 0, 1. Treatment assignment is independent of the potential outcomes given baseline covariates.

Assumption 2 (Completely random censoring). C̃a⟂⟂T̃a\tilde{C}^a \perp\!\!\!\perp \tilde{T}^a, for a=0,1a = 0, 1. The censoring time is unconditionally independent of the event time. This assumption is essential for nonparametric estimation. As discussed by Deng and Wang (2025), it may be relaxed to conditional random censoring, but at the cost of requiring additional modeling of the censoring mechanism.

Assumption 3 (Positivity). 0<c<e(X)<1−c<10 < c < e(X) < 1 - c < 1 for a constant c>0c > 0, where e(X)=P(A=1∣X)e(X) = P(A = 1 \mid X) is the propensity score. Every subject has a positive probability of receiving either treatment.

Assumption 4 (Consistency). T=TA,Δ=ΔAT = T^A,\; \Delta = \Delta^A. The observed outcome equals the potential outcome corresponding to the treatment actually received.

Weighted Kaplan–Meier Estimation via IPTW

Propensity Score and IPW Weights

The propensity score e(X)=P(A=1∣X)e(X) = P(A = 1 \mid X) summarizes the covariate information relevant to treatment assignment (Rosenbaum and Rubin 1983). The inverse probability weights are defined as:

w(a;A,X)=I(A=a)e(a;X),w(a; A, X) = \frac{I(A = a)}{e(a; X)},

where e(1;X)=e(X)e(1; X) = e(X) and e(0;X)=1−e(X)e(0; X) = 1 - e(X).

Stabilized weights. To reduce variability, one commonly uses stabilized weights:

wstab(a;A,X)=P(A=a)e(a;X)⋅I(A=a),w^{\text{stab}}(a; A, X) = \frac{P(A = a)}{e(a; X)} \cdot I(A = a),

where P(A=a)P(A = a) is the marginal treatment probability. In practice, both e(X)e(X) and P(A=a)P(A = a) are estimated from the data. When stabilized weights are used, the weighted risk set at baseline equals the original sample size, which facilitates interpretation (Cole and Hernán 2004).

Weighted Counting Processes

By applying IPW weights to the individual counting processes, we construct weighted aggregate processes:

N‾jw(t)=∑i:Ai=jwi⋅Ni(t),Y‾jw(t)=∑i:Ai=jwi⋅Yi(t),\bar{N}_j^w(t) = \sum_{i: A_i = j} w_i \cdot N_i(t), \qquad \bar{Y}_j^w(t) = \sum_{i: A_i = j} w_i \cdot Y_i(t),

where wiw_i is the propensity score weight for subject ii.

Adjusted Nelson–Aalen Estimator

The adjusted Nelson–Aalen estimator for the counterfactual cumulative hazard under treatment aa is defined as (Deng and Wang 2025; Winnett and Sasieni 2002):

Λ̂a(t)=∫0t∑i=1nw(a;Ai,Xi)dNi(s)∑i=1nw(a;Ai,Xi)Yi(s).\hat{\Lambda}^a(t) = \int_0^t \frac{\sum_{i=1}^n w(a; A_i, X_i) \, dN_i(s)}{\sum_{i=1}^n w(a; A_i, X_i) \, Y_i(s)}.

This is equivalent to the standard Nelson–Aalen formula applied to the weighted counting and at-risk processes.

Weighted KM Estimator

The weighted Kaplan–Meier estimator is obtained via the product-limit:

Ŝa(t)=∏s≤t{1−dN‾aw(s)Y‾aw(s)}.\hat{S}^a(t) = \prod_{s \leq t} \left\{1 - \frac{d\bar{N}_a^w(s)}{\bar{Y}_a^w(s)}\right\}.

When there is a single terminal event (no competing risks), the weighted KM estimator and the survival function derived from the adjusted Nelson–Aalen estimator ŜNAa(t)=exp⁡{−Λ̂a(t)}\hat{S}^a_{\text{NA}}(t) = \exp\{-\hat{\Lambda}^a(t)\} are asymptotically equivalent (Deng and Wang 2025).

Practical Weight Computation

In the weightedsurv package, ps_weights() computes propensity score weights from a logistic model for the treatment: inverse probability weights (type = "ipw", the default) or stabilized weights (type = "stabilized", used in the weightedsurv_examples vignette). The recipe for stabilized weights, following Cole and Hernán (2004), is:

  1. Fit a propensity score model: ê(Xi)=expit(β̂TXi)\hat{e}(X_i) = \text{expit}(\hat{\beta}^T X_i) via logistic regression.
  2. Compute the marginal probability: P̂(A=1)=π̂null\hat{P}(A = 1) = \hat{\pi}_{\text{null}} from an intercept-only model.
  3. Calculate stabilized weights: wi={π̂null/ê(Xi)if Ai=1,(1−π̂null)/(1−ê(Xi))if Ai=0.w_i = \begin{cases} \hat{\pi}_{\text{null}} / \hat{e}(X_i) & \text{if } A_i = 1, \\ (1 - \hat{\pi}_{\text{null}}) / (1 - \hat{e}(X_i)) & \text{if } A_i = 0. \end{cases}
  4. (Optional) Truncate extreme weights to reduce variance, for example at the 5th and 95th percentiles.

Step 4 describes common practice, not the package: weightedsurv never truncates or rescales weights. ps_weights() returns the weights of steps 1–3 as computed (it takes the marginal probability in step 2 as the proportion treated), and every analysis function uses the weight column it is given.

Asymptotic Theory

Known Propensity Score

When the propensity score e(X)e(X) is known (as in a randomized trial with known allocation probabilities), Deng and Wang (2025) show that the weighted counting process admits a martingale decomposition. Specifically, for each subject ii in treatment group aa:

w(a;Ai,Xi)dNi(t)=w(a;Ai,Xi)Yi(t)dΛa(t)+w(a;Ai,Xi)dMia(t),w(a; A_i, X_i) \, dN_i(t) = w(a; A_i, X_i) \, Y_i(t) \, d\Lambda^a(t) + w(a; A_i, X_i) \, dM_i^a(t),

where Mia(t)M_i^a(t) is a martingale. This yields the finite-sample unbiasedness of dΛ̂a(t)d\hat{\Lambda}^a(t) for dΛa(t)d\Lambda^a(t).

The variance of Λ̂a(t)\hat{\Lambda}^a(t) follows from martingale theory:

Var[Λ̂a(t)]≈∫0tE[w(a;A,X)2Y(s)dΛa(s)](E[w(a;A,X)Y(s)])2.\text{Var}\bigl[\hat{\Lambda}^a(t)\bigr] \approx \int_0^t \frac{E\bigl[w(a; A, X)^2 \, Y(s) \, d\Lambda^a(s)\bigr]}{\bigl(E\bigl[w(a; A, X) \, Y(s)\bigr]\bigr)^2}.

Estimated Propensity Score

In practice, the propensity score is unknown and must be estimated. A key contribution of Deng and Wang (2025) is deriving the influence function for Λ̂a(t)\hat{\Lambda}^a(t) when using an estimated propensity score ê(X)\hat{e}(X). If the estimated propensity score is regular and asymptotically linear (RAL), the additional variance term due to propensity score estimation can be characterized.

The influence function of Λ̂a(t)\hat{\Lambda}^a(t) decomposes as:

n(Λ̂a(t)−Λa(t))=1n∑i=1nψia(t)+op(1),\sqrt{n}\bigl(\hat{\Lambda}^a(t) - \Lambda^a(t)\bigr) = \frac{1}{\sqrt{n}} \sum_{i=1}^n \psi_i^a(t) + o_p(1),

where ψia(t)\psi_i^a(t) is the influence function that incorporates both the martingale term (from the counting process) and the correction term (from estimating e(X)e(X)).

In weightedsurv the argument weight_variance says which of the two terms enter the standard errors, intervals, bands and tests. With weight_variance = "known" (the default) the weights are treated as fixed, known numbers and only the first term is used. With weight_variance = "estimated" the correction term for a logistic propensity model is added, from the object returned by ps_weights() (formulas in the next section). No estimate differs between the two options. How the two behave (coverage, test size, interval length) was evaluated by simulation for this version of the package; the results are in the section “Simulation results by time” of the article estimated_weights_methodology.

Variance Estimation in weightedsurv

No weights, or all weights equal. The variance of Ŝa(t)\hat{S}^a(t) is Greenwood’s formula.

Weights that are not all equal: robust variance. The variance is the robust (infinitesimal-jackknife) variance. With TiT_i, Δi\Delta_i and wiw_i the time, event indicator and weight of subject ii in group aa, and the weighted risk set Y‾aw(s)\bar{Y}_a^w(s) and weighted event count dN‾aw(s)d\bar{N}_a^w(s) defined above,

Var̂[Ŝa(t)]=Ŝa(t)2∑i:Ai=awi2ψi(t)2,ψi(t)=ΔiI(Ti≤t)Y‾aw(Ti)−dN‾aw(Ti)−∑s≤min⁡(t,Ti)dN‾aw(s)Y‾aw(s){Y‾aw(s)−dN‾aw(s)},\widehat{\text{Var}}\bigl[\hat{S}^a(t)\bigr] = \hat{S}^a(t)^2 \sum_{i: A_i = a} w_i^2\, \psi_i(t)^2, \qquad \psi_i(t) = \frac{\Delta_i\, I(T_i \leq t)}{\bar{Y}_a^w(T_i) - d\bar{N}_a^w(T_i)} - \sum_{s \leq \min(t,\, T_i)} \frac{d\bar{N}_a^w(s)}{\bar{Y}_a^w(s)\bigl\{\bar{Y}_a^w(s) - d\bar{N}_a^w(s)\bigr\}},

where the sum runs over the event times of the group and a term is 0 when Y‾aw(s)=0\bar{Y}_a^w(s) = 0 or Y‾aw(s)−dN‾aw(s)≤10−10Y‾aw(s)\bar{Y}_a^w(s) - d\bar{N}_a^w(s) \leq 10^{-10}\, \bar{Y}_a^w(s). ψi(t)\psi_i(t) is subject ii’s influence contribution to the curve. The resulting standard error equals that of survival::survfit(weights = w, robust = TRUE) and reduces to Greenwood’s formula when all weights are equal. It does not depend on the scale of the weights (wiw_i and cwic\, w_i give the same value), so the weights are not frequency weights: a weight of 2 is not two copies of the row. The weights are treated as fixed and known.

Estimated weights. ps_weights() fits a logistic regression for the treatment (or takes a fitted one) and returns an object with the weights, the fitted probabilities êi\hat{e}_i, and two matrices with one row per subject: the influence IFiIF_i of subject ii on the fitted coefficients and the derivative dwidw_i of the subject’s weight in the coefficients,

IFi={∑jxjxj⊤êj(1−êj)}−1xi(Ai−êi),dwi=−1−êiêixi(Ai=1),dwi=êi1−êixi(Ai=0),IF_i = \Bigl\{\sum_j x_j x_j^\top\, \hat{e}_j (1 - \hat{e}_j)\Bigr\}^{-1} x_i\, (A_i - \hat{e}_i), \qquad dw_i = -\frac{1 - \hat{e}_i}{\hat{e}_i}\, x_i \ \ (A_i = 1), \qquad dw_i = \frac{\hat{e}_i}{1 - \hat{e}_i}\, x_i \ \ (A_i = 0),

with xix_i the row of the model matrix (for stabilized weights wiw_i and dwidw_i are multiplied by the arm proportion, which is treated as a fixed number). Passed as weight_model with weight_variance = "estimated" to df_counting(), KM_diff(), plotKM.band_subgroups() or cumulative_rmst_bands(), it adds to each subject’s contribution the term through the propensity model:

Da(t)=∑k:Ak=aψk(t)dwk,Φia(t)=I(Ai=a)wiψi(t)+IFi⊤Da(t)(i=1,…,n),Var̂[Ŝa(t)]=Ŝa(t)2∑i=1nΦia(t)2.D_a(t) = \sum_{k: A_k = a} \psi_k(t)\, dw_k, \qquad \Phi_i^a(t) = I(A_i = a)\, w_i\, \psi_i(t) + IF_i^\top D_a(t) \quad (i = 1, \ldots, n), \qquad \widehat{\text{Var}}\bigl[\hat{S}^a(t)\bigr] = \hat{S}^a(t)^2 \sum_{i=1}^{n} \Phi_i^a(t)^2 .

Every subject contributes, also those in the other arm, through the model. "estimated" needs a logistic glm fitted on exactly the rows analysed, with the weight column equal to the weights of the object. The derivation and the statistical properties of this option are in the article estimated_weights_methodology (“Estimated propensity-score weights: statistical details and properties”).

Resampling variance. With draws > 0 and weights that are not all equal, the pointwise variance is instead the variance over draws resampling draws of Ŝa(t)∑iGiwiψi(t)\hat{S}^a(t) \sum_i G_i\, w_i\, \psi_i(t), with standard normal multipliers GiG_i; it estimates the same quantity as the robust variance. This resampling-based pointwise variance is not available with weight_variance = "estimated" (draws must be 0); the simultaneous bands described below (draws.band) are.

With concentrated weights (a low effective sample size, df_counting()$ess) the standard error can be too small under either option.

Inference for Survival Differences

Pointwise Confidence Intervals

For comparing two treatment groups, the survival difference Δ(t)=S1(t)−S0(t)\Delta(t) = S^1(t) - S^0(t) is estimated by Δ̂(t)=Ŝ1(t)−Ŝ0(t)\hat{\Delta}(t) = \hat{S}^1(t) - \hat{S}^0(t). Pointwise confidence intervals are constructed as:

Δ̂(t)±zα/2⋅sê[Δ̂(t)].\hat{\Delta}(t) \pm z_{\alpha/2} \cdot \widehat{\text{se}}\bigl[\hat{\Delta}(t)\bigr].

Without weights, and with weights treated as known, the variance of the difference is the sum of the variances of Ŝ1(t)\hat{S}^1(t) and Ŝ0(t)\hat{S}^0(t) given above. With weight_variance = "estimated" it is not the sum of the two arm variances, because the two arms share the coefficients of the propensity model:

Var̂[Δ̂(t)]=∑i=1n{Ŝ1(t)Φi1(t)−Ŝ0(t)Φi0(t)}2.\widehat{\text{Var}}\bigl[\hat{\Delta}(t)\bigr] = \sum_{i=1}^{n} \bigl\{\hat{S}^1(t)\, \Phi_i^1(t) - \hat{S}^0(t)\, \Phi_i^0(t)\bigr\}^2 .

Simultaneous Confidence Bands via Martingale Resampling

Pointwise confidence intervals provide valid inference at any single time point, but the survival difference Δ̂(t)\hat{\Delta}(t) is evaluated across a range of time points tt. Simultaneous confidence bands guarantee coverage uniformly over an interval of time.

The weightedsurv package implements simultaneous confidence bands using the martingale resampling approach of Dobler et al. (2017).

Martingale Resampling Principle

The key idea is to approximate the distribution of the centered process

Δ̂(t)−Δ(t)\hat{\Delta}(t) - \Delta(t)

over the time range of the analysis by generating resampled versions of the process, conditionally on the observed data, with independent standard normal variates GiG_i (one per subject, independent of the data) in the role of the unobservable martingale increments. Unknown quantities are replaced by their estimates (“plug-in”).

No weights, or all weights equal. The multipliers perturb the observable counting process increments. The resampled deviation of the curve of group jj is

Ŝj*(t)−Ŝj(t)=−Ŝj(t)∑i:Ai=jGi∫0tdNi(s)Y‾j(s),\hat{S}_j^{*}(t) - \hat{S}_j(t) = -\hat{S}_j(t) \sum_{i: A_i = j} G_i \int_0^t \frac{dN_i(s)}{\bar{Y}_j(s)},

so that the increments dNi(s)dN_i(s) serve as proxies for the martingale increments.

Weights that are not all equal. The resampled deviation is built from the influence contributions ψi(t)\psi_i(t) of the robust variance (section “Variance Estimation in weightedsurv”):

Ŝj*(t)−Ŝj(t)=−Ŝj(t)∑i:Ai=jGiwiψi(t),\hat{S}_j^{*}(t) - \hat{S}_j(t) = -\hat{S}_j(t) \sum_{i: A_i = j} G_i\, w_i\, \psi_i(t),

whose variance over draws is the robust variance. With weight_variance = "estimated" the sum runs over all nn subjects with Φij(t)\Phi_i^j(t) in place of wiψi(t)w_i\, \psi_i(t), so that the resampled curves carry the estimation of the weights.

In every case the resampled difference is Δ̂*(t)={Ŝ1*(t)−Ŝ1(t)}−{Ŝ0*(t)−Ŝ0(t)}\hat{\Delta}^{*}(t) = \{\hat{S}_1^{*}(t) - \hat{S}_1(t)\} - \{\hat{S}_0^{*}(t) - \hat{S}_0(t)\}, a draw of the centered process.

Algorithm

The procedure, as implemented in plotKM.band_subgroups and KM_diff, proceeds as follows:

  1. Compute the observed survival difference Δ̂(t)\hat{\Delta}(t) and its standard error sê[Δ̂(t)]\widehat{\text{se}}[\hat{\Delta}(t)] at each time point of the grid. In plotKM.band_subgroups the grid holds every observed time up to the smaller of the two arms’ last event times (Maxtau replaces that limit when supplied, and tau_add extends it when later), so the band covers the whole range as called. No quantile range is trimmed: qtau has an effect only with modify_tau = TRUE, in which case the grid is a regular sequence between the qtau and 1 - qtau quantiles of the event times (together with the risk-table time points up to the upper quantile).
  2. For b=1,…,Bb = 1, \ldots, B resamples (draws.band):
    1. Generate nn independent N(0,1)N(0,1) variates {Gi(b)}\{G_i^{(b)}\}.
    2. Compute the resampled centered difference Δ̂*(b)(t)\hat{\Delta}^{*(b)}(t) as described above.
  3. For each resample bb, compute the supremum of the standardized process, sup⁡t|Δ̂*(b)(t)|/sê[Δ̂(t)]\sup_t |\hat{\Delta}^{*(b)}(t)| / \widehat{\text{se}}[\hat{\Delta}(t)].
  4. The (1−α)(1-\alpha) simultaneous band is: Δ̂(t)±c1−α⋅sê[Δ̂(t)],\hat{\Delta}(t) \pm c_{1-\alpha} \cdot \widehat{\text{se}}\bigl[\hat{\Delta}(t)\bigr], where c1−αc_{1-\alpha} is the (1−α)(1-\alpha) quantile of the suprema in step 3 over the BB resamples. The band is therefore wider where the standard error is larger.

Extension to Weighted Setting

The resampling framework accommodates IPTW weights. In the weighted case (weights not all equal) the resampled curves are built from the per-subject influence contributions, as described above, and the band is standardized by the robust standard error; with weight_variance = "estimated" both carry the estimation of the weights. This is operationally handled in weightedsurv by passing a weight.name argument (and, for estimated weights, weight_variance and weight_model) to the relevant functions (e.g., plotKM.band_subgroups, KM_diff, cumulative_rmst_bands).

Cumulative RMST Inference

RMST Definition

The restricted mean survival time (RMST) up to a truncation time τ\tau is defined as:

μa(τ)=∫0τSa(t)dt=E[min⁡(T̃a,τ)].\mu^a(\tau) = \int_0^{\tau} S^a(t)\, dt = E\bigl[\min(\tilde{T}^a, \tau)\bigr].

The RMST difference μ1(τ)−μ0(τ)\mu^1(\tau) - \mu^0(\tau) is an interpretable, model-free summary of the treatment effect (Uno et al. 2014).

Cumulative RMST Curves

Rather than evaluating the RMST at a single τ\tau, the cumulative_rmst_bands function in weightedsurv computes μ̂1(τ)−μ̂0(τ)\hat{\mu}^1(\tau) - \hat{\mu}^0(\tau) as a function of τ\tau across the entire follow-up range. This provides a “cumulative RMST curve” that reveals how the treatment benefit (or harm) accumulates over time.

Simultaneous confidence bands for the RMST difference curve are obtained by the same martingale resampling approach, applied to the integrated survival difference process.

Relationship to the Adjusted Nelson–Aalen Estimator

As formalized by Deng and Wang (2025), the adjusted Nelson–Aalen estimator and the weighted KM estimator are asymptotically equivalent for a single terminal event. The Nelson–Aalen approach avoids product limits in the estimator and connects directly to the hazard-based identification results. The weightedsurv package works primarily with the product-limit (KM) form, which is more commonly used in clinical practice and has the natural interpretation as an estimated probability.

Weighted Risk Set Estimators

An alternative approach to estimating treatment-specific survival distributions from sequential randomization designs was proposed by Guo and Tsiatis (2005). The weighted risk set (WRS) estimator uses inverse probability weights within the risk sets of a Nelson–Aalen-type estimator. Miyahara and Wahed (2010) proposed weighted KM estimators (with both fixed and time-dependent weights) for two-stage treatment regimes and showed that both forms are asymptotically unbiased.

These WRS and WKM estimators share the same fundamental structure as the IPTW KM estimator: weight each subject’s contribution to the risk set and event count by an inverse probability weight reflecting the probability of following the treatment regime of interest.

Doubly-Robust Estimators

Bai et al. (2013) developed doubly-robust estimators for treatment-specific survival distributions that are consistent if either the propensity score model or a model for the survival distribution as a function of covariates is correctly specified. These augmented IPTW estimators can achieve greater efficiency than pure IPTW methods. While the current weightedsurv implementation focuses on IPTW, the counting-process infrastructure is amenable to such extensions.

Covariate-Adjusted Log-Rank Tests

In the randomized trial setting, Ye et al. (2024) developed covariate-adjusted log-rank tests with guaranteed efficiency gains over the unadjusted test. A key result is the universal applicability of their method to different randomization schemes (simple randomization, stratified permuted block, Pocock–Simon minimization). The weighted log-rank statistics in weightedsurv are complementary: while the package’s Fleming–Harrington class statistics target non-proportional hazards alternatives, the covariate-adjusted framework of Ye et al. (2024) targets efficiency gains through covariate adjustment under any hazard structure.

Adjusted Nelson–Aalen with Retrospective Matching

Winnett and Sasieni (2002) developed a weighted Nelson–Aalen estimator for retrospectively matched data, with stratum-specific random effects. Their work highlighted that ignoring heterogeneity from matched strata leads to variance underestimation—a cautionary result relevant to any weighted survival analysis where the source of weights introduces additional variability.

Covariate-Adjusted Logrank Tests and Working Models

Kong and Slud (1997) showed how to construct robust covariate-adjusted logrank statistics by substituting maximum partial likelihood estimators from various working models, providing valid hypothesis tests through robust variance estimators even under model misspecification. This work provides theoretical foundation for the approach taken in weightedsurv where working models need not be exactly correctly specified.

Sample Size Formulae for Weighted Designs

Li and Murphy (2011) developed sample size formulae for two-stage randomized trials with survival outcomes based on both a weighted KM estimator of survival probabilities at a fixed time-point and a weighted version of the log-rank test. Their conservative formulae demonstrate that the weighted KM framework extends naturally to the design phase of clinical trials.

Implementation in weightedsurv

The weighted KM methodology described above is implemented through several interconnected functions in the weightedsurv package. The key functions and their roles are:

  • ps_weights: Fits (or takes) a logistic propensity model and returns inverse probability or stabilized weights, with what is needed for weight_variance = "estimated".

  • df_counting / get_dfcounting: Prepare the counting-process dataset from raw survival data. When a weight.name argument is supplied, these functions construct the weighted risk sets and event counts needed for weighted KM estimation.

  • plot_weighted_km: Plots weighted (or unweighted) KM survival curves for two groups, with optional confidence intervals, risk tables, and summary statistics (log-rank p-value, Cox HR).

  • KM_diff: Computes the KM survival difference Ŝ1(t)−Ŝ0(t)\hat{S}^1(t) - \hat{S}^0(t), with both pointwise and simultaneous confidence intervals. Accepts arbitrary non-negative weights for IPTW.

  • plotKM.band_subgroups: Produces publication-ready plots of the survival difference with simultaneous confidence bands via martingale resampling.

  • cumulative_rmst_bands: Computes cumulative RMST difference curves with simultaneous confidence bands, again using the martingale resampling framework.

For comprehensive examples demonstrating both the randomized trial (GBSG) and observational (Rotterdam) settings, see the weightedsurv_examples vignette. It also checks the weighted standard errors: those of the weighted Kaplan-Meier curves agree with survival::survfit(weights = ); the curves agree with the iptw_km method of the adjustedCurves package, whose standard errors differ.

Summary

The weighted KM estimator provides a principled nonparametric approach to estimating population-level survival distributions from observational data via IPTW. The methodology rests on:

  1. Causal identification via the ignorability, completely random censoring, positivity, and consistency assumptions.
  2. Counting process formulation enabling martingale-based variance estimation and resampling inference.
  3. Martingale resampling for simultaneous confidence bands, extending naturally to the weighted setting and to cumulative RMST curves.

The weightedsurv package provides an integrated implementation of these methods. What is checked against other packages (in the weightedsurv_examples vignette): with weights that are not all equal, the weighted K-M standard errors equal those of survival::survfit() with the same weights; the weighted K-M curves equal those of adjustedCurves (method = "iptw_km"), whose standard errors differ from those of weightedsurv.

References

Austin, Peter C. 2014. “Use of the Propensity Score for Estimating Comparative Effectiveness in Observational Studies.” Statistics in Medicine 33 (13): 2202–11. https://doi.org/10.1002/sim.6051.
Bai, Xiaofei, Anastasios A. Tsiatis, and Sean M. O’Brien. 2013. “Doubly-Robust Estimators of Treatment-Specific Survival Distributions in Observational Studies with Stratified Sampling.” Biometrics 69 (4): 830–39. https://doi.org/10.1111/biom.12076.
Cole, Stephen R., and Miguel A. Hernán. 2004. “Adjusted Survival Curves with Inverse Probability Weights.” Computer Methods and Programs in Biomedicine 75 (1): 45–49. https://doi.org/10.1016/j.cmpb.2003.10.004.
Deng, Yuhao, and Rui Wang. 2025. “Adjusted Nelson–Aalen Estimators by Inverse Treatment Probability Weighting with an Estimated Propensity Score.” Statistics in Medicine 44 (10–12): e70085. https://doi.org/10.1002/sim.70085.
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.
Guo, Xiang, and Anastasios Tsiatis. 2005. “A Weighted Risk Set Estimator for Survival Distributions in Two-Stage Randomization Designs with Censored Survival Data.” The International Journal of Biostatistics 1 (1): Article 1. https://doi.org/10.2202/1557-4679.1000.
Kaplan, E. L., and Paul Meier. 1958. “Nonparametric Estimation from Incomplete Observations.” Journal of the American Statistical Association 53 (282): 457–81.
Kong, Fan Hui, and Eric Slud. 1997. “Robust Covariate-Adjusted Logrank Tests.” Biometrika 84 (4): 847–62.
Li, Zhiguo, and Susan A. Murphy. 2011. “Sample Size Formulae for Two-Stage Randomized Trials with Survival Outcomes.” Biometrika 98 (3): 503–18. https://doi.org/10.1093/biomet/asr019.
Miyahara, Sachiko, and Abdus S. Wahed. 2010. “Weighted Kaplan–Meier Estimators for Two-Stage Treatment Regimes.” Statistics in Medicine 29: 2581–91. https://doi.org/10.1002/sim.4020.
Rosenbaum, Paul R., and Donald B. Rubin. 1983. “The Central Role of the Propensity Score in Observational Studies for Causal Effects.” Biometrika 70 (1): 41–55.
Uno, Hajime, Brian Claggett, Lu Tian, et al. 2014. “Moving Beyond the Hazard Ratio in Quantifying the Between-Group Difference in Survival Analysis.” Journal of Clinical Oncology 32 (22): 2380–85. https://doi.org/10.1200/JCO.2014.55.2208.
Winnett, Angela, and Peter Sasieni. 2002. “Adjusted Nelson–Aalen Estimates with Retrospective Matching.” Journal of the American Statistical Association 97 (457): 245–56.
Ye, Ting, Jun Shao, and Yanyao Yi. 2024. “Covariate-Adjusted Log-Rank Test: Guaranteed Efficiency Gain and Universal Applicability.” Biometrika 111 (2): 691–705. https://doi.org/10.1093/biomet/asad045.