Skip to main content

lifelines-hc

DOI PyPI License: MIT

Higher Criticism and related tests for detecting non-proportional hazard deviations in two-sample survival data — implemented as a lifelines extension.

These tests are especially powerful when hazard differences are rare (occur at few event times) and weak (small effect at each time), a regime where the classical log-rank test has little power.

Reference

Method paper. If you use this package, please cite:

Kipnis, A., Galili, B., and Yakhini, Z. (2026). Higher criticism for rare and weak non-proportional hazard deviations in survival analysis. Biometrika, 113(1), asaf075. doi:10.1093/biomet/asaf075 · arXiv:2310.00554

Software. To cite the package itself:

Kipnis, A. (2026). lifelines-hc [Computer software]. Zenodo. doi:10.5281/zenodo.23170281

Installation

pip install lifelines-hc

Or install from a local checkout in development mode:

cd lifelines-hc
pip install -e ".[dev]"

Quick start

import numpy as np
from lifelines_hc import higher_criticism_test

rng = np.random.default_rng(42)
durations_A = rng.exponential(10, size=300)
durations_B = rng.exponential(10, size=300)

result = higher_criticism_test(durations_A, durations_B, n_intervals_to_pool=50)
result.print_summary()

The result is a lifelines.statistics.StatisticalResult, so it plugs straight into any lifelines workflow.

Note on n_intervals_to_pool: The per-event hypergeometric test has very coarse resolution when each event time has at most one event (typical of continuous survival data). Setting n_intervals_to_pool pools events into equal-width time intervals, restoring statistical power. A value between 50 and 200 usually works well. For data with naturally discrete or tied event times this parameter can be omitted.

With a permutation p-value

result = higher_criticism_test(
    durations_A, durations_B,
    n_intervals_to_pool=50,
    n_permutations=1000,
    seed=0,
)
print(f"HC = {result.test_statistic:.3f}, p = {result.p_value:.4f}")

Handling censored data

event_A = rng.binomial(1, 0.8, size=300)
event_B = rng.binomial(1, 0.8, size=300)

result = higher_criticism_test(
    durations_A, durations_B,
    event_observed_A=event_A,
    event_observed_B=event_B,
    n_intervals_to_pool=50,
)
result.print_summary()

Other tests

The same per-event hypergeometric p-values can be aggregated with different statistics:

from lifelines_hc import berk_jones_test, fisher_combination_test, min_p_test

bj = berk_jones_test(durations_A, durations_B, n_intervals_to_pool=50)
fc = fisher_combination_test(durations_A, durations_B, n_intervals_to_pool=50)
mp = min_p_test(durations_A, durations_B, n_intervals_to_pool=50)

Inspecting per-event p-values

from lifelines_hc import event_pvalues

pvals = event_pvalues(durations_A, durations_B, alternative="greater", n_intervals_to_pool=50)

Identifying and visualising suspected intervals

suspected_deviations returns a DataFrame flagging the time bins where the p-value falls at or below the HC threshold — ready for gray-shading on a Kaplan-Meier plot:

from lifelines_hc import suspected_deviations

df = suspected_deviations(durations_A, durations_B, n_intervals_to_pool=50)
print(df[df["suspected"]])

See examples/plot_survival_with_hc.py for a full working example that produces a figure like:

KM with HC

API

Function Returns
higher_criticism_test StatisticalResult (HC)
berk_jones_test StatisticalResult (BJ)
fisher_combination_test StatisticalResult (Fisher)
min_p_test StatisticalResult (min-p)
event_pvalues ndarray of p-values
suspected_deviations DataFrame with flags

All test functions accept the same parameters and return a lifelines.statistics.StatisticalResult.

License

MIT

Metadata

Release files for lifelines-hc 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for lifelines-hc 0.1.3
File Size Uploaded Provenance Actions
lifelines_hc-0.1.3.tar.gz 16.6 kB Without provenance Details for lifelines_hc-0.1.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for lifelines-hc 0.1.3
File Interpreter ABI Platform Actions
lifelines_hc-0.1.3-py3-none-any.whl Python 3 none any Details for lifelines_hc-0.1.3-py3-none-any.whl

Total release size: 30.5 kB

Release files / lifelines_hc-0.1.3.tar.gz

Download URL lifelines_hc-0.1.3.tar.gz
Size 16.6 kB
Tags Source
SHA-256 checksum
How to use checksums
8b0eddf1d670908e8a912af8593fe823980dd21f86136238efc023161501a0fe
BLAKE2b-256 checksum
How to use checksums
f971fb7b99bcd2b16d5321c27b81ef22cc6f75cba3c333f65d333acdbceb36b5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / lifelines_hc-0.1.3-py3-none-any.whl

Download URL lifelines_hc-0.1.3-py3-none-any.whl
Size 13.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
be9ca4b98e277bdae232adbaf55a2074ade869a32b0c0904265124b25284aef4
BLAKE2b-256 checksum
How to use checksums
4c75afce740e0fc8cc6684c1a8dd55c7f3eac8690089f426396728285f899929
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Security for lifelines-hc 0.1.3

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.

Release history Release notifications | RSS feed

This release

0.1.3 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page