Per-time risk-set tabulation (optionally within strata).
EventTable(
time,
n_risk,
n_event,
n_censor,
strata=None,
)
Every array is aligned row-wise. When strata is not None, rows are grouped by stratum (each stratum’s times are ascending). Counts are weighted when case weights are supplied, so they may be floats.
Parameter Attributes
time: Array
-
n_risk: Array
-
n_event: Array
-
n_censor: Array
-
strata: Array | None = None
-
Examples
An EventTable is produced by event_table. Build one from the bundled lung dataset and view it as a Polars frame with to_frame.
import greenwood as gw
lung = gw.load_dataset("lung", backend="polars")
y = gw.Surv.right(lung["time"], event=(lung["status"] == 2))
et = gw.event_table(y)
et.to_frame(format="polars")
shape: (186, 4)| time | n_risk | n_event | n_censor |
|---|
| f64 | f64 | f64 | f64 |
| 5.0 | 228.0 | 1.0 | 0.0 |
| 11.0 | 227.0 | 3.0 | 0.0 |
| 12.0 | 224.0 | 1.0 | 0.0 |
| 13.0 | 223.0 | 2.0 | 0.0 |
| 15.0 | 221.0 | 1.0 | 0.0 |
| … | … | … | … |
| 840.0 | 5.0 | 0.0 | 1.0 |
| 883.0 | 4.0 | 1.0 | 0.0 |
| 965.0 | 3.0 | 0.0 | 1.0 |
| 1010.0 | 2.0 | 0.0 | 1.0 |
| 1022.0 | 1.0 | 0.0 | 1.0 |
Methods
|
Name
|
Description
|
|
to_frame()
|
Return the tabulation as a DataFrame.
|
to_frame()
Return the tabulation as a DataFrame.
Exports the event-table rows with one row per unique exit time and columns for the risk set, events, censorings, and optional strata labels.
Parameters
format: str | None = None
-
Output format:
None (default), "pandas", "polars", or "pyarrow". When None, a backend is auto-detected (Polars, then Pandas, then PyArrow).
Returns
pandas.DataFrame, polars.DataFrame, or pyarrow.Table
-
A tidy table containing
time, n_risk, n_event, n_censor, and optionally strata.
Raises
ImportError
-
If the requested (or, when auto-detecting, any) DataFrame library is not installed.
Examples
Build an event table from the bundled lung dataset and convert it to a Polars frame for inspection or downstream analysis:
import greenwood as gw
lung = gw.load_dataset("lung", backend="polars")
y = gw.Surv.right(lung["time"], event=(lung["status"] == 2))
et = gw.event_table(y)
et.to_frame(format="polars")
shape: (186, 4)| time | n_risk | n_event | n_censor |
|---|
| f64 | f64 | f64 | f64 |
| 5.0 | 228.0 | 1.0 | 0.0 |
| 11.0 | 227.0 | 3.0 | 0.0 |
| 12.0 | 224.0 | 1.0 | 0.0 |
| 13.0 | 223.0 | 2.0 | 0.0 |
| 15.0 | 221.0 | 1.0 | 0.0 |
| … | … | … | … |
| 840.0 | 5.0 | 0.0 | 1.0 |
| 883.0 | 4.0 | 1.0 | 0.0 |
| 965.0 | 3.0 | 0.0 | 1.0 |
| 1010.0 | 2.0 | 0.0 | 1.0 |
| 1022.0 | 1.0 | 0.0 | 1.0 |
Request a different backend with format=:
et.to_frame(format="pandas")
|
time |
n_risk |
n_event |
n_censor |
| 0 |
5.0 |
228.0 |
1.0 |
0.0 |
| 1 |
11.0 |
227.0 |
3.0 |
0.0 |
| 2 |
12.0 |
224.0 |
1.0 |
0.0 |
| 3 |
13.0 |
223.0 |
2.0 |
0.0 |
| 4 |
15.0 |
221.0 |
1.0 |
0.0 |
| ... |
... |
... |
... |
... |
| 181 |
840.0 |
5.0 |
0.0 |
1.0 |
| 182 |
883.0 |
4.0 |
1.0 |
0.0 |
| 183 |
965.0 |
3.0 |
0.0 |
1.0 |
| 184 |
1010.0 |
2.0 |
0.0 |
1.0 |
| 185 |
1022.0 |
1.0 |
0.0 |
1.0 |
186 rows × 4 columns