Skip to content

Improve electricity and gas imputations to match NEED 2023 admin data#286

Merged
MaxGhenis merged 8 commits intomainfrom
feat/energy-imputation-improvements
Mar 6, 2026
Merged

Improve electricity and gas imputations to match NEED 2023 admin data#286
MaxGhenis merged 8 commits intomainfrom
feat/energy-imputation-improvements

Conversation

@nwoodruff-co
Copy link
Collaborator

Summary

  • Derives separate electricity and gas spending from LCFS interview variables (B226/B489/B490) rather than splitting the aggregate P537 variable
  • Calibrates LCFS training data to NEED 2023 mean kWh targets by income band, using Ofgem Q4 2023 unit rates (27.35p/kWh electricity, 6.89p/kWh gas) — 2023 rather than 2022 to avoid the energy price crisis anomaly
  • Adds tenure_type and accommodation_type as QRF predictors
  • Applies iterative raking on the FRS post-prediction to pin imputed means to NEED 2023 margins across income band, tenure, accommodation type, and region simultaneously
  • Switches income predictor to hbai_household_net_income throughout
  • Bumps policyengine-uk dependency to >=2.74.0 (required for num_vehicles)

Test plan

  • test_energy_calibration.py verifies imputed electricity and gas on the FRS are within 10% of NEED 2023 admin data across all four dimensions:
    • Income band (10 bands, <£15k to £150k+)
    • Tenure (owner-occupied, private rent, social)
    • Accommodation type (detached, semi, terraced, flat, mobile)
    • Region (10 regions, England and Wales)
  • All 8 tests pass

- Derive separate electricity and gas from LCFS interview variables
  (B226/B489/B490) rather than splitting the P537 aggregate
- Calibrate LCFS training data to NEED 2023 kWh targets by income band
  using Ofgem Q4 2023 unit rates (27.35p/kWh elec, 6.89p/kWh gas)
- Add tenure_type and accommodation_type as QRF predictors
- Post-prediction iterative raking on the FRS over income band, tenure,
  accommodation type, and region to pin imputed means to NEED 2023 margins
- Use hbai_household_net_income as the income predictor throughout
- Update policyengine-uk dependency to >=2.74.0 (adds num_vehicles)
- Add test_energy_calibration.py proving <10% error vs NEED 2023 across
  all four dimensions
@MaxGhenis MaxGhenis force-pushed the feat/energy-imputation-improvements branch from 85f8515 to 42f5c9c Compare March 6, 2026 13:50
MaxGhenis and others added 5 commits March 6, 2026 08:52
… B231 ref

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Move kWh→spend conversions to module-level _NEED_SPEND dict (avoids
  recomputing dict comprehensions on every impute_consumption() call)
- Pre-compute income/tenure/accomm/region boolean masks before the 20-
  iteration raking loop (saves ~80 redundant mask computations)
- Add comment explaining why 4D raking in impute_consumption differs
  from the 1D income-band calibration in _calibrate_energy_to_need

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Also fixes ruff formatting from previous commit.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The *band star-unpacking yielded a 3-element list (label, gas, elec)
but the indices assumed the original 5-element tuple positions.
Replace with explicit for-loop unpacking.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…tension

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Contributor

@MaxGhenis MaxGhenis left a comment

Choose a reason for hiding this comment

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

Code reviewed and improved: fixed NEED 2022→2023 typos, removed unused variables, precomputed NEED spend targets and raking masks for efficiency, added 3 sanity tests (non-negativity, national mean, elec+gas≈domestic). All CI checks pass.

@MaxGhenis MaxGhenis merged commit 8ba7649 into main Mar 6, 2026
3 checks passed
@nwoodruff-co nwoodruff-co deleted the feat/energy-imputation-improvements branch March 6, 2026 14:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants