pairwise_rmst_test()

Pairwise RMST tests for all group pairs with multiple-comparison correction.

Usage

Source

pairwise_rmst_test(
    surv,
    tau,
    group,
    *,
    estimand="difference",
    strata=None,
    correction="holm",
    conf_level=0.95,
    format=None
)

Compares RMST between all pairs of groups, with optional multiple-comparison adjustment. This answers the question: “Which pairs of groups have significantly different RMST?” when you have more than two groups.

Parameters

surv: Surv

A right-censored Surv response (time-to-event data).

tau: float

The restriction time for RMST calculation.

group: Any

Group labels, one per observation. Can be array-like or categorical variable. Must have at least 2 unique levels to create pairs.

estimand: str = "difference"

Type of estimand: "difference" (default), "ratio", or "percentage_difference".

strata: Any | None = None

(Optional) Stratification variable. Each pairwise test is stratified by this factor.

correction: str = "holm"

Multiple-comparison adjustment: "holm" (default), "bh", "bonferroni", or "none".

conf_level: float = 0.95

Confidence level for intervals (the default is 0.95).

format: str | None = None
Output format: None (auto-detect), "pandas", "polars", or "pyarrow".

Returns

DataFrame
One row per pair of groups with columns for group1, group2, RMST estimates, difference/ratio, confidence interval, test statistic, p-value, and adjusted p-value.

Examples

Compare RMST across multiple groups with pairwise comparisons:

import greenwood as gw

lung = gw.load_dataset("lung", backend="polars")
y = gw.Surv.right(lung["time"], event=(lung["status"] == 2))
# If there are multiple groups, e.g., by stage:
# result = gw.pairwise_rmst_test(y, tau=365, group=lung["stage"])