Skip to content

Add ClinicalPresenceMortalityMIMIC3 task and capacity-based fairness metrics (Jeanselme et al., ML4H 2022) - #1557

Merged
solarsys merged 41 commits into
sunlabuiuc:masterfrom
johvnguyen:cse6250/clinical-presence-fairness
Nov 28, 2026
Merged

solarsys merged 41 commits into
sunlabuiuc:masterfrom
johvnguyen:cse6250/clinical-presence-fairness

Conversation

@johvnguyen

@johvnguyen johvnguyen commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Contributor: Chunyi Yu (cyu410@gatech.edu) and John Nguyen (jnguyen461@gatech.edu), Georgia Tech, CSE 6250 (Fall 2026)

Contribution Type: Standalone Task, with a fairness metric

Paper: Jeanselme, De-Arteaga, Zhang, Barrett and Tom. "Imputation Strategies Under Clinical Presence: Impact on Algorithmic Fairness." ML4H 2022, PMLR 193:12–34. https://proceedings.mlr.press/v193/jeanselme22a.html. Reference code: https://github.com/Jeanselme/ClinicalPresenceFairness (MIT).

Description: Missing data in electronic health records indicates both the patient's access to care and their health. Consequently, missingness can be used as an indicator between groups of patients. Jeanselme et al. shows that imputation strategies with similar population AUC can still treat marginalised groups differently. This PR makes its MIMIC-III experiment reproducible in PyHealth:

  • ClinicalPresenceMortalityMIMIC3 builds the paper's cohort (each adult's last admission of at least 24 h, the latest value of 67 labs in its first 24 h, death within 8 days) and imputes the labs at the cohort level. Strategies: Median, MICE and Group MICE, each with optional missingness indicators, plus MissForest-style imputation as an ablation and a corrected MICE as a sensitivity analysis. Black, female and public-insurance flags travel with each sample for evaluation only.
  • capacity_fairness_metrics compares a group with the rest when only the top capacity share of risk scores is prioritised. It reports AUC, prioritisation rate, FNR and FPR, and their gaps, bootstrapped as in the paper.
  • An example script reruns the experiment and writes the paper's tables and figures as aggregates. Its results on MIMIC-III v1.4 are in the .md file next to it.

No MIMIC-III data is included. The tests use synthetic patients.

Files to Review:

  • pyhealth/tasks/clinical_presence_mortality_mimic3.py - the task (start with pre_filter)
  • pyhealth/metrics/fairness_utils/capacity.py - the metric
  • examples/mimic3_clinical_presence_mortality_logistic_regression.py - the experiment
  • examples/mimic3_clinical_presence_mortality_logistic_regression.md - our results on MIMIC-III v1.4
  • tests/core/test_clinical_presence_mortality_mimic3.py, tests/core/test_fairness_capacity.py - tests
  • docs/api/tasks/pyhealth.tasks.ClinicalPresenceMortalityMIMIC3.rst, docs/api/metrics/pyhealth.metrics.fairness.rst - docs, with their toctree entries and the two __init__.py exports

Design

  • Imputation runs in pre_filter, the only hook that sees the whole cohort. By default each imputer is fit on the training patients only, so validation and test patients cannot shift the training values. __call__ is then a lookup.
  • Each (patient, imputation draw) is one sample, with split and draw fields. The split depends only on cohort and seed, so every strategy is evaluated on the same test patients.

Differences from the reference code

The task follows the reference code, which produced the paper's numbers, except where the code has a bug or departs from the paper's text. The task's docs page lists each difference and its effect.

  • The split is 80/10/10, as in the text. The code evaluates on 28% of patients, and reference_split=True re-creates its split.
  • Missingness indicators are added after imputation, as in the text. indicators_in_imputation=True gives the code's order.
  • Group MICE drops all three group flags. The code leaves the Black flag among the classifier inputs, which the example's diagnostic rows re-create.
  • The sex flag is fixed, and the MICE noise is seeded.
  • The index admission is the latest one, and the label and lab-linking rules are stand-ins for DEATHTIME and HADM_ID, which PyHealth's config did not load when the task was written.

Results

On MIMIC-III v1.4 and run over five split seeds. The results file has the full tables, the hypotheses and the ablations.

  • The cohort has 36,313 patients (paper: 36,296). A port of the reference preprocessing gives exactly 36,296, and the difference comes from the index-admission, label and lab rules above.
  • Population AUC is within 0.022 of the paper's for every strategy, and missingness indicators raise it by about 0.035 (paper: 0.04–0.05).
  • Median, MICE and Group MICE have nearly the same AUC, yet Group MICE widens the sex and insurance prioritisation gaps in every seed.
  • In the paper, Group MICE lowers the share of Black patients prioritised at 30% capacity from 0.323 (MICE) to 0.150. We see no drop (0.346 under both) unless the classifier also gets the Black flag, as in the reference code (0.211).
  • Neither the MissForest ablation nor the corrected MICE changes these findings.

Verification

  • 47 unit tests on synthetic patients, each under 1 s. A multi-worker test runs only with PYHEALTH_RUN_SLOW=1.
  • The metric matches the reference's evaluate() to 12 decimal places.
  • On full MIMIC-III v1.4, the cohort matches the reference port (above), and noise-free MICE through the task matches the reference loop on the well-observed labs.
  • All PR contribution rules pass (tools/check_pr_rules.py).
  • The docs pages add no warnings to a Sphinx 8.2.3 build (the pinned 5.2.3 does not run on Python 3.13).

Limitations

  • MICE is numerically ill-posed on this cohort both in the reference and in ours. Rare labs have fewer observed training patients than predictors, some imputations land far outside the training range, and the noise collapses after one sweep. The task logs the extreme-imputation rate, and corrected MICE is the sensitivity analysis.
  • The reference's duplicate rule erases Prothrombin time, so the models effectively see 66 labs.
  • A 10% test split leaves few Black patient deaths per seed, so the results file reports five-seed means.
  • PyHealth's LogisticRegression is the library-native path, not the paper's ℓ2 model, and its results depend on the sample cache's order.

Notes from the authors

  • The main claim holds. Population AUC alone cannot choose an imputation strategy: strategies with nearly the same AUC still differ in their subgroup gaps.
  • Group-aware imputation can widen gaps, just not the Black-patient gap the paper highlights. In our runs, Group MICE widens the sex and insurance gaps. The paper's drop for Black patients mostly comes from the Black flag reaching the classifier, not from the imputation.
  • On other datasets, we suggest fitting imputers on the training patients only, comparing every strategy's subgroup gaps at the capacity that will be used, checking that group flags used for imputation don't reach the classifier, and judging small groups over several split seeds.

Possible follow-ups

  • The reference's label and lab-linking rules, now that PyHealth loads deathtime and labevents.hadm_id.
  • Keeping INR when INR and PT share a charttime, so that Prothrombin time survives.
  • Sorting each split by patient ID before training PyHealth's model, so that its results no longer depend on the cache's order.

Question for maintainers

Should capacity_fairness_metrics also be importable from pyhealth.metrics, like fairness_metrics_fn?

@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Test Coverage

Total: 87.55% (52981 / 60516 lines)

Modified file Coverage Lines
pyhealth/metrics/fairness_utils/__init__.py 100.00% 3 / 3
pyhealth/metrics/fairness_utils/capacity.py 100.00% 59 / 59
pyhealth/tasks/__init__.py 98.36% 120 / 122
pyhealth/tasks/clinical_presence_mortality_mimic3.py 98.84% 256 / 259

Workflow run · b1ce58f

@johvnguyen
johvnguyen marked this pull request as ready for review November 20, 2026 02:28
@johvnguyen
johvnguyen force-pushed the cse6250/clinical-presence-fairness branch from 1743205 to 4a0a9b1 Compare November 20, 2026 21:01
@solarsys solarsys added the status: manual Pending maintainer's review label Nov 21, 2026
@solarsys

Copy link
Copy Markdown
Collaborator

/review

@github-actions github-actions Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previous review

Reviewed commit 4a0a9b1

@github-actions github-actions Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previous review

AI Review

suggestion: need change
decision: human review

Thank you for this contribution, Chunyi and John. It adds a reproducible version of the Jeanselme et al. MIMIC-III experiment: a ClinicalPresenceMortalityMIMIC3 task with several imputation strategies, a capacity-based fairness metric that matches the reference bootstrap, an example script with results, docs, and 47 synthetic-data tests. It is carefully done and thoroughly documented. Coverage is above the bar: 100% for capacity.py, 98.84% for the task file, and 86.11% for the whole repository.

To get this merged:

  • The example examples/mimic3_clinical_presence_mortality_logistic_regression.py imports the private helper _bootstrap from pyhealth/metrics/fairness_utils/capacity.py. It uses it in paired_differences to reuse the metric's resampling. The description doesn't mention this link. Please do one of these: confirm the sharing is intended and say why in the description (for example, the paired bootstrap needs the same resamples as capacity_fairness_metrics), or keep the example self-contained, by copying the few lines it needs or calling the public function.

Optional suggestions:

  • The task docstring says the group flags are "never features". Group MICE does use them as imputation predictors, so they reach the classifier indirectly. A short sentence saying so would be clearer.
  • The example script is about 1,400 lines. Moving the report and plotting code into helpers or a separate file would make it easier to review. The script itself has no tests, so that is worth noting too.
  • On your question about pyhealth.metrics: that is a maintainer call. Re-exporting there would be a simple registration.

I haven't run the code, so the numbers in the results file are unchecked.

Reviewed commit 4a0a9b1

Copy link
Copy Markdown
Collaborator

/review


Generated by Claude Code

@github-actions github-actions Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previous review

Reviewed commit bece67c

@github-actions github-actions Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previous review

AI Review

suggestion: approve
decision: human review

Thank you, Chunyi and John, for this contribution. It adds a reproducible task for the Jeanselme et al. clinical-presence experiment, a capacity-based fairness metric that matches the reference evaluate() to 12 decimals, an example script and a results write-up.

This looks ready to merge. The task and the metric are self-contained. The __init__.py edits only add exports, and nothing existing is renamed or rebound. The task imports only BaseTask and Patient, so there are no undeclared links between components. The task cites its paper and the MIMIC-III source. The docs match the code, and the differences from the reference are listed clearly.

Coverage meets the bar. The whole repository is at 86.2%, which is above 60%. The new files are at 98.8% (task) and 100% (metric), which is above 80%.

Optional suggestions:

  • The task docs page (about 280 lines) repeats much of the class docstring and the results .md. You could shorten it, for example by keeping the strategies table and the differences table and linking to the results file for the rest.
  • The example script is long (about 1,400 lines). Moving the report and plotting helpers into a separate module would make it easier to read.
  • The results file says PyHealth 2.0.2 for the main run. A short note on whether anything changed in 2.1.0 would help readers who reproduce it.
  • On your question about exporting capacity_fairness_metrics from pyhealth.metrics: that is up to the maintainers.

Reviewed commit bece67c

@johvnguyen
johvnguyen force-pushed the cse6250/clinical-presence-fairness branch from bece67c to a775c99 Compare November 28, 2026 03:25
@johvnguyen

Copy link
Copy Markdown
Contributor Author

Pushed a rebase to resolve a merge conflict.

@solarsys

Copy link
Copy Markdown
Collaborator

/review

@github-actions github-actions Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previous review

Reviewed commit a775c99

@github-actions github-actions Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previous review

AI Review

suggestion: approve
decision: human review

Thank you, Chunyi and John, for this contribution. It adds a task that reproduces the Jeanselme et al. MIMIC-III experiment (cohort-level imputation, 8-day mortality), plus a capacity-based fairness metric, an example script with results, and docs.

It looks ready to merge. The task and the metric are self-contained. The only edits to existing files are two exports in __init__.py and docs entries, which count as registration. The description names the paper and reference code, lists every difference from the reference, and states the limitations. The metric is checked against the reference's evaluate() to 12 decimals. The 47 tests cover the cohort rules, split, imputers, train-only fitting, set_task end to end, the metric's hand-computed values and its error cases.

Coverage is above the bar. The whole repo is at 87.22%. capacity.py is at 100% and the task file at 98.84%. The two modified __init__.py files are at 100% and 98.29%.

Optional suggestions:

  • The task docs page (about 280 lines) and the example script (about 1,300 lines) are long. You could trim the docs to the essentials and link to the results .md for the rest.
  • from sklearn.experimental import enable_iterative_imputer runs at import of pyhealth.tasks. You could import it lazily inside _make_imputer, so other users of pyhealth.tasks don't pay for it.
  • With num_workers above 1, the fitted feature arrays (up to about 195 MB) are pickled to each worker. A short note in the docs would help.
  • On your question about exporting capacity_fairness_metrics from pyhealth.metrics, a maintainer can decide that.

Reviewed commit a775c99

@solarsys solarsys added status: automatic The PR will go through automatic review process. and removed status: manual Pending maintainer's review labels Nov 28, 2026
@solarsys

Copy link
Copy Markdown
Collaborator

Good news: this PR has moved from status: manual to status: automatic. It had the manual label only because of its size. It adds only new files, it fits under the AI review's size limit, and the AI review already suggests approve on the latest commit.

One step is left. The AI review doesn't review a commit twice, so please push a new commit (rebasing on master is enough) and then comment /review. On automatic PRs you can request the review yourself. If the review approves, the PR merges.

1. Extreme imputation count inflated due to imputed float32 values with float64 bounds. A lab with one trianing value causes imputed values to fall out of bounds, making this type mismatch matter.

2. Reduce amount of logging, only keeping the base log.txt.

3. Fix figure titles.
… expeirments, utilizing the indicators before imputation.
…skip regression when there are no missing training values.
…nge generic var names to be specific. Remove inline logic.
@johvnguyen
johvnguyen force-pushed the cse6250/clinical-presence-fairness branch from a775c99 to b1ce58f Compare November 28, 2026 20:53
@johvnguyen

Copy link
Copy Markdown
Contributor Author

/review

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed commit b1ce58f

"max_iter": max_iter,
"initial_strategy": "median",
"imputation_order": "ascending",
"keep_empty_features": True,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[low] Labs never observed in training rows are left unscaled in val/test

With keep_empty_features=True, scikit-learn's imputers fill a lab that is all-NaN in the fitted rows with 0. The scaler in _assemble then sees a constant zero column and uses scale 1. Any val or test patient who does have that lab keeps the raw value, so it enters the classifier unstandardised, which contradicts the docs ("every column is standardised on the training patients"). This needs a lab with no training observations but some validation or test observations, so it is unlikely on MIMIC-III, but the docs promise otherwise. Fix: mask such labs out of the features, or set their scaled values to 0 for all rows, and add a test where a lab is observed only outside the training rows.

)
black = pl.col("ethnicity").str.contains("BLACK", literal=True).fill_null(False)
female = (pl.col("gender") == "F").fill_null(False)
public_insurance = (pl.col("insurance") != "Private").fill_null(True)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[low] Null insurance is counted as public, and the docs do not say so

fill_null(True) makes a patient with a missing insurance value public_insurance = 1. The docs say the flag is "any insurance other than Private", which does not cover null. Either document the null case, or treat null as unknown and exclude it from the fairness comparison.

@@ -0,0 +1,1406 @@
r"""Imputation strategies and fairness on MIMIC-III (Jeanselme et al., ML4H 2022).

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[low] Example is about 1,400 lines, mostly report generation

The script adds plotting, markdown report writing, paired bootstraps and the order comparison on top of the experiment. Much of this is beyond what PyHealth's examples usually carry. Moving the report and plotting code out, or dropping the paired-bootstrap and figure parts, would make the experiment easier to follow. The results file already documents the outputs, so this does not block the merge.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI Review

suggestion: approve
decision: approve

Thank you for this contribution. It adds a task that reproduces the MIMIC-III experiment of Jeanselme et al. (ML4H 2022), and a capacity-based fairness metric that matches the reference evaluate to 12 decimals. It also adds an example script, a results write-up, docs and 47 synthetic-data tests. It looks ready to merge.

Checks:

  • Self-contained: the task uses only BaseTask, Patient and third-party libraries. The only edits to shared files are the new export lines in two __init__.py files. They are registration only, and no existing export is removed, renamed or rebound.
  • Citations: the paper and the reference code are cited in the docstrings and docs. No new dataset is added.
  • Docs: the differences from the reference code, the limitations and the sample schema are clearly documented and match the code.
  • Coverage: the whole repository is at 87.55%, against the 60% bar. capacity.py is at 100% and clinical_presence_mortality_mimic3.py is at 98.84%, both above the 80% bar.

Optional suggestions:

  • A lab with no training observations but some validation or test observations seems to keep its raw, unscaled values. Please check this, and note it in the docs if it is intended.
  • Say in the docs that a null insurance value is counted as public insurance.
  • The 1,400-line example holds a lot of report-building code. You could trim it or move part of it out, but this is not required.
  • On your question about pyhealth.metrics: exporting capacity_fairness_metrics there is reasonable if it matches fairness_metrics_fn. That is the maintainers' call.

Reviewed commit b1ce58f

@solarsys
solarsys merged commit 69d0623 into sunlabuiuc:master Nov 28, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: automatic The PR will go through automatic review process.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants