Signature
x_next = x_now + (F_in - F_out + b - d) * dt
| Inputs | Definition | Unit |
|---|---|---|
x_now | Number of people in the compartment at the start of the step, zero or above | people |
F_in | Sum of the flows f_kj into the compartment from all other compartments, at the start of the step | people per day |
F_out | Sum of the flows f_jk out of the compartment to all other compartments, at the start of the step | people per day |
b | Flow into the compartment from outside the model, such as births or immigration | people per day |
d | Flow out of the compartment that leaves the model, such as deaths or emigration | people per day |
dt | Length of the time step, in the time unit of the flows | days |
x_next | Number of people in the compartment at the end of the step | people |
|---|
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.
Canonical Identity
Stable URI · Machine-readable · Resolvable · CC BY 4.0
