Euler step of one compartment from its inflows, outflows, births and deaths

Over a short step of length dt the number in a compartment changes by the flows into it from other compartments, less the flows out of it to other compartments, plus births or immigration into it, less deaths or emigration out of it, each held at its value at the start of the step. This is the article's balance equation for dx_j/dt advanced by one Euler step. Each internal flow leaves one compartment and enters another, so summed over all compartments the internal flows cancel and the population total changes only by births less deaths times dt, and stays fixed in a closed population (derived from the balance equation). Hethcote's endemic SIR model is a case with external flows, with births at rate mu N entering the susceptible class and deaths at rates mu S, mu I and mu R leaving the three classes, so that the population size stays constant. The SIR form of the step is HE-FM-CMPM-004.

Signature

x_next = x_now + (F_in - F_out + b - d) * dt
Inputs
InputsDefinitionUnit
x_nowNumber of people in the compartment at the start of the step, zero or abovepeople
F_inSum of the flows f_kj into the compartment from all other compartments, at the start of the steppeople per day
F_outSum of the flows f_jk out of the compartment to all other compartments, at the start of the steppeople per day
bFlow into the compartment from outside the model, such as births or immigrationpeople per day
dFlow out of the compartment that leaves the model, such as deaths or emigrationpeople per day
dtLength of the time step, in the time unit of the flowsdays
Output
x_nextNumber of people in the compartment at the end of the steppeople

Function

Compartment flow balance function of a compartmental model

Maps the numbers of people in the compartments of a population model, the flows between compartments per unit time and any inflow from or outflow to outside the model to the rate of change of each compartment, or, after a time step of length dt, to the next set of compartment counts. The flows can be fixed rates times compartment sizes, as in a static model, or can depend on the number infectious through the force of infection, which makes the model dynamic and nonlinear. A Markov cohort update (HE-FN-MM-001, HE-FM-MM-001) applies one fixed transition matrix to a closed cohort, the agent-based update HE-FN-ABM-001 with the per-contact infection probability HE-FM-ABM-001 follows individuals instead of pools, and a per-cycle probability from a constant rate follows HE-FM-TP-001. Reproduction numbers of the SIR model and of stratified models are in HE-FN-BRN-001 (HE-FM-BRN-001 to HE-FM-BRN-005 and HE-CF-BRN-001), and the final size of an epidemic and R_0 estimated from it are in HE-FN-ATR-001, HE-CF-ATR-001 and HE-FM-ATR-005, so none of them is restated here. Notation follows the Compartmental Model article.

Try this function

Implementations

  • Excel

    Euler step of one compartment from named flow cells

    With the start count in CompNow, the total inflow and outflow rates in InflowRate and OutflowRate, the external inflow and outflow in BirthInflow and DeathOutflow and the step length in StepLength, the first cell returns the count at the end of the step, held in a cell named CompNext. The second flags a step long enough to make the compartment negative.

    =CompNow+(InflowRate-OutflowRate+BirthInflow-DeathOutflow)*StepLength; =IF(CompNext<0,"step too long","ok")

Assumptions

  • Flows held constant within each step and steps short enough to keep compartments non-negative

    The Euler step treats every flow as constant over the step, as the article does with its one-day steps. The step has to be short relative to the time people spend in the compartment, so that F_out times dt stays below x_now plus the inflows over the step; a longer step can return a negative count. Pitman and colleagues note that the Euler method often used in spreadsheet models is less accurate than other numerical techniques.

Worked examples

  • Article's infectious compartment after day 1 without vaccination

    In the article's illustrative closed population, 29.7 new infections enter the infectious compartment on day 1 and 10 recoveries leave it, with no births or deaths, so the compartment ends the day with 119.7 people against 100 at the start.

    x_now = 100; F_in = 29.7; F_out = 10; b = 0; d = 0; dt = 1; x_next = 119.7
  • Illustrative susceptible compartment of an open population with births and deaths

    With illustrative births of 2 a day entering the susceptible compartment and deaths of 0.4 a day leaving it, the article's 29.7 day-1 infections leave 9,871.9 of the 9,900 susceptibles, against 9,870.3 in the closed population.

    x_now = 9900; F_in = 0; F_out = 29.7; b = 2; d = 0.4; dt = 1; x_next = 9871.9
  • Compartment with no flows left unchanged by an Euler step

    With every flow at zero the compartment keeps its count whatever the step length, a limiting case.

    x_now = 500; F_in = 0; F_out = 0; b = 0; d = 0; dt = 7; x_next = 500

Common errors

  • Internal flow taken from its source compartment but not added to its destination

    Each internal flow appears twice, as an outflow of one compartment and an inflow of another. Taking the article's 29.7 day-1 infections from the susceptibles but leaving them out of the infectious compartment gives 90 infectious people instead of 119.7 and a population of 9,970.3 instead of 10,000 after one day, a loss that a mass-balance check on the compartment totals catches at once.

Sources

  • Hethcote on the endemic SIR model with births and deaths

    Hethcote HW. The mathematics of infectious diseases. SIAM Review. 2000;42(4):599-653. Section 2.4, The Classic Endemic Model (pages 607 and 608), which gives the SIR model with births and deaths with S(t) + I(t) + R(t) = N, an inflow of newborns into the susceptible class at rate mu N and deaths in the classes at rates mu S, mu I and mu R, and states that the deaths balance the births so that the population size N is constant.

    View source →

Canonical Identity

Euler step of one compartment from its inflows, outflows, births and deaths | HealthEconomics.wiki