Skip to content

Commit 09c9807

Browse files
committed
Preserve household weight fuel uprating
1 parent 353a7f2 commit 09c9807

5 files changed

Lines changed: 80 additions & 12 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Restore the pre-fuel-change household-weight uprating row when calibrating fuel litre proxies.

policyengine_uk_data/storage/uprating_factors.csv

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ childcare_expenses,1.0,1.04,1.144,1.209,1.237,1.277,1.301,1.327,1.353,1.38,1.38,
1212
clothing_and_footwear_consumption,1.0,1.04,1.144,1.209,1.237,1.277,1.301,1.327,1.353,1.38,1.38,1.38,1.38,1.38,1.38
1313
communication_consumption,1.0,1.04,1.144,1.209,1.237,1.277,1.301,1.327,1.353,1.38,1.38,1.38,1.38,1.38,1.38
1414
corporate_wealth,1.0,1.0,1.092,1.147,1.19,1.223,1.258,1.297,1.34,1.384,1.384,1.384,1.384,1.384,1.384
15-
diesel_spending,1.0,1.138,1.56,1.531,1.579,1.537,1.509,1.467,1.422,1.363,1.286,1.28,1.275,1.27,1.265
15+
diesel_spending,1.0,1.138,1.57,1.539,1.589,1.54,1.507,1.46,1.415,1.355,1.284,1.284,1.284,1.284,1.284
1616
dividend_income,1.0,1.0,1.092,1.147,1.19,1.223,1.258,1.297,1.34,1.384,1.384,1.384,1.384,1.384,1.384
1717
domestic_energy_consumption,1.0,1.04,1.144,1.209,1.237,1.277,1.301,1.327,1.353,1.38,1.38,1.38,1.38,1.38,1.38
1818
education_consumption,1.0,1.04,1.144,1.209,1.237,1.277,1.301,1.327,1.353,1.38,1.38,1.38,1.38,1.38,1.38
@@ -30,7 +30,7 @@ free_school_milk,1.0,1.04,1.144,1.209,1.237,1.277,1.301,1.327,1.353,1.38,1.38,1.
3030
gross_financial_wealth,1.0,1.0,1.092,1.147,1.19,1.223,1.258,1.297,1.34,1.384,1.384,1.384,1.384,1.384,1.384
3131
health_consumption,1.0,1.04,1.144,1.209,1.237,1.277,1.301,1.327,1.353,1.38,1.38,1.38,1.38,1.38,1.38
3232
household_furnishings_consumption,1.0,1.04,1.144,1.209,1.237,1.277,1.301,1.327,1.353,1.38,1.38,1.38,1.38,1.38,1.38
33-
household_weight,1.0,1.0,1.009,1.023,1.033,1.041,1.045,1.049,1.053,1.058,1.062,1.067,1.071,1.076,1.08
33+
household_weight,1.0,1.0,1.003,1.017,1.027,1.039,1.046,1.054,1.058,1.064,1.064,1.064,1.064,1.064,1.064
3434
housing_benefit_reported,1.0,1.04,1.144,1.209,1.237,1.277,1.301,1.327,1.353,1.38,1.38,1.38,1.38,1.38,1.38
3535
housing_service_charges,1.0,1.0,1.0,1.064,1.137,1.191,1.235,1.262,1.289,1.318,1.318,1.318,1.318,1.318,1.318
3636
housing_water_and_electricity_consumption,1.0,1.04,1.144,1.209,1.237,1.277,1.301,1.327,1.353,1.38,1.38,1.38,1.38,1.38,1.38
@@ -56,7 +56,7 @@ owned_land,1.0,1.0,1.092,1.147,1.19,1.223,1.258,1.297,1.34,1.384,1.384,1.384,1.3
5656
pension_credit_reported,1.0,1.04,1.144,1.209,1.237,1.277,1.301,1.327,1.353,1.38,1.38,1.38,1.38,1.38,1.38
5757
pension_income,1.0,1.0,1.092,1.147,1.19,1.223,1.258,1.297,1.34,1.384,1.384,1.384,1.384,1.384,1.384
5858
personal_pension_contributions,1.0,1.059,1.127,1.205,1.261,1.308,1.337,1.365,1.396,1.431,1.431,1.431,1.431,1.431,1.431
59-
petrol_spending,1.0,1.104,1.624,1.786,1.521,1.48,1.454,1.413,1.37,1.313,1.239,1.233,1.228,1.223,1.218
59+
petrol_spending,1.0,1.104,1.635,1.796,1.531,1.483,1.452,1.406,1.363,1.305,1.237,1.237,1.237,1.237,1.237
6060
private_pension_income,1.0,1.003,1.053,1.106,1.161,1.216,1.261,1.288,1.315,1.346,1.346,1.346,1.346,1.346,1.346
6161
private_transfer_income,1.0,1.0,1.092,1.147,1.19,1.223,1.258,1.297,1.34,1.384,1.384,1.384,1.384,1.384,1.384
6262
property_income,1.0,1.0,1.092,1.147,1.19,1.223,1.258,1.297,1.34,1.384,1.384,1.384,1.384,1.384,1.384

policyengine_uk_data/storage/uprating_growth_factors.csv

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ childcare_expenses,0,0.04,0.1,0.057,0.023,0.032,0.019,0.02,0.02,0.02,0.0,0.0,0.0
1212
clothing_and_footwear_consumption,0,0.04,0.1,0.057,0.023,0.032,0.019,0.02,0.02,0.02,0.0,0.0,0.0,0.0,0.0
1313
communication_consumption,0,0.04,0.1,0.057,0.023,0.032,0.019,0.02,0.02,0.02,0.0,0.0,0.0,0.0,0.0
1414
corporate_wealth,0,0.0,0.092,0.05,0.037,0.028,0.029,0.031,0.033,0.033,0.0,0.0,0.0,0.0,0.0
15-
diesel_spending,0,0.138,0.371,-0.019,0.031,-0.027,-0.018,-0.028,-0.031,-0.041,-0.056,-0.005,-0.004,-0.004,-0.004
15+
diesel_spending,0,0.138,0.379,-0.019,0.033,-0.031,-0.021,-0.032,-0.031,-0.043,-0.052,0.0,0.0,0.0,0.0
1616
dividend_income,0,0.0,0.092,0.05,0.037,0.028,0.029,0.031,0.033,0.033,0.0,0.0,0.0,0.0,0.0
1717
domestic_energy_consumption,0,0.04,0.1,0.057,0.023,0.032,0.019,0.02,0.02,0.02,0.0,0.0,0.0,0.0,0.0
1818
education_consumption,0,0.04,0.1,0.057,0.023,0.032,0.019,0.02,0.02,0.02,0.0,0.0,0.0,0.0,0.0
@@ -30,7 +30,7 @@ free_school_milk,0,0.04,0.1,0.057,0.023,0.032,0.019,0.02,0.02,0.02,0.0,0.0,0.0,0
3030
gross_financial_wealth,0,0.0,0.092,0.05,0.037,0.028,0.029,0.031,0.033,0.033,0.0,0.0,0.0,0.0,0.0
3131
health_consumption,0,0.04,0.1,0.057,0.023,0.032,0.019,0.02,0.02,0.02,0.0,0.0,0.0,0.0,0.0
3232
household_furnishings_consumption,0,0.04,0.1,0.057,0.023,0.032,0.019,0.02,0.02,0.02,0.0,0.0,0.0,0.0,0.0
33-
household_weight,0,0.0,0.009,0.014,0.01,0.008,0.004,0.004,0.004,0.005,0.004,0.005,0.004,0.005,0.004
33+
household_weight,0,0.0,0.003,0.014,0.01,0.012,0.007,0.008,0.004,0.006,0.0,0.0,0.0,0.0,0.0
3434
housing_benefit_reported,0,0.04,0.1,0.057,0.023,0.032,0.019,0.02,0.02,0.02,0.0,0.0,0.0,0.0,0.0
3535
housing_service_charges,0,0.0,0.0,0.064,0.069,0.047,0.037,0.022,0.021,0.022,0.0,0.0,0.0,0.0,0.0
3636
housing_water_and_electricity_consumption,0,0.04,0.1,0.057,0.023,0.032,0.019,0.02,0.02,0.02,0.0,0.0,0.0,0.0,0.0
@@ -56,7 +56,7 @@ owned_land,0,0.0,0.092,0.05,0.037,0.028,0.029,0.031,0.033,0.033,0.0,0.0,0.0,0.0,
5656
pension_credit_reported,0,0.04,0.1,0.057,0.023,0.032,0.019,0.02,0.02,0.02,0.0,0.0,0.0,0.0,0.0
5757
pension_income,0,0.0,0.092,0.05,0.037,0.028,0.029,0.031,0.033,0.033,0.0,0.0,0.0,0.0,0.0
5858
personal_pension_contributions,0,0.059,0.064,0.069,0.046,0.037,0.022,0.021,0.023,0.025,0.0,0.0,0.0,0.0,0.0
59-
petrol_spending,0,0.104,0.471,0.1,-0.148,-0.027,-0.018,-0.028,-0.03,-0.042,-0.056,-0.005,-0.004,-0.004,-0.004
59+
petrol_spending,0,0.104,0.481,0.099,-0.147,-0.031,-0.021,-0.032,-0.031,-0.043,-0.052,0.0,0.0,0.0,0.0
6060
private_pension_income,0,0.003,0.05,0.05,0.05,0.047,0.037,0.021,0.021,0.024,0.0,0.0,0.0,0.0,0.0
6161
private_transfer_income,0,0.0,0.092,0.05,0.037,0.028,0.029,0.031,0.033,0.033,0.0,0.0,0.0,0.0,0.0
6262
property_income,0,0.0,0.092,0.05,0.037,0.028,0.029,0.031,0.033,0.033,0.0,0.0,0.0,0.0,0.0

policyengine_uk_data/tests/test_road_fuel_volume_uprating.py

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,24 @@
3333
uprate_dataset,
3434
)
3535

36+
HOUSEHOLD_WEIGHT_INDEX_BEFORE_FUEL_CHANGE = [
37+
1.0,
38+
1.0,
39+
1.003,
40+
1.017,
41+
1.027,
42+
1.039,
43+
1.046,
44+
1.054,
45+
1.058,
46+
1.064,
47+
1.064,
48+
1.064,
49+
1.064,
50+
1.064,
51+
1.064,
52+
]
53+
3654

3755
def test__given_hmrc_outturn__then_road_fuel_volume_matches_petrol_plus_diesel():
3856
# Given/When
@@ -78,21 +96,29 @@ def test__given_pre_pandemic_base__then_obr_forecast_volume_declines():
7896
def test__given_uprating_table__then_only_fuel_rows_are_overridden():
7997
# Given
8098
df = pd.DataFrame(
81-
{year: [1.0, 1.0, 1.0] for year in range(START_YEAR, END_YEAR + 1)},
82-
index=["petrol_spending", "diesel_spending", "some_other_variable"],
99+
{year: [1.0, 1.0, 1.0, 1.0] for year in range(START_YEAR, END_YEAR + 1)},
100+
index=[
101+
"petrol_spending",
102+
"diesel_spending",
103+
"household_weight",
104+
"some_other_variable",
105+
],
83106
)
107+
df.loc["household_weight", 2024] = 1.2
84108

85109
# When
86110
out = _apply_road_fuel_litre_proxy_override(df.copy())
87111

88112
# Then
89113
for year in range(START_YEAR, END_YEAR + 1):
90114
assert out.loc["some_other_variable", year] == 1.0
115+
assert out.loc["household_weight", year] == df.loc["household_weight", year]
91116
for variable in VOLUME_OVERRIDDEN_VARIABLES:
92117
expected = fuel_spending_litre_proxy_index(
93118
variable=variable,
94119
base_year=START_YEAR,
95120
end_year=END_YEAR,
121+
household_weight_index=df.loc["household_weight"],
96122
)
97123
for year in range(START_YEAR, END_YEAR + 1):
98124
assert out.loc[variable, year] == round(expected[year], 3)
@@ -108,12 +134,26 @@ def test__given_storage_csv__then_fuel_rows_reflect_litre_proxy_index():
108134
variable=variable,
109135
base_year=START_YEAR,
110136
end_year=END_YEAR,
137+
household_weight_index=df.loc["household_weight"],
111138
)
112139
assert variable in df.index
113140
for year in range(START_YEAR, END_YEAR + 1):
114141
assert df.loc[variable, str(year)] == round(expected[year], 3)
115142

116143

144+
def test__given_storage_csv__then_household_weight_row_is_unchanged():
145+
# Given
146+
df = pd.read_csv(STORAGE_FOLDER / "uprating_factors.csv").set_index("Variable")
147+
148+
# Then
149+
assert (
150+
df.loc[
151+
"household_weight", [str(year) for year in range(START_YEAR, END_YEAR + 1)]
152+
].tolist()
153+
== HOUSEHOLD_WEIGHT_INDEX_BEFORE_FUEL_CHANGE
154+
)
155+
156+
117157
def test__given_lcfs_training_table__then_fuel_uprating_preserves_litre_proxy():
118158
# Given
119159
household = pd.DataFrame({variable: [1.0] for variable in IMPUTATIONS})

policyengine_uk_data/utils/uprating.py

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ def fuel_spending_litre_proxy_index(
8888
base_year: int = START_YEAR,
8989
end_year: int = END_YEAR,
9090
parameters=None,
91+
household_weight_index: dict[int, float] | pd.Series | None = None,
9192
) -> dict[int, float]:
9293
"""Return the spending-proxy index that preserves fuel litres.
9394
@@ -112,16 +113,38 @@ def fuel_spending_litre_proxy_index(
112113
parameters.household.consumption.fuel.prices,
113114
FUEL_PRICE_PARAMETER_NAME[variable],
114115
)
115-
population = parameters.gov.economic_assumptions.indices.ons.population
116116
base_price = price_parameter(base_year)
117-
base_population = population(base_year)
117+
118+
if household_weight_index is None:
119+
population = parameters.gov.economic_assumptions.indices.ons.population
120+
base_household_weight_index = population(base_year)
121+
122+
def household_weight_relative(year: int) -> float:
123+
return population(year) / base_household_weight_index
124+
125+
else:
126+
127+
def household_weight_value(year: int) -> float:
128+
if hasattr(household_weight_index, "index"):
129+
if year in household_weight_index.index:
130+
return float(household_weight_index.loc[year])
131+
return float(household_weight_index.loc[str(year)])
132+
try:
133+
return float(household_weight_index[year])
134+
except KeyError:
135+
return float(household_weight_index[str(year)])
136+
137+
base_household_weight_index = household_weight_value(base_year)
138+
139+
def household_weight_relative(year: int) -> float:
140+
return household_weight_value(year) / base_household_weight_index
141+
118142
return {
119143
year: (
120144
volume_index[year]
121145
* price_parameter(year)
122146
/ base_price
123-
* base_population
124-
/ population(year)
147+
/ household_weight_relative(year)
125148
)
126149
for year in volume_index
127150
}
@@ -141,10 +164,14 @@ def _apply_road_fuel_litre_proxy_override(df: pd.DataFrame) -> pd.DataFrame:
141164
for variable in VOLUME_OVERRIDDEN_VARIABLES:
142165
if variable not in df.index:
143166
continue
167+
household_weight_index = (
168+
df.loc["household_weight"] if "household_weight" in df.index else None
169+
)
144170
index = fuel_spending_litre_proxy_index(
145171
variable=variable,
146172
base_year=START_YEAR,
147173
end_year=END_YEAR,
174+
household_weight_index=household_weight_index,
148175
)
149176
missing_years = [
150177
year for year in range(START_YEAR, END_YEAR + 1) if year not in index

0 commit comments

Comments
 (0)