Add UK wealth decile impact outputs#358
Conversation
|
@vahid-ahmadi I’d especially like your review on whether the UK wealth-decile formula/usage here is correct and typical: the new outputs measure household net income impacts grouped by |
PavelMakarchuk
left a comment
There was a problem hiding this comment.
Approving on methodology — verified that the relative_change formula (mean of per-household ratios) and the implicit negative-decile exclusion via mask == self.decile are both pre-existing patterns from #180 and the earlier IntraDecileImpact work, not introduced here. Wealth-decile outputs will be consistent with the income-decile outputs already produced by economic_impact_analysis.
Two non-blocking suggestions for follow-up:
-
Test brittleness in
test_uk_analysis.py— the exact-equality kwargs assertions (e.g.assert decile_calls[0] == {"baseline_simulation": baseline, "reform_simulation": reform}) will break the next time anyone adds a parameter tocalculate_decile_impacts. Prefer containment-style assertions (assert kwargs["decile_variable"] == "household_wealth_decile"). -
Schema asymmetry — UK's
PolicyReformAnalysisnow haswealth_decile_impactsandintra_wealth_decile_impactsas required fields while the US model does not, so generic consumers must branch on country. Worth a follow-up to decide whether to unify the schema withOptional[...] = Nonedefaults.
Also worth noting separately (not for this PR): the DecileImpact.relative_change formula diverges from the legacy policyengine-api aggregate Σ(change)/Σ(baseline) measure. This is a pre-existing divergence from #180, but it will become user-visible whenever economic_impact_analysis gets wired into api-v2.
Fixes #353
Fixes #354
Summary
decile_variablesupport tocalculate_decile_impacts(...), allowing callers to measure changes in one variable while grouping by a precomputed decile variable.wealth_decile_impactsandintra_wealth_decile_impactstoeconomic_impact_analysis(...).decile_variabledataframe column.Testing
uv run --extra dev python -m pytest tests/test_intra_decile_impact.py tests/test_uk_analysis.py -quv run --extra dev ruff check src/policyengine/outputs/decile_impact.py src/policyengine/tax_benefit_models/uk/analysis.py tests/test_intra_decile_impact.py tests/test_uk_analysis.pyuv run --extra dev ruff format --check src/policyengine/outputs/decile_impact.py src/policyengine/tax_benefit_models/uk/analysis.py tests/test_intra_decile_impact.py tests/test_uk_analysis.pyNotes
policyengine-api-v2; API response mapping forwealth_decileandintra_wealth_decilewill be handled separately.calculate_decile_impacts(...).dataframenow includes an additivedecile_variablecolumn so consumers can distinguish income-derived deciles from precomputed grouping variables.