Improve electricity and gas imputations to match NEED 2023 admin data#286
Merged
Improve electricity and gas imputations to match NEED 2023 admin data#286
Conversation
- 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
85f8515 to
42f5c9c
Compare
… 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>
MaxGhenis
approved these changes
Mar 6, 2026
Contributor
MaxGhenis
left a comment
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
tenure_typeandaccommodation_typeas QRF predictorshbai_household_net_incomethroughoutpolicyengine-ukdependency to>=2.74.0(required fornum_vehicles)Test plan
test_energy_calibration.pyverifies imputed electricity and gas on the FRS are within 10% of NEED 2023 admin data across all four dimensions: