EquiFlow - Equity-Focused Cohort Flow Diagrams
Visualize and quantify selection bias in clinical ML/research cohorts. Based on Ellen et al. (2024) J Biomed Inform.
When to Use This Skill
- Building patient cohorts from MIMIC-IV or eICU
- Documenting inclusion/exclusion criteria with CONSORT-style diagrams
- Detecting disproportionate exclusion of vulnerable groups
- Quantifying selection bias via Standardized Mean Difference (SMD)
Default Equity Variables
When no variables are specified, CohortFlow automatically tracks:
| Category |
Variables |
Column Aliases |
| Demographics |
gender |
gender, sex |
|
race |
race, ethnicity |
|
age |
anchor_age, age, admission_age |
| Socioeconomic |
insurance |
insurance, insurance_type, payer |
|
language |
language, primary_language |
|
marital_status |
marital_status, marital |
| Clinical |
los |
los, length_of_stay, icu_los |
| Outcome |
mortality |
hospital_expire_flag, mortality, death |
SMD Interpretation
| |SMD| | Interpretation | Action |
|-------|----------------|--------|
| < 0.1 | Negligible | OK |
| 0.1-0.2 | Small | Monitor |
| > 0.2 | Meaningful | Investigate |
| > 0.5 | Large | Serious concern |
See references/smd_interpretation.md for detailed guidance.
Critical Implementation Notes
Auto-detection: CohortFlow scans DataFrame columns for known aliases. Override with use_defaults=False if you want full control.
SMD > 0.2 is the default threshold for flagging potential bias. This follows established covariate balance literature.
Missing data: Exclusion steps that remove patients with missing values can introduce systematic bias. Always check SMD after such steps.
Example Queries
Full workflow with MIMIC-IV
from cohort_flow import CohortFlow
# Step 1: Query MIMIC-IV
query = """
SELECT
p.subject_id, p.gender, p.anchor_age,
a.race, a.insurance, a.language, a.marital_status,
a.hospital_expire_flag,
i.los
FROM mimiciv_hosp.patients p
JOIN mimiciv_hosp.admissions a USING (subject_id)
JOIN mimiciv_icu.icustays i ON a.hadm_id = i.hadm_id
"""
df = execute_query(query)
# Step 2: Build cohort with equity tracking
cf = CohortFlow(df) # Auto-detects equity variables
cf.exclude(df['anchor_age'] >= 18, "Age < 18", "Adults")
cf.exclude(df['los'] >= 24, "ICU < 24h", "ICU >= 24h")
cf.exclude(df['anchor_age'] <= 90, "Age > 90", "Age 18-90")
# Step 3: Check for bias
print(cf.check_bias()) # Flags variables with SMD > 0.2
# Step 4: Generate diagram
cf.plot("sepsis_cohort_flow")
Minimal example
cf = CohortFlow(df)
cf.exclude(df['anchor_age'] >= 18, "Age < 18", "Adults")
cf.view_drifts() # SMD values after exclusion
Dependencies
pip install equiflow
References
- Ellen JG, et al. "Participant flow diagrams for health equity in AI." J Biomed Inform. 2024;152:104631.
Converted and distributed by TomeVault — claim your Tome and manage your conversions.
1---2name: equiflow3description: Generate equity-focused cohort selection flow diagrams. Tracks demographic, socioeconomic, and outcome variables at each exclusion step and calculates SMD to detect selection bias. Use for cohort construction, CONSORT-style diagrams, or bias detection in clinical ML/research. Use when this capability is needed.4---56# EquiFlow - Equity-Focused Cohort Flow Diagrams78Visualize and quantify selection bias in clinical ML/research cohorts. Based on Ellen et al. (2024) J Biomed Inform.910## When to Use This Skill1112- Building patient cohorts from MIMIC-IV or eICU13- Documenting inclusion/exclusion criteria with CONSORT-style diagrams14- Detecting disproportionate exclusion of vulnerable groups15- Quantifying selection bias via Standardized Mean Difference (SMD)1617## Default Equity Variables1819When no variables are specified, CohortFlow automatically tracks:2021| Category | Variables | Column Aliases |22|----------|-----------|----------------|23| Demographics | gender | gender, sex |24| | race | race, ethnicity |25| | age | anchor_age, age, admission_age |26| Socioeconomic | insurance | insurance, insurance_type, payer |27| | language | language, primary_language |28| | marital_status | marital_status, marital |29| Clinical | los | los, length_of_stay, icu_los |30| Outcome | mortality | hospital_expire_flag, mortality, death |3132## SMD Interpretation3334| |SMD| | Interpretation | Action |35|-------|----------------|--------|36| < 0.1 | Negligible | OK |37| 0.1-0.2 | Small | Monitor |38| > 0.2 | Meaningful | Investigate |39| > 0.5 | Large | Serious concern |4041See `references/smd_interpretation.md` for detailed guidance.4243## Critical Implementation Notes44451. **Auto-detection**: CohortFlow scans DataFrame columns for known aliases. Override with `use_defaults=False` if you want full control.46472. **SMD > 0.2 is the default threshold** for flagging potential bias. This follows established covariate balance literature.48493. **Missing data**: Exclusion steps that remove patients with missing values can introduce systematic bias. Always check SMD after such steps.5051## Example Queries5253### Full workflow with MIMIC-IV5455```python56from cohort_flow import CohortFlow5758# Step 1: Query MIMIC-IV59query = """60SELECT61 p.subject_id, p.gender, p.anchor_age,62 a.race, a.insurance, a.language, a.marital_status,63 a.hospital_expire_flag,64 i.los65FROM mimiciv_hosp.patients p66JOIN mimiciv_hosp.admissions a USING (subject_id)67JOIN mimiciv_icu.icustays i ON a.hadm_id = i.hadm_id68"""69df = execute_query(query)7071# Step 2: Build cohort with equity tracking72cf = CohortFlow(df) # Auto-detects equity variables7374cf.exclude(df['anchor_age'] >= 18, "Age < 18", "Adults")75cf.exclude(df['los'] >= 24, "ICU < 24h", "ICU >= 24h")76cf.exclude(df['anchor_age'] <= 90, "Age > 90", "Age 18-90")7778# Step 3: Check for bias79print(cf.check_bias()) # Flags variables with SMD > 0.28081# Step 4: Generate diagram82cf.plot("sepsis_cohort_flow")83```8485### Minimal example8687```python88cf = CohortFlow(df)89cf.exclude(df['anchor_age'] >= 18, "Age < 18", "Adults")90cf.view_drifts() # SMD values after exclusion91```9293## Dependencies9495```bash96pip install equiflow97```9899## References100101- Ellen JG, et al. "Participant flow diagrams for health equity in AI." J Biomed Inform. 2024;152:104631.102103---104> Converted and distributed by [TomeVault](https://tomevault.io/claim/hannesill) — claim your Tome and manage your conversions.105<!-- tomevault:4.0:skill_md:2026-04-11 -->