polarstate
Fast, Polars-native Aalen-Johansen estimates for time-to-event data.
polarstate turns event times and outcomes into state-occupancy probabilities
at the time horizons you care about. It supports ordinary single-event analyses
and binary event/censoring data, with optional competing events.
The workflow has two explicit steps:
prepare_event_table()turns subject-level observations into an inspectable Aalen-Johansen event table at each observed time.predict_aj_estimates()evaluates those estimates at the time horizons you request.
Install
With uv:
uv add polarstate
Alternatively, with pip:
pip install polarstate
Quick start
Start with one row per observation:
import polars as pl
from polarstate import prepare_event_table, predict_aj_estimates
observations = pl.DataFrame(
{
"times": [24.1, 9.7, 49.9, 18.6, 34.8, 14.2, 39.2, 46.0, 31.5, 4.3],
"reals": [1, 1, 1, 1, 0, 2, 1, 2, 0, 1],
}
)
1. Prepare the event table
event_table = prepare_event_table(observations)
event_table.select(
"times",
"at_risk",
"count_0",
"count_1",
"count_2",
"overall_survival",
"state_occupancy_probability_1_at_times",
"state_occupancy_probability_2_at_times",
)
Selected columns from the output:
| times | at_risk | count_0 | count_1 | count_2 | overall_survival | state 1 probability | state 2 probability |
|---|---|---|---|---|---|---|---|
| 4.3 | 10 | 0 | 1 | 0 | 0.900000 | 0.100000 | 0.000000 |
| 9.7 | 9 | 0 | 1 | 0 | 0.800000 | 0.200000 | 0.000000 |
| 14.2 | 8 | 0 | 0 | 1 | 0.700000 | 0.200000 | 0.100000 |
| 18.6 | 7 | 0 | 1 | 0 | 0.600000 | 0.300000 | 0.100000 |
| 24.1 | 6 | 0 | 1 | 0 | 0.500000 | 0.400000 | 0.100000 |
| 31.5 | 5 | 1 | 0 | 0 | 0.500000 | 0.400000 | 0.100000 |
| 34.8 | 4 | 1 | 0 | 0 | 0.500000 | 0.400000 | 0.100000 |
| 39.2 | 3 | 0 | 1 | 0 | 0.333333 | 0.566667 | 0.100000 |
| 46.0 | 2 | 0 | 0 | 1 | 0.166667 | 0.566667 | 0.266667 |
| 49.9 | 1 | 0 | 1 | 0 | 0.000000 | 0.733333 | 0.266667 |
The complete event table also retains the intermediate hazards, survival increments, and transition probabilities used in the calculation.
2. Query fixed time horizons
estimates = predict_aj_estimates(
event_table,
pl.Series([10.0, 20.0, 30.0, 40.0]),
)
estimates
Output:
| times | state 0 probability | state 1 probability | state 2 probability | estimate_origin |
|---|---|---|---|---|
| 10.0 | 0.800000 | 0.200000 | 0.000000 | fixed_time_horizons |
| 20.0 | 0.600000 | 0.300000 | 0.100000 | fixed_time_horizons |
| 30.0 | 0.500000 | 0.400000 | 0.100000 | fixed_time_horizons |
| 40.0 | 0.333333 | 0.566667 | 0.100000 | fixed_time_horizons |
State 0 is remaining event-free, state 1 is the event of interest, and state 2 is the competing event.
Code 0 in the input indicates right-censoring: follow-up ended without an
observed event. This includes administrative censoring at the end of
observation. Code 1 indicates the event of interest, and optional code 2
a competing event.
Why polarstate?
- Polars-native inputs and outputs
- A compact, explicit event table you can inspect
- Predictions at arbitrary time horizons
- Support for single-event, binary event/censoring, and competing-risks data
Learn more
- How the estimator works explains the Aalen-Johansen calculation and every returned column.
- Package comparisons checks the same estimates against Python's lifelines and R's tidycmprsk.
- Recipes covers single-event, competing-risks, grouped, and pandas-to-Polars workflows.
- The API Reference provides complete signatures and parameter details.
Metadata
Release files for polarstate 0.1.9
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| polarstate-0.1.9.tar.gz | 8.7 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| polarstate-0.1.9-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 19.6 kB
Release files / polarstate-0.1.9.tar.gz
| Download URL | polarstate-0.1.9.tar.gz |
|---|---|
| Size | 8.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
801dfa0aedeb11a4bddf7cd26c95bf906212e7ee0f05316d111c1ccac97fe5c1
|
|
BLAKE2b-256 checksum How to use checksums |
5063f2267a3d38017712530180547a8391b47bdc534596133fbedd12c5dd02dd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.1 {"installer":{"name":"uv","version":"0.13.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / polarstate-0.1.9-py3-none-any.whl
| Download URL | polarstate-0.1.9-py3-none-any.whl |
|---|---|
| Size | 10.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
07606e86295148409e626e09ff275f4e58e54d20aed87316497ec55d561390ea
|
|
BLAKE2b-256 checksum How to use checksums |
037e03b93b990a56f1c2c602c6780591ecb7bf6f6cb105ffdcb92ff8b173976b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.1 {"installer":{"name":"uv","version":"0.13.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for polarstate 0.1.9
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.