Metadata-Version: 2.5
Name: esther-ineq
Version: 0.1.0
Summary: Epidemiological Statistics Toolkit for Health Inequality Estimation and Reporting in Python
Project-URL: Homepage, https://github.com/ahernandezv/ESTHER-ineq
Project-URL: Documentation, https://ahernandezv.github.io/ESTHER-ineq/
Project-URL: Repository, https://github.com/ahernandezv/ESTHER-ineq
Project-URL: Issues, https://github.com/ahernandezv/ESTHER-ineq/issues
Project-URL: Changelog, https://github.com/ahernandezv/ESTHER-ineq/blob/main/CHANGELOG.md
Author: Akram Hernández-Vásquez
License-Expression: GPL-3.0-or-later
License-File: LICENSE
Keywords: complex-surveys,concentration-index,epidemiology,equiplot,erreygers,health-equity,health-inequality,rii,sii,strobe-equity,wagstaff,who-heat
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Healthcare Industry
Classifier: Intended Audience :: Science/Research
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Scientific/Engineering :: Mathematics
Classifier: Topic :: Scientific/Engineering :: Medical Science Apps.
Classifier: Typing :: Typed
Requires-Python: >=3.10
Requires-Dist: matplotlib>=3.7
Requires-Dist: numpy>=1.24
Requires-Dist: pandas>=2.0
Requires-Dist: scipy>=1.10
Provides-Extra: all
Requires-Dist: formulaic>=1.0; extra == 'all'
Requires-Dist: openpyxl>=3.1; extra == 'all'
Requires-Dist: plotly>=5.18; extra == 'all'
Requires-Dist: polars>=1.0; extra == 'all'
Requires-Dist: python-docx>=1.1; extra == 'all'
Requires-Dist: svy>=0.35; extra == 'all'
Provides-Extra: dev
Requires-Dist: mypy>=1.10; extra == 'dev'
Requires-Dist: openpyxl>=3.1; extra == 'dev'
Requires-Dist: plotly>=5.18; extra == 'dev'
Requires-Dist: polars>=1.0; extra == 'dev'
Requires-Dist: pytest-cov>=5.0; extra == 'dev'
Requires-Dist: pytest>=8.0; extra == 'dev'
Requires-Dist: python-docx>=1.1; extra == 'dev'
Requires-Dist: ruff>=0.6; extra == 'dev'
Provides-Extra: formula
Requires-Dist: formulaic>=1.0; extra == 'formula'
Provides-Extra: interactive
Requires-Dist: plotly>=5.18; extra == 'interactive'
Provides-Extra: office
Requires-Dist: openpyxl>=3.1; extra == 'office'
Requires-Dist: python-docx>=1.1; extra == 'office'
Provides-Extra: polars
Requires-Dist: polars>=1.0; extra == 'polars'
Provides-Extra: svy
Requires-Dist: svy>=0.35; extra == 'svy'
Description-Content-Type: text/markdown

# ESTHER-ineq

**Epidemiological Statistics Toolkit for Health Inequality Estimation and Reporting in Python**

[![PyPI version](https://img.shields.io/pypi/v/esther-ineq.svg)](https://pypi.org/project/esther-ineq/)
[![CI](https://github.com/ahernandezv/ESTHER-ineq/actions/workflows/ci.yml/badge.svg)](https://github.com/ahernandezv/ESTHER-ineq/actions/workflows/ci.yml)
[![Documentation](https://img.shields.io/badge/docs-GitHub%20Pages-blue.svg)](https://ahernandezv.github.io/ESTHER-ineq/)
[![License: GPL v3+](https://img.shields.io/badge/License-GPLv3+-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)
[![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/)

`ESTHER-ineq` (`esther-ineq`) is a scientific Python library uniting **complex-survey health econometrics** (World Bank *Analyzing Health Equity*, Stata `conindex` / `lorenz` / `oaxaca_rif`, R `convey` / `rineq`) and **epidemiological health inequality surveillance & reporting** (WHO Health Inequality Monitor `healthequal` / HEAT, Pelotas ICEH `ICEHmeasures` / `equiplot`, UKHSA `PHEindicatormethods`, Moreno-Betancur GLMs, and **STROBE-Equity 2025**).

---

## Key Capabilities (`v0.1.0`)

1. **Dual First-Class Data Containers (`SurveyHealthData` & `GroupedHealthData`):**
   - Native support for `pandas.DataFrame`, `polars.DataFrame`, and optional `svy.Sample` (`samplics-org/svy`) objects.
   - Full complex multistage survey design support: probability weights (`weights`), stratification (`strata`), primary sampling units (`psu`), finite population correction (`fpc`), lonely-PSU handling, survey replicate weights (`BRR`, `Fay`, `JK1`, `JKn`, `Bootstrap`), and unconditional domain/subpopulation comparisons (`by=...`).
2. **Exact Influence-Function (`IF` / `RIF`) Variance Kernel:**
   - Default `vce="if"` accounts jointly for outcome variance, mean $\hat{\mu}_h$ denominator variance, and fractional rank $\hat{R}_i$ uncertainty in $O(N \log N)$ time, alongside `vce="convenient"` and `vce="newey"` modes for 1-to-1 Stata `conindex` replication.
3. **Complete Concentration & Classical Inequality Suite:**
   - Standard (`CI`), Generalized (`GC` / `ACI`), Modified (`MC`), **Wagstaff (`W`)**, **Erreygers (`E`)**, **Extended (`v`)**, and **Symmetric (`beta`)** concentration indices with tie-exact interval integration + omnibus subgroup Wald $F$-tests.
   - Classical `Gini`, `S-Gini`, `Atkinson` (+ Equally Distributed Equivalent `EDE`), `Generalized Entropy` (`MLD`, `Theil`, Between/Within subgroup decomposition), `Palma`, and `S80/S20`.
4. **All 21 WHO Health Inequality Monitor (`healthequal` / HEAT) Summary Measures:**
   - Simple (`D`, `R`), Ordered (`ACI`, `RCI`, `SII`, `RII`), Non-ordered (`BGV`, `BGSD`, `COV`, `MDMW`, `MDMU`, `MDBW`, `MDBU`, `MDRW`, `MDRU`, `IDISW`, `IDISU`, `TI`, `MLD`), and Population Impact (`PAR`, `PAF`) on both disaggregated tables and complex surveys.
5. **Modern Epidemiological `SII` & `RII` Engine:**
   - Survey-weighted Logistic/Probit G-computation marginal standardization (`method="logit_marginal"`), Moreno-Betancur Identity-link + Modified Poisson (`method="moreno_betancur"`), and WLS/Monte Carlo on surveillance tables, with age/stratum-specific ridits.
6. **Epidemiological & Need Standardization (`DSR`, `SMR`, `ISR`, and Horizontal Inequity `HI`):**
   - Directly and indirectly standardized rates with exact Dobson / Byar Poisson-Gamma CIs and built-in WHO (2000–2025), Segi (1960), and European (2013) standard populations.
   - Gravelle-consistent linear and nonlinear indirect need standardization (`HI`) with PSU-level Rao–Wu–Yue survey bootstrap SEs.
7. **Regression & Counterfactual Decompositions:**
   - **Wagstaff, van Doorslaer & Watanabe (2003)** linear & GLM (`AME`/`MEM`) decomposition with **automatic reference-invariant dummy grouping** for categorical factors `C(...)`.
   - **Bivariate `RIF-I-OLS`** (Heckley, Gerdtham & Kjellsson, 2016) and **`RIF-Oaxaca`** (Ríos-Ávila, 2020, including IPW propensity reweighting).
8. **Editorial Visualizations & Trilingual `STROBE-Equity` Reporting (`en`, `es`, `pt`):**
   - Pelotas `equiplot` (with automatic *top* vs. *bottom inequality* pattern diagnostics), Concentration/Lorenz curves with simultaneous confidence bands, SII/RII Ridit bubble gradients, Decomposition forest plots, and Spiegelhalter overdispersed `funnel_plot`s (`matplotlib` + optional `plotly`).
   - Direct export to `DataFrame`, `Markdown`, `LaTeX` (`booktabs`), `HTML`, `Excel (.xlsx)`, and `Word (.docx)` with automated **STROBE-Equity (2025)** methodological notes.

---

## Installation

```bash
pip install esther-ineq
# With optional Polars, Plotly, and Office exporters:
pip install "esther-ineq[all]"
```

For local editable development:

```bash
pip install -e .
```

---

## Quick Start

```python
import esther_ineq as ei

# 1. Load built-in DHS/ENDES-style complex survey dataset
df = ei.datasets.load_survey_mch()

svy = ei.SurveyHealthData(
    data=df,
    weights="sample_weight",
    strata="stratum_id",
    psu="cluster_id",
)

# 2. Erreygers concentration index across urban vs. rural domains + Wald F-test
res_ci = svy.concentration_index(
    outcome="stunting",
    rank="wealth_score",
    method="erreygers",
    by="area",
    favorable=False,
)
print(res_ci.summary())  # Default English; pass lang="es" or lang="pt" if needed

# 3. Epidemiological SII & RII + LaTeX booktabs table & STROBE-Equity note
res_sii = svy.sii_rii(
    outcome="full_immunization",
    rank="wealth_quintile",
    favorable=True,
    scale=100.0,
)
print(res_sii.to_latex())

# 4. Reference-invariant Wagstaff decomposition
decomp = svy.decompose_wagstaff(
    formula="stunting ~ C(mother_edu) + C(area) + improved_sanitation + child_age_mo",
    rank="wealth_score",
    method="erreygers",
    bootstrap_reps=200,
)
fig, ax = decomp.plot()

# 5. Pelotas equiplot directly from survey microdata (no manual collapse/reshape needed)
fig_eq, ax_eq = svy.equiplot(
    outcome="full_immunization",
    subgroup="wealth_quintile",
    by="region",
    scale=100.0,
    diagnose_pattern=True,
    sort_by="gap",
)

# Or from a Stata-style wide subgroup table:
# ei.equiplot(df_wide, columns=["Q1", "Q2", "Q3", "Q4", "Q5"], by="dpto", outcome="cloro")
```

---

## Documentation

See the [`docs/`](docs/index.md) directory for:
- [User guide and overview](docs/index.md)
- [Mathematical methodology and variance formulas](docs/methodology.md)
- [R (CRAN), Python, and Stata ecosystem benchmark](docs/ecosystem_benchmark.md)
- [API reference](docs/api_reference.md)

## Methodological Credits & References

- **ICEH Pelotas Equiplot & Inequality Patterns:** International Center for Equity in Health (ICEH), Federal University of Pelotas (`equidade.org/equiplot`; Barros & Victora).
- **WHO Health Inequality Monitor:** Schlotheuber & Hosseinpoor (2022), *International Journal of Environmental Research and Public Health* (`healthequal` / HEAT).
- **Rank-Dependent Concentration Indices & Decompositions:** O'Donnell, van Doorslaer, Wagstaff & Lindelow (2008); O'Donnell, O'Neill, Van Ourti & Walsh (2016, `conindex`); Heckley, Gerdtham & Kjellsson (2016); Ríos-Ávila (2020, `oaxaca_rif`).
- **Epidemiological SII, RII, and Reporting:** Moreno-Betancur et al. (2015); Welch et al. (2025, `STROBE-Equity`).

## Citation

If you use `ESTHER-ineq` in academic research or public health surveillance reports, please cite:

```bibtex
@software{hernandez_vasquez_esther_ineq_2026,
  author       = {Hern{\'a}ndez-V{\'a}squez, Akram},
  title        = {{ESTHER-ineq: Epidemiological Statistics Toolkit for Health Inequality Estimation and Reporting in Python}},
  year         = {2026},
  version      = {0.1.0},
  url          = {https://github.com/ahernandezv/ESTHER-ineq}
}
```

## Acknowledgments

This work was supported in part by complimentary access to Google Antigravity and Gemini 4 Argon to accelerate scientific workflows.

## License

Distributed under the **GNU General Public License v3.0 or later (`GPL-3.0-or-later`)**. See [`LICENSE`](LICENSE) for details.
