Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions changelog_entry.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- bump: minor
changes:
added:
- Add calibration target for babies under 1 in Scotland (~46k from NRS Vital Events)
1 change: 1 addition & 0 deletions policyengine_uk_data/storage/demographics.csv
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ scotland_age_60_69,person-k,ons_age_sex_region,,,,,691,702,714,727,741,755,767,,
scotland_age_70_79,person-k,ons_age_sex_region,,,,,506,520,534,546,557,565,575,,,
scotland_age_80_89,person-k,ons_age_sex_region,,,,,274,282,290,297,302,307,312,,,
scotland_children_under_16,person-k,nrs_mid_year_population_estimates,,,,,904,900,896,892,888,884,880,,,
scotland_babies_under_1,person-k,nrs_vital_events,,,,,46,46,46,46,46,46,46,,,
scotland_households_3plus_children,household-k,scotland_census_2022,,,,,82,82,82,82,82,82,82,,,
south_east_age_0_9,person-k,ons_age_sex_region,,,,,1047,1044,1042,1039,1034,1028,1024,,,
south_east_age_10_19,person-k,ons_age_sex_region,,,,,1122,1119,1117,1114,1108,1102,1097,,,
Expand Down
35 changes: 35 additions & 0 deletions policyengine_uk_data/tests/test_scotland_babies.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""Test Scotland babies under 1 calibration target.

Source: NRS Vital Events Reference Tables 2024
https://www.nrscotland.gov.uk/publications/vital-events-reference-tables-2024/
Scotland had 45,763 live births in 2024.
"""

import pytest


@pytest.mark.xfail(
reason="Will pass after recalibration with new scotland_babies_under_1 target"
)
def test_scotland_babies_under_1(baseline):
"""Test that babies under 1 in Scotland matches NRS birth statistics.

Target: ~46,000 babies under 1 (based on ~46k annual births)
Source: NRS Vital Events 2024 reports 45,763 births
"""
region = baseline.calculate("region", map_to="person", period=2025)
age = baseline.calculate("age", map_to="person", period=2025).values
person_weight = baseline.calculate(
"person_weight", map_to="person", period=2025
).values

scotland_babies = (region.values == "SCOTLAND") & (age < 1)
total_babies = (person_weight * scotland_babies).sum()

TARGET = 46_000 # NRS Vital Events 2024: 45,763 births
TOLERANCE = 0.15 # 15% tolerance

assert abs(total_babies / TARGET - 1) < TOLERANCE, (
f"Expected ~{TARGET/1000:.0f}k babies under 1 in Scotland, "
f"got {total_babies/1000:.0f}k ({total_babies/TARGET*100:.0f}% of target)"
)
9 changes: 9 additions & 0 deletions policyengine_uk_data/utils/loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,15 @@ def pe_count(*variables):
scotland_children_under_16
)

# Babies under 1 in Scotland
# Source: NRS Vital Events - births registered in Scotland
# https://www.nrscotland.gov.uk/publications/vital-events-reference-tables-2024/
# ~46,000 births per year (45,763 in 2024)
scotland_babies_under_1 = (region == "SCOTLAND") & (age < 1)
df["ons/scotland_babies_under_1"] = household_from_person(
scotland_babies_under_1
)

# Households with 3+ children in Scotland
# Source: Scotland Census 2022 - Household composition
# https://www.scotlandscensus.gov.uk/census-results/at-a-glance/household-composition/
Expand Down