Skip to content

Fix intra-decile income change double-counting on 0.x maintenance branch #238

@anth-volk

Description

@anth-volk

Bug

The intra_decile_impact and intra_wealth_decile_impact functions in policyengine/outputs/macro/comparison/calculate_economy_comparison.py double-count income changes when computing percentage change.

The buggy calculation:

absolute_change = (reform_income - baseline_income).values
capped_baseline_income = np.maximum(baseline_income.values, 1)
capped_reform_income = np.maximum(reform_income.values, 1) + absolute_change
income_change = (capped_reform_income - capped_baseline_income) / capped_baseline_income

reform_income already reflects the change relative to baseline_income, so adding absolute_change again to capped_reform_income doubles the effective percentage change. This causes households with a true 4% gain to appear as 8%, pushing them into the wrong bucket (>5% instead of <5%).

Fix

Replace with:

absolute_change = reform_values - baseline_values
capped_baseline = np.maximum(baseline_values, 1)
income_change = absolute_change / capped_baseline

This mirrors the fix applied in policyengine-api (PR PolicyEngine/policyengine-api#3283).

Scope

  • intra_decile_impact
  • intra_wealth_decile_impact
  • Both on the 0.x maintenance branch

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions