Skip to content

Bug in computing the pre-time-path population #1070

@jdebacker

Description

@jdebacker

The ogcore.demographics module computes the population over the time path, but also needs the population distribution in the year before the time path begins. This is inferred and there seems to be an error constructing this when using certain population distributions (e.g., that from Ethiopia).

@claude is suggesting the following issues and fixes:
I've found the root cause of the infeasible growth rates. Here's
the complete analysis:

Root Cause: Backward Population Solver Produces Negative Values

The Problem:
When ogcore.demographics calculates the pre-period population (2023) by
solving backwards from 2024, it encounters a mathematical impossibility
with Ethiopia's demographic structure, particularly at very old ages
(93-99).

Why This Happens

The demographic equation is:
pop_current[age] = pop_previous[age-1] * survival_rate + pop_previous[age]

  • imm_rate

When solving backwards for pop_previous[age]:
pop_previous[age] = (pop_current[age] - survived_from_previous_age) /
imm_rate

The bug occurs when:

  • More people survive from age N-1 than exist at age N in the current
    period
  • Immigration rate is positive
  • Result: pop_previous[age] becomes hugely negative

Specific Examples from Ethiopia

At age 99:

  • Current population (2024): 189 people
  • People surviving from age 98: 365,692,350 (366 million!)
  • Immigration rate: +19.9% (positive)
  • Solved pre-population: -1.8 BILLION ❌

This creates a mathematical impossibility. The equation needs a negative
population to make the immigration math work, but negative populations
don't exist.

The Impact

This causes:

  1. 76 out of 80 working-age groups to have negative omega_S_preTP values
  2. omega_S_preTP ranges from -0.59 to +1.49 (should be all positive,
    summing to 1.0)
  3. Growth rate g_n[0] = -105.3% (< -100%, which is impossible)

Why Ethiopia but not South Africa?

Ethiopia has:

  • Very young, rapidly growing population (high fertility)
  • Steep population decline at old ages
  • The backward solver hits this edge case

South Africa has:

  • More balanced age distribution
  • Slower population changes
  • The backward solver works fine

Recommendations

demographics.py:1006-1033 - The pre_pop_solve() function needs to be
fixed. Options:

  1. Use actual historical data instead of solving backwards (best solution)
  2. Add constraints to prevent negative population values in the solver
  3. Use different immigration assumptions for backward vs forward solving
  4. Skip the backward solve and use forward data from get_pop() which
    already retrieves 2023 data

The good news: The UN data itself is perfectly fine. This is purely an
ogcore.demographics implementation issue in how it initializes the
pre-transition period population.

cc @rickecon

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions