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

The public-safe reproduction case runners are included in the wheel and source distribution. After installation, run them with python -m cases.<case>.<runner>; the same module commands work from a prepared source checkout.

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 (immutable v1.0.2 archive 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.4.tar.gz (92.2 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.4-py3-none-any.whl (88.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: risk_bridge-1.0.4.tar.gz
  • Upload date:
  • Size: 92.2 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.4.tar.gz
Algorithm Hash digest
SHA256 2bc19ad15878abff740fd87d2ce19643e3c6e05c95d5f4fe20dd8f53b77acc32
MD5 fac40fb1e7cac0d7d72461bc99a0274e
BLAKE2b-256 d5deb4a66b9e825344e59cc86bc87974fb01883cbcb113e2bd3c426dd26f0224

See more details on using hashes here.

File details

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

File metadata

  • Download URL: risk_bridge-1.0.4-py3-none-any.whl
  • Upload date:
  • Size: 88.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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 f39fac87ff6a45df151a4931894d53f461a2baaab8a31ea8c6af5e238c9f4027
MD5 9f4c0c24bfcc015f8da2f42c82bfa028
BLAKE2b-256 b9daad851580cc2119940e69b11ae72dc8960d4b8d4b4f9f218e5f0512d80315

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