MyNixOS website logo
Description

Algorithmic Fairness Assessment for Clinical Prediction Models.

Post-hoc fairness auditing toolkit for clinical prediction models. Unlike in-processing approaches that modify model training, this package evaluates existing models by computing group-wise fairness metrics (demographic parity, equalized odds, predictive parity, calibration disparity), visualizing disparities across protected attributes, and performing threshold-based mitigation. Supports intersectional analysis across multiple attributes and generates audit reports useful for fairness-oriented auditing in clinical AI settings. Methods described in Obermeyer et al. (2019) <doi:10.1126/science.aax2342> and Hardt, Price, and Srebro (2016) <doi:10.48550/arXiv.1610.02413>.

clinicalfair

Algorithmic Fairness Assessment for Clinical Prediction Models

R-CMD-check License: MIT


Overview

clinicalfair is a post-hoc fairness auditing toolkit for clinical prediction models. It evaluates existing models by computing group-wise fairness metrics, visualizing disparities, and performing threshold-based mitigation -- motivated by regulatory expectations for transparency in clinical AI.

  • Metrics: demographic parity, equalized odds, predictive parity, AUC, Brier score -- with optional bootstrap confidence intervals
  • Visualization: disparity plots, ROC by group, calibration by group
  • Mitigation: group-specific threshold optimization with configurable grid resolution (default 0.01)
  • Intersectional: cross-tabulated analysis (race x sex x age) with automatic small-group filtering
  • Reporting: four-fifths rule violation detection

Fairness audit

Figure 1 | Fairness audit with threshold mitigation. (a) Group-wise selection rate, TPR, and FPR before and after equalized-odds threshold optimization. Mitigation reduces cross-group TPR disparity while maintaining acceptable accuracy. (b) ROC curves by racial group showing differential model performance. Data: COMPAS-style simulated recidivism predictions. Methods: Hardt et al. (2016); Obermeyer et al. (2019).


Why clinicalfair?

Existing R packages approach fairness from different angles:

PackageFocusclinicalfair difference
fairmodelsModel-level fairness (wraps mlr3)clinicalfair is model-agnostic: works with any predicted probabilities
fairnessMetric computationclinicalfair adds threshold mitigation + intersectional analysis
fairmetricsCIs for fairness metricsclinicalfair also provides bootstrap CIs, plus audit reports with four-fifths rule screening

clinicalfair is designed for the clinical audit use case: a clinician or regulator receives a trained model and needs to answer "is this model fair across patient subgroups?" in one function call, with actionable output.

# One-line audit
fairness_report(fairness_data(predictions, labels, race))

Installation

# From GitHub:
devtools::install_github("CuiweiG/clinicalfair")

# After CRAN acceptance:
install.packages("clinicalfair")

Quick start

library(clinicalfair)
data(compas_sim)

# Create fairness evaluation object
fd <- fairness_data(
    predictions = compas_sim$risk_score,
    labels = compas_sim$recidivism,
    protected_attr = compas_sim$race
)

# Compute metrics
fairness_metrics(fd)

# With bootstrap confidence intervals
fairness_metrics(fd, ci = TRUE, n_boot = 2000)

# Generate audit report
fairness_report(fd)

# Mitigate via threshold optimization
threshold_optimize(fd, objective = "equalized_odds")

Calibration by group

Figure 2 | Calibration curves by racial group. Each point represents a decile bin; point size proportional to sample count. Deviation from the diagonal indicates miscalibration. Differential calibration across groups is a key fairness concern identified by Obermeyer et al. (2019) Science 366:447.


Functions

FunctionDescription
fairness_data()Bundle predictions, labels, protected attributes
fairness_metrics()Compute group-wise fairness metrics (optional bootstrap CIs)
fairness_report()Generate audit report with four-fifths rule screening
threshold_optimize()Group-specific threshold mitigation (configurable grid resolution)
intersectional_fairness()Cross-tabulated multi-attribute analysis (small-group filtering)
autoplot()Disparity bar plots (S3 method)
plot_roc()ROC curves by protected group
plot_calibration()Calibration curves by group

Key references

  • Obermeyer Z et al. (2019). Dissecting racial bias in an algorithm. Science 366:447. doi:10.1126/science.aax2342
  • Hardt M et al. (2016). Equality of Opportunity in Supervised Learning. NeurIPS.
  • FDA (2021). Artificial Intelligence/Machine Learning (AI/ML)-Based Software as a Medical Device (SaMD) Action Plan.

License

MIT.

Metadata

Version

0.1.0

License

Unknown

Platforms (80)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    uefi
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-uefi
  • aarch64-windows
  • aarch64_be-none
  • arc-linux
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-linux
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • sh4-linux
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-uefi
  • x86_64-windows