Skip to main content

metrics-adjuster

metrics-adjuster computes conventional and adjusted group-aware metrics for binary prediction models. It provides a typed Python API, a command-line interface, deterministic synthetic demos, self-contained HTML reports, and optional parquet artifacts for downstream inspection.

Research and software provenance

The underlying adjusted-risk-distribution research was originally led by Jinbo Chen and Sarah E. Hegarty. Hegarty developed the original R implementation, fairRisk, for the aTPR methodology.

Sae-Hwan Park later joined the research team and performed additional VA analyses with his Python rewrite of that workflow. The rewrite was validated internally and reviewed and approved by Hegarty for the team's analysis. It subsequently became the foundation of metrics-adjuster, which is maintained as a separate Python project and does not replace or supersede fairRisk.

For scientific provenance, users of the aTPR methodology should cite the underlying research article and acknowledge fairRisk as the original R implementation. Cite metrics-adjuster separately when using this Python software.

How metrics-adjuster extends the workflow

fairRisk remains the original native R implementation and the methodological reference for the adjusted error-rate work. Compared with the currently documented fairRisk v1.1.1.1 interface, metrics-adjuster exposes additional capabilities for Python-based analysis and reproducible delivery:

Area fairRisk Additional metrics-adjuster capability
Interface Native R package functions Typed Python API plus a shell CLI that can also be invoked from R
Adjusted metrics aTPR, aTNR, aPPV, and aNPV Nine named adjusted outputs: aTPR, aFPR, aPPV, aNPV, aBSP, aBSN, aSP, aNB, and aHR
Adjustment decomposition Calibration and density-ratio estimation support the adjusted estimators Optional calibrated-unweighted c* metrics separate recalibration effects from density-ratio standardization
Cutoffs and comparisons Function-level R analysis Fixed thresholds or risk-score quantiles, with optional reference-versus-comparison pairwise deltas
Uncertainty and intermediates Original estimator-focused R workflow Integrated bootstrap summaries plus optional calibrated-risk and density-ratio parquet artifacts
Reporting No report or decision-curve surface is exported by the current package namespace Self-contained HTML reports, metric tables, density and weight-ratio plots, adjusted net-benefit decision curves, standalone figures, and CSV artifacts
Reproducible execution Installable from the fairRisk GitHub repository PyPI distribution, validated configuration models, CSV/Parquet input, deterministic synthetic demos, and contract-tested CLI workflows

These additions broaden the operational workflow; they do not make metrics-adjuster a scientific replacement for fairRisk. Shared aTPR analyses should align the calibration model, density-ratio model, thresholds, reference group, and other estimator settings before comparing results across languages. Intentional differences in supported metrics, defaults, or output schemas should be documented rather than treated as implementation disagreement.

Installation

Install from PyPI (Python 3.11+):

python -m pip install metrics-adjuster

That one command installs both the metrics-adjuster CLI and the Python API. Parquet input and artifact output work out of the box (pyarrow is included).

Other setups:

  • CLI only, without a project environment: pipx install metrics-adjuster
  • uv project: uv add metrics-adjuster
  • conda or mamba env: run the pip command above inside your activated environment
  • pinned release: python -m pip install "metrics-adjuster==1.1.2"
  • source checkout: see Contributing

Quick Example

metrics-adjuster demo \
  --output-dir demo_outputs \
  --report \
  --save-artifacts \
  --report-figures

For caller-provided CSV or Parquet data:

metrics-adjuster run \
  --input cohort.csv \
  --output-dir adjusted_metric_outputs \
  --group-col group \
  --ref-group ref \
  --response-col outcome \
  --risk-col risk \
  --id-col patient_id \
  --metrics aTPR,aPPV,aNB,aHR \
  --report \
  --save-artifacts \
  --report-figures

The CLI writes one CSV per adjusted metric. Optional outputs include:

  • report.html when --report is enabled
  • figure_1_calibrated_density.svg, figure_2_weight_ratio.svg, and figure_3_decision_curve.svg when --report-figures is also used
  • calibration.parquet and weights.parquet when --save-artifacts is used

Python API

from pathlib import Path

from metrics_adjuster import ColumnSpec, MetricConfig, OutputConfig, adjusted_metrics
from metrics_adjuster.synthetic import generate_synthetic_metrics_data

frame = generate_synthetic_metrics_data(n=600, seed=2026)
config = MetricConfig(
  columns=ColumnSpec(group="group", response="outcome", risk="risk", id="patient_id"),
  ref_group="ref",
  output=OutputConfig(
    calibration_path=Path("artifacts/calibration.parquet"),
    density_ratio_path=Path("artifacts/weights.parquet"),
    include_intermediates=True,
  ),
  random_state=2026,
)

result = adjusted_metrics(frame, config)
print(result.metrics["aTPR"])
print(result.weighted[["cal_risk", "dens_ratio"]].head())

For reports and standalone figures, use adjusted_metrics_report(...) and write_report_figures(...). See the API manual.

Documentation

Citation

If you use the aTPR methodology, cite the underlying research article and acknowledge Sarah E. Hegarty's fairRisk as the original R implementation. If you use metrics-adjuster, cite this Python software separately as:

APA:

Park, S. (2026). metrics-adjuster (Version 1.1.2) [Computer software]. GitHub. https://github.com/SaehwanPark/metrics-adjuster

AMA:

Park S. metrics-adjuster [computer program]. Version 1.1.2. Published 2026. Accessed August 20, 2026. https://github.com/SaehwanPark/metrics-adjuster

License

metrics-adjuster is distributed under the GNU General Public License v3.0.

Download files

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

Source Distribution

metrics_adjuster-1.1.2.tar.gz (69.6 kB view details)

Uploaded Source

Built Distribution

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

metrics_adjuster-1.1.2-py3-none-any.whl (31.6 kB view details)

Uploaded Python 3

File details

Details for the file metrics_adjuster-1.1.2.tar.gz.

File metadata

  • Download URL: metrics_adjuster-1.1.2.tar.gz
  • Upload date:
  • Size: 69.6 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 metrics_adjuster-1.1.2.tar.gz
Algorithm Hash digest
SHA256 377360b95c72d7dc9e2dcb7d2b7b17e5ed71bc367c9324c6de7429bcb1d305e0
MD5 43d52f28809811ddfdc76ef4effc71ab
BLAKE2b-256 52890f67c88dbd871a35a8ca43500371038fa10c4be04def869c3006da8ef631

See more details on using hashes here.

File details

Details for the file metrics_adjuster-1.1.2-py3-none-any.whl.

File metadata

  • Download URL: metrics_adjuster-1.1.2-py3-none-any.whl
  • Upload date:
  • Size: 31.6 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 metrics_adjuster-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ab3ebb45d5bb241403d98ed1f0b84ebe45d44522e263e086d27d37b7a558acaf
MD5 26b3356d5764a863b94f98e8878eed80
BLAKE2b-256 3ddbf6099574b806e8712a2602e96510ac1b0eea5a78f8daffe4ea8cfa9a2d58

See more details on using hashes here.

Release history Release notifications | RSS feed

1.1.3

2 files

This release

1.1.2 This release

2 files

1.1.1

2 files

1.1.0

2 files

1.0.2

2 files

1.0.1

2 files

1.0.0

2 files

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