Pairwise RMST tests for all group pairs with multiple-comparison correction.
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
group1, group2, rmst1, rmst2, estimate, se, lower_ci, upper_ci, statistic, p_value, and p_adjusted.
Details
All \binom{k}{2} pairwise comparisons are performed, where k is the number of unique group levels. The raw p-values are then adjusted for multiplicity using the chosen correction method. Holm’s step-down procedure (the default) controls the family-wise error rate without assuming independence between tests.
Examples
Compare one-year RMST across sex groups in the lung cancer dataset with Holm correction:
import greenwood as gw
# Load data and build a right-censored response
lung = gw.load_dataset("lung", backend="polars")
y = gw.Surv.right(lung["time"], event=(lung["status"] == 2))
# Run pairwise RMST comparisons with Holm-adjusted p-values
gw.pairwise_rmst_test(y, tau=365, group=lung["sex"], format="polars")
shape: (1, 11)| group1 | group2 | rmst1 | rmst2 | estimate | se | lower_ci | upper_ci | statistic | p_value | p_adjusted |
|---|
| i64 | i64 | f64 | f64 | f64 | f64 | f64 | f64 | f64 | f64 | f64 |
| 1 | 2 | 241.495085 | 297.46541 | -55.970324 | 14.958126 | -85.287712 | -26.652936 | -3.741801 | 0.000183 | 0.000183 |