Skip to main content

Risk Bridging through Constrained MLE

Project description

Risk Bridge banner

Risk Bridge

Risk Bridge is a Python package for estimating transportable binary-risk models when the available cohorts do not all contain the same information. It combines propensity-score sampling, reference-cohort calibration, maximum likelihood estimation, and constrained maximum likelihood estimation (cMLE) into reproducible simulation and user-data workflows.

Package title: Risk Bridging through Constrained MLE.

Motivation

Risk models often need to be evaluated or adapted across related populations: a target cohort, a source cohort, and a reference cohort. Standard model fitting can drift when covariate distributions, calibration strata, or observed risk markers differ across those cohorts. Risk Bridge provides a repeatable way to compare ordinary ML estimates with calibration-constrained estimates while preserving diagnostics, thresholds, and run metadata.

Foundation Papers

  • Cao, Y., Ma, W., Zhao, G., McCarthy, A. M., & Chen, J. (2024). A constrained maximum likelihood approach to developing well-calibrated models for predicting binary outcomes. Lifetime Data Analysis, 30(3), 624-648.

  • Wang, Le., Chen, J. (2026). Developing Accurate Risk Prediction Using Biased Electronic Health Record Data. Manuscript in preparation.

Key features

  • Simulated Scenario 1-3 workflows for reproducible method evaluation.
  • User-data workflow for prepared target, source, and reference CSV datasets.
  • Propensity-score matched and random-sampled source paths.
  • Constrained MLE solver ladder with calibration-violation diagnostics.
  • CSV-first output contract with optional parquet mirrors.
  • Public Python API and risk-bridge command-line interface.
  • Unit tests covering preprocessing, calibration, likelihoods, constraints, optimization, metrics, sampling, and pipeline behavior.

Installation

From the package index (standard path)

uv add risk-bridge
# or: pip install risk-bridge

From a repository checkout

Risk Bridge is also packaged with uv and a checked-in lock file. To install uv, read this.

git clone git@github.com/SaehwanPark/risk-bridge.git
cd risk-bridge
uv sync --locked

Run the test suite:

uv run pytest
uv run basedpyright

The orchestration layer uses comp-builders for explicit Result composition in recoverable validation paths. uv sync --locked installs it from the package index as recorded in uv.lock.

Quick start

Run a small simulated scenario:

uv run risk-bridge \
  --mode simulated \
  --scenario 2 \
  --nsim 5 \
  --n-target 5000 \
  --n-source 2000 \
  --n-reference 5000 \
  --sample-size 500 \
  --output-root data \
  --run-label quickstart

Run on prepared CSV datasets:

uv run risk-bridge \
  --mode user-data \
  --target-csv /path/to/target.csv \
  --source-csv /path/to/source.csv \
  --reference-csv /path/to/reference.csv \
  --y-col label \
  --z-origin-col z_cont \
  --z-cat-col z_cat \
  --x-cols X1,X2,X3,X4 \
  --sample-size 500 \
  --nsim 1 \
  --output-root data \
  --run-label user_data

For a five-minute setup path, see QUICKSTART.md.

Architecture

Input cohorts
  target, source, reference
        ⬇️
Preprocessing and schema validation
        ⬇️
Calibration artifacts from reference cohort
  risk strata, external prevalence, X-support
        ⬇️
Sampling paths
  propensity-score matched source + random source
        ⬇️
Model fitting
  ML baseline + cMLE with calibration constraints
        ⬇️
Evaluation and exports
  estimates, ROC metrics, accuracy metrics, diagnostics, metadata

The public CLI delegates to typed configuration objects in risk_bridge.config, orchestration in risk_bridge.runs, reusable pipeline helpers in risk_bridge.pipeline, and numerical components in risk_bridge.likelihood, risk_bridge.constraints, risk_bridge.optimize, and risk_bridge.metrics.

Library usage

from risk_bridge import UserDataRunConfig, UserDataSchema, run_user_data

run_dir = run_user_data(
  UserDataRunConfig(
    target_df=target_df,
    source_df=source_df,
    reference_df=reference_df,
    schema=UserDataSchema(
      x_cols=("X1", "X2", "X3", "X4"),
      y_col="label",
      z_origin_col="z_cont",
    ),
    sample_size=500,
    output_root="data",
    run_label="hospital_a",
  )
)
print(run_dir)

Outputs

Each run writes a timestamped directory under output_root with intermediate/ and final/ folders. Start with these final outputs:

  • final/run_metadata.csv (includes schema_version, currently 1.1.0)
  • final/fit_diagnostics.csv
  • final/est_cml_psm.csv
  • final/calibration_metrics.csv
  • final/calibration_residuals.csv
  • final/roc_metrics.csv
  • final/accuracy_metrics.csv

Reproduction

End-to-end regeneration commands for Scenario 2, numerical validation, external calibration validation, the synthetic transport second example, and the runtime/support-scaling protocol are in REPRODUCTION.md. Cite this software with CITATION.cff (Zenodo version DOI 10.5281/zenodo.21418590, concept DOI 10.5281/zenodo.21401396).

Repository layout

src/risk_bridge/  Python package source
tests/            Unit tests
cases/            Privacy-safe replication harnesses
examples/         Minimal runnable examples
docs/             Supplementary documentation
assets/           README visual assets

Documentation

License

Risk Bridge is released under the Apache License 2.0.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

risk_bridge-1.0.3.tar.gz (66.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

risk_bridge-1.0.3-py3-none-any.whl (57.8 kB view details)

Uploaded Python 3

File details

Details for the file risk_bridge-1.0.3.tar.gz.

File metadata

  • Download URL: risk_bridge-1.0.3.tar.gz
  • Upload date:
  • Size: 66.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for risk_bridge-1.0.3.tar.gz
Algorithm Hash digest
SHA256 2308b35cbc81105a3936bab096192d21f0b09b2e5ce2d08e7d914fab2899c714
MD5 34753de9091d76735e52ff240be1e800
BLAKE2b-256 45449c7b44644e2a74a7ea8c76098cbc8c5b50fee4856d6b507eca0892d7fa1b

See more details on using hashes here.

File details

Details for the file risk_bridge-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: risk_bridge-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 57.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for risk_bridge-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 c6dda97ab58cbef3a047eb7fc7dfd5f60975c96890fb4afa699d1f20aecfb080
MD5 466be76bfbe1d7a84536201700b3c4ef
BLAKE2b-256 4a3a39c7a7d7e2d8cddf94a5d50164c9ce4a8bbce20071da63165390293e184d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page