Skip to content

statspai.censoring

censoring

Inverse probability of censoring / treatment weighting primitives.

IPCWResult dataclass

Result of an IPCW fit.

Attributes:

Name Type Description
weights ndarray

Per-observation IPC weights (uncensored obs only; censored rows receive weight 0 by convention but are returned for alignment).

stabilized bool

Whether stabilized weights are reported.

summary_stats dict

Basic diagnostics — mean, max, share above common thresholds.

method str

Nuisance model used for the censoring hazard.

Examples:

>>> import numpy as np
>>> import pandas as pd
>>> import statspai as sp
>>> rng = np.random.default_rng(0)
>>> n = 200
>>> age = rng.normal(50, 10, n)
>>> biomarker = rng.normal(0, 1, n)
>>> p = 1.0 / (1.0 + np.exp(-(0.5 - 0.5 * biomarker)))
>>> df = pd.DataFrame({
...     "time": rng.exponential(5, n),
...     "event": rng.binomial(1, p),
...     "age": age,
...     "biomarker": biomarker,
... })
>>> res = sp.ipcw(df, time="time", event="event",
...               censor_covariates=["age", "biomarker"])
>>> isinstance(res, sp.IPCWResult)
True
>>> diag = res.diagnose()        # weight diagnostics table
>>> list(diag.columns)
['metric', 'value']

diagnose

diagnose() -> DataFrame

Common weight diagnostics — flags extreme IPCW values.