Repository navigation
Start the population projection from the last year of population data - #1295
Open
arihantlodha-cmd wants to merge 1 commit into
Open
arihantlodha-cmd wants to merge 1 commit into
arihantlodha-cmd wants to merge 1 commit into
Conversation
The population data have one more year than the rates, but the projection started from year T0 - 1, so with UN data it replaced data year T0 with a step using the extrapolated rates while rho and imm_rates list the year T0 - 1 rates. When mortality changes in the last data year the population breaks its law of motion in that period, which shows up as a resource constraint error in period 2 of the transition. Adds a test that the path follows its law of motion in every period before fixper.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1295 +/- ##
==========================================
+ Coverage 80.10% 80.17% +0.06%
==========================================
Files 24 24
Lines 7208 7208
==========================================
+ Hits 5774 5779 +5
+ Misses 1434 1429 -5
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
This branch has not been deployed
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.
What this fixes
get_pop_objsbuilds the population path from data years, then projects forward with constant rates:The population data have one more year than the rates, which map each year into the next. That is T0 + 1 years with user-provided data, and T0 + 2 with UN data, whose fertility, mortality, and immigration rates run from
start_data_yeartofinal_data_year, i.e. T0 + 1 years. With UN data, the first projected step (year T0 - 1 to T0) therefore usesmort_rates[-1](= the year T0 rates), while therhoarray the model aggregates with lists the year T0 - 1 rates for that step.imm_rates[T0 - 1]was solved to be consistent with the year T0 - 1 mortality. When mortality changes in the last data year, the population path breaks its own law of motion in that one period:This change starts the projection from the last data year (
pop_2D[len_pop_dist - 1]), keeping all data years. With user-provided data, where the rates cover T0 years, the path is the same as before, because the old first step reproduced data year T0 exactly.How it showed up
In OG-JPN (Japan, UN data,
initial_data_year = start_year - 1), every transition had a resource-constraint error of 1.5e-3 of GDP in period 2, with the rest of the path below 1e-6 apart from thefixperperiod (#1290). Checking the law of motion on the model's ownomega,rho,imm_rates, andg_n, the residual is 1e-17 in every period except t = 1 → 2 (1.9e-5) and the fixper period.With this change, on the same calibration:
Tests
Adds
test_pop_path_follows_its_law_of_motion. It mimics the UN path without network access, monkeypatchingget_fert,get_mort, andget_popto return rates for 3 years and population for 4, with mortality falling in the last year. It then checks the law of motion in every period beforefixperto 1e-12. The test fails on master and passes with the change. The other non-localdemographics tests pass.