## rmst_test()


Test for equality of RMST across two or more groups.


Usage

``` python
rmst_test(
    surv, tau, group, *, estimand="difference", strata=None, conf_level=0.95
)
```


Compares restricted mean survival time (RMST) up to a fixed time tau across groups using a z-test or t-test. Provides point estimate, standard error, confidence interval, and p-value for the null hypothesis of equal RMST.

For two groups, this is equivalent to a z-test on the RMST difference (default) or log-ratio (if estimand="ratio").


## Parameters


`surv: Surv`  
A right-censored [Surv](Surv.md#greenwood.Surv) response (time-to-event data).

`tau: float`  
The restriction time, typically a clinically relevant horizon (e.g., 365, 1825).

`group: Any`  
Group membership for each observation. Can be array-like or categorical variable.

`estimand: str = ``"difference"`  
Type of estimand: `"difference"` (default, RMST1 - RMST2), `"ratio"` (RMST1 / RMST2), or `"percentage_difference"` ((RMST1 - RMST2) / RMST2 \* 100).

`strata: Any | None = None`  
(Optional) Stratification variable for stratified RMST comparison. If provided, RMST estimates are combined across strata before computing the test statistic.

`conf_level: float = ``0.95`  
Confidence level for confidence intervals (the default is `0.95` for 95% CI).


## Returns


`RMSTResult`  
A result object containing estimate, standard error, confidence interval, test statistic, and p-value.


## Details

For two groups (i=1,2), the RMST difference is:

\\ \Delta = \mathrm{RMST}\_1(\tau) - \mathrm{RMST}\_2(\tau) \\

with standard error:

\\ \mathrm{SE}(\Delta) = \sqrt{\mathrm{SE}(\mathrm{RMST}\_1)^2 + \mathrm{SE}(\mathrm{RMST}\_2)^2} \\

assuming independence. The z-statistic is \\Z = \Delta / \mathrm{SE}(\Delta)\\, with two-tailed p-value from the standard normal.

For ratio estimand, the log-ratio variance uses the delta method:

\\ \mathrm{SE}(\log R) = \sqrt{\frac{\mathrm{SE}\_1^2}{\mathrm{RMST}\_1^2} + \frac{\mathrm{SE}\_2^2}{\mathrm{RMST}\_2^2}} \\


## Examples

Test RMST difference between two treatment groups:


``` python
import greenwood as gw

lung = gw.load_dataset("lung", backend="polars")
y = gw.Surv.right(lung["time"], event=(lung["status"] == 2))
result = gw.rmst_test(y, tau=365, group=lung["sex"])
result.estimate   # RMST difference
result.p_value    # significance
```


    0.00018270646131113288


Using ratio estimand:


``` python
result_ratio = gw.rmst_test(y, tau=365, group=lung["sex"], estimand="ratio")
```
