## TestResult


The outcome of a log-rank group comparison test.


Usage

``` python
TestResult(
    statistic,
    df,
    p_value,
    method,
    observed=dict(),
    expected=dict(),
)
```


This class stores the results of [logrank_test](logrank_test.md#greenwood.logrank_test) or [pairwise_logrank_test](pairwise_logrank_test.md#greenwood.pairwise_logrank_test) in a structured format. Access test statistics, significance (p-value), and per-group observed vs. expected event counts.


## Attributes


`statistic: float`  
The chi-square test statistic. Larger values indicate stronger evidence against the null hypothesis of equal survival across groups.

`df: int`  
Degrees of freedom for the chi-square distribution (number of groups minus one for [logrank_test](logrank_test.md#greenwood.logrank_test), always 1 for pairwise tests).

`p_value: float`  
Upper-tail chi-square p-value. The probability of observing a chi-square statistic this large or larger under the null hypothesis of equal survival. Small p-values (typically p \< 0.05) indicate significant differences between groups.

`method: str`  
Human-readable description of the test method and its configuration, e.g., "Log-rank test", "Stratified log-rank test", "G-rho test (rho=1, gamma=0)".

`observed: dict[Any, float]`  
Dictionary mapping each group label to its observed (actual) weighted event count. Useful for understanding which groups contribute more events.

`expected: dict[Any, float]`  
Dictionary mapping each group label to its expected event count under the null hypothesis of equal survival. Comparison of observed vs. expected reveals which groups have more or fewer events than expected.


## Details

For a significant result (p_value \< 0.05), examine the `observed` and `expected` dictionaries to see which groups experienced more or fewer events than expected. Groups with observed \> expected have worse (shorter) survival; groups with observed \< expected have better (longer) survival.


## Examples

Run a log-rank test and examine results:


``` python
import greenwood as gw

lung = gw.load_dataset("lung", backend="polars")
y = gw.Surv.right(lung["time"], event=(lung["status"] == 2))
result = gw.logrank_test(y, group=lung["sex"])
result
```


    TestResult(method='Log-rank test', statistic=10.3267, df=1, p_value=0.001311)


Access individual components. The chi-square statistic:


``` python
result.statistic
```


    10.32674195488564


The p-value for significance:


``` python
result.p_value
```


    0.001311164520355484


Observed event counts per group (actual events in data):


``` python
result.observed
```


    {1: 112.0, 2: 53.0}


Expected event counts per group (under null hypothesis):


``` python
result.expected
```


    {1: 91.58173902957279, 2: 73.41826097042721}


Test description:


``` python
result.method
```


    'Log-rank test'
