Test results for a single time window within a windowed proportional-hazards test.
ZPHWindowResult(
interval,
n_events,
per_term,
global_test,
)
When cox_zph() is called with breaks=, it partitions events into time windows and runs a separate proportional-hazards test in each window. Each ZPHWindowResult holds the test statistics for one window.
Attributes
interval: tuple[float, float]
-
The half-open time interval (lower, upper] that this window covers.
n_events: int
-
Number of events (Schoenfeld residuals) in this window.
per_term: dict[str, dict[str, float]]
-
Dictionary mapping each covariate name to {chisq, df, p_value} dict.
global_test: dict[str, float]
-
Dictionary with
{chisq, df, p_value} for the joint test across all terms.
Examples
Fit a Cox model on the lung dataset and run a windowed proportional-hazards test. Each element of the windows list is a ZPHWindowResult:
import greenwood as gw
lung = gw.load_dataset("lung", backend="polars")
cox = gw.CoxPH().fit("Surv(time, status) ~ age + sex", data=lung)
zph = cox.cox_zph(breaks=[365])
zph.windows[0]
ZPHWindowResult(interval=(0.0, 365), n_events=121, per_term={'age': {'chisq': 1.8472795365393373, 'df': 1, 'p_value': 0.1741001321564735}, 'sex': {'chisq': 1.563508224694727, 'df': 1, 'p_value': 0.2111522871555517}}, global_test={'chisq': 3.221968471495379, 'df': 2, 'p_value': 0.19969097432566088})
Inspect the per-term results for the first window:
{'age': {'chisq': 1.8472795365393373, 'df': 1, 'p_value': 0.1741001321564735},
'sex': {'chisq': 1.563508224694727, 'df': 1, 'p_value': 0.2111522871555517}}