15.2 Predator–Prey & Competing Species ended on a coupling: a product of two populations, a conserved quantity, a threshold that decides who invades. An epidemic is the same machinery with the roles changed. Susceptibles meet infectious people at a rate proportional to , which is mass-action again, and the infectious recover into a class that cannot be infected twice. There is no predator to starve, so no cycle: the susceptibles are only used up. What replaces the oscillation is a threshold and a final size, and both come out of one conserved quantity.
Transcript
- Last lesson ended on a promise, so let us cash it. Susceptibles S and infectious people I meet at a rate proportional to the product S times I, which is mass action again. The equations are S prime equals minus beta S I, I prime equals beta S I minus gamma I, and R prime equals gamma I. Take beta 0.4, gamma 0.2 and a seed of 0.001. Dividing dI by dS separates the variables, and Q equals I plus S minus one over R 0 times ln S is conserved. It starts at 1.000500, and over 300 days it drifts by only 6 times 10 to the minus 13.
- Factor the second equation: I prime equals I times beta S minus gamma. Infection grows exactly when beta S exceeds gamma. At the start S is about 1, so R 0 equals beta over gamma, the number of people one infectious person infects in a wholly susceptible population. Here R 0 is 2. Early on I grows like e to the beta minus gamma times t, with a doubling time of 3.47 days, and I first reaches 0.01 on day 11.7. Then I peaks exactly when S equals 1 over R 0, and falls afterwards. This is last lesson's invasion test again.
- Now the peak. At the peak S equals 1 over R 0, so set Q there equal to Q at the start and solve. I max equals I 0 plus S 0 minus one plus ln of R 0 S 0, all over R 0. For R 0 equal to 2 the formula gives 0.153927. The run peaks at 0.153926 on day 33.8, when S is 0.4996, and an independent scipy integration agrees at 0.153927.
- How far does it go? The epidemic ends when I returns to 0, and Q at the end gives ln of S 0 over S infinity equals R 0 times 1 minus S infinity. This is transcendental: no elementary formula. But g is convex and decreasing left of 1 over R 0, so Newton's method from the left converges monotonically. For R 0 equal to 2 the iterates are 0.185561, 0.201935, 0.203181, 0.2031879 and 0.20318787. So S infinity is 0.203188, and 79.7 percent are infected, although the herd immunity threshold is 0.5: 15 percent are still infectious when S passes 1 over R 0.
- Vaccinating a fraction v starts those people in R. An outbreak is impossible when R 0 S 0 is at most 1, so v must reach 1 minus 1 over R 0: 50 percent for R 0 equal to 2. Short of that, vaccination still helps. With 30 percent vaccinated the peak falls from 0.1539 to 0.0325 and arrives on day 61.9. With 40 percent it is 0.0097, on day 87.9. At 50 percent there is no outbreak.
- Distancing lowers beta. Cut it to 0.6 beta on day 30, so the new R 0 is 1.2. On day 30 the epidemic is at its peak, I is 0.1401, and R 0 prime times S is 0.752, below 1, so infection falls. Restarting the final-size equation from that state gives S infinity of 0.40695: 59.3 percent infected instead of 79.7. The same cut on day 60, when the epidemic is almost over, leaves 79.0 percent. Timing matters.
- Now add a latent class E, with rate sigma. The final-size derivation never used sigma, so the final size is unchanged, 79.7 percent. What changes is timing. Linearising gives a growth rate of 0.0922 for a four-day latent period, against 0.2000 without it. The peak is lower, 0.0848 against 0.1539, and later, on day 71.1 instead of 33.8. And I first reaches 0.01 on day 32.3, instead of 11.7.
- Add births and deaths at rate mu and the epidemic need not end. With mu equal to 0.01, R 0 is 1.905, and the endemic point has S star 0.525 and I star 0.022619. The trace of the Jacobian is minus 0.019048 and the determinant is 0.0019, so the eigenvalues are minus 0.009524 plus or minus 0.042536 i: a stable spiral. The period is 2 pi over 0.042536, or 147.7 days, and the run measures 146.7. The epidemic rings, and the ringing dies out with e-folding time 105 days.
- SIR is a reaction network written as differential equations: S plus I makes 2 I at rate beta S I, and I becomes R at rate gamma I. That product is the law of mass action, and the next lesson on chemical kinetics builds on it: rate constants, equilibrium, Michaelis-Menten saturation. One warning. Here beta and gamma differ by a factor of two, so RK4 at 0.05 days is far from its stability limit. In chemistry rate constants differ by many orders of magnitude, and that is stiffness.
The SIR model
Take the population as fractions, , and time in days. Each infectious person makes contacts that infect a susceptible at rate per day, and recovers at rate , so the infectious period averages :
The three equations sum to , so can be dropped: the dynamics live in the plane. We use and per day and a seed throughout (teaching values, not fitted to any disease).
The threshold. Factor the second equation: . Infection grows iff . At the start , so define the basic reproduction number
the number of people one infectious person infects in a wholly susceptible population: per day, over days. With below the relevant number is the effective reproduction number . Then rises while , peaks exactly when , and falls afterwards. Here . In the linearised early phase , a doubling time of days, and in the full run first reaches on day (sim and scipy agree).
This is the invasion test of the last lesson: a rare newcomer grows iff its per-capita growth rate, here , is positive.
The conserved quantity
Divide the equations, as for Lotka-Volterra:
This separates, and integrating gives
Check by differentiating: . For the run above, at the start and the largest deviation over days is for RK4 with step (scipy gives ). Unlike the Lotka-Volterra , this has no interior minimum: its level sets are arcs from the start, over the line , down to the axis .
Peak prevalence. At the peak, . Equate there to at the start:
For , the formula gives , the sim’s RK4 run on day (at ), and scipy at tolerance gives at .
The final-size relation
The epidemic ends when . Where does stop? The conserved quantity again, now at the end of the run, where :
Rearranged, and using with no one vaccinated,
This is transcendental: appears both inside a logarithm and linearly, so there is no elementary closed form (the Lambert W function solves it, from memory). Solve it numerically. Let . Then and : on the function is convex and decreasing, positive near and negative at (it equals there). So exactly one root lies below and Newton’s method started from the left converges monotonically, because every tangent of a convex decreasing function undershoots the root. A good left start is .
For and the iterates are , , , , (sim); an independent bracketing root-finder (scipy brentq) gives . So of the population is infected. With the seed the root is and the ODE run ends at , so again. Newton takes steps to reach (sim).
| final size | peak | herd threshold | |
|---|---|---|---|
All rows use . Each final size was checked two ways, Newton in the sim and the end of a long scipy integration, which agree to . The peak column is the formula, checked against an integrated peak for only.
The overshoot. At the peak occurs when half the population has been infected, yet the epidemic ends with . When passes the number currently infectious is of the population, and those people keep infecting for a while after the growth has stopped. Reaching the tipping point is not the same as stopping there.
Herd immunity and vaccination
Vaccinate a fraction before the epidemic: they start in , so and the effective number is . An outbreak is impossible iff , that is
the herd-immunity threshold: each case then infects fewer than one other. For that is ; for , . The final-size relation becomes , which is how the sim computes the table below.
| peak (day) | ever infected | ||
|---|---|---|---|
| (day ) | |||
| (day ) | |||
| (day ) | |||
| no outbreak | |||
| no outbreak |
(Sim and scipy agree on every entry. “Ever infected” counts everyone who leaves , seed included; “no outbreak” means never exceeds .) Vaccinating and , short of the threshold, shrinks the peak by factors of and and delays it by weeks.
Changing beta mid-course
Distancing and masks lower . Suppose drops to on day , so the new reproduction number is . At day the epidemic is at its peak (, , , so ), and infection falls from there. The conserved quantity changes at the jump, but the final-size argument can be restarted from the state at day with the new constant: . Solving gives , and the full ODE run ends at too. So are infected instead of .
Timing matters. The same cut on day , when the epidemic is almost over (, ), leaves the peak at and the final size at : the intervention came too late to matter.
SEIR: a latent period
After exposure a person is infected but not yet infectious. Add a class with rate (mean latent period ):
What does not change. The derivation of the final size used only and , so is unchanged for the same : latency delays but does not reduce the number infected. In the runs below the final size is for latent periods of and days alike.
What does. Linearise the block at . The matrix has the growth rate
which tends to as and is smaller otherwise.
| latent period | growth rate | peak | day of peak |
|---|---|---|---|
| none (SIR) | |||
| days | |||
| days | |||
| days |
(Growth rates from the formula and numpy; peaks from the sim and scipy, agreeing to four digits.) With a four-day latent period the infectious fraction reaches on day instead of : slower to start, later and flatter at the peak, the same endpoint.
Births, waning immunity and the endemic state
If the population is replenished the epidemic need not end. Let births and deaths both occur at rate (a constant population), with newborns susceptible:
Now . For there is an endemic fixed point. Setting gives , and then gives . The Jacobian there, with , is
(Since , the trace is , and .) The determinant is positive whenever and the trace is negative, and for small we have : a stable spiral. The epidemic rings, and the ringing dies out.
With , and : , , , trace , determinant and eigenvalues (sim and numpy). The period of the ringing is days; the long ODE run measures between the last two upward crossings before day , the small difference being the nonlinearity of the first cycles. Amplitudes shrink with -folding time days. The first epidemic peaks at on day (against without births), falls to a trough of and then recovers.
Since , the period is close to where is the infectious period and is the average age at infection (Anderson and May’s interepidemic period, from memory; here ). SIRS, with immunity that wanes at rate , behaves similarly: it keeps and an endemic prevalence (algebra from , ).
What the model leaves out
- Heterogeneity. Everyone mixes equally. Real contact rates vary enormously, and a few high-contact people drive transmission; this lowers the final size and herd threshold below the formulas above (from memory) and replaces by a matrix of contact rates.
- Networks and space. Contacts form a graph with clusters, so early growth is slower and patchier than .
- Stochasticity. With a handful of people, new cases are random. An outbreak with can die out by chance (a branching-process estimate for one seed case is , from memory), and the model also cannot show endemic fade-out.
- Fixed parameters. and change with behaviour and season.
Treat every number here as a property of these equations, not a forecast. The value is calibration: threshold, overshoot, sensitivity to timing.
The exercise: final size by Newton, and the endemic eigenvalues
The playground runs SIR and SEIR with RK4. In the exercise you implement the final-size solver, the peak formula, the endemic point and its eigenvalues; the tests are table entries.
Concept checks
Problems
Take , and an infinitesimal seed (, ). Find , the herd-immunity threshold, the peak prevalence, and use one Newton step from to estimate in (the exact root is ).
Show worked solution
, the threshold is , and the peak is (at ). For Newton, , and , so . Repeating once more brings it to (the verified root is : infected, far above the threshold).
For a vaccine protects a vaccinated person fully with probability and not at all otherwise. What coverage is needed for herd immunity? What does the answer say about a vaccine that works on half of the people?
Show worked solution
The immune fraction is and must reach , so . For efficacy the requirement is : even vaccinating everyone cannot reach the threshold, and the disease persists at a lower level. In general , which can exceed .
With a fraction vaccinated at the start and , show that with , and that (no outbreak) when .
Show worked solution
From we get , since the vaccinated start at . At the end , so . Let , so and . If , is convex and decreasing on , so below and the only root is itself. If , then at , just to its left, and a second root exists: the epidemic.
Keep , and take . Find , the endemic point, the trace and determinant of the Jacobian, the eigenvalues and the period of the damped oscillation. Compare the period with the value for ( days).
Show worked solution
and , . The trace is and the determinant is . Then : a stable spiral with eigenvalues (numpy agrees). The period is days, shorter than days, and the damping is nearly twice as fast: decay rate against .
What comes next
SIR is a reaction network written as differential equations: at rate and at rate . The product is exactly the law of mass action of chemistry, where the rate of is proportional to the product of concentrations, and 15.4 Chemical Kinetics & Stiff Systems builds on it: rate constants, equilibrium, Michaelis-Menten saturation. One honest warning. Here and differ by a factor of two, so RK4 at days is far from its stability limit. In chemistry rate constants can differ by many orders of magnitude (the Robertson problem, from memory), a fast reaction forces tiny steps long after it has finished, and that is stiffness, see 4.5 Stability Regions & Stiffness.
Key Takeaways
- SIR with mass action: grows iff with , and peaks when ; there are no cycles because only decreases.
- is conserved (checked to ), which gives the peak .
- The final size solves the transcendental equation , by Newton from the left or bisection: for .
- The final size overshoots the herd-immunity threshold : infection continues after the peak.
- Vaccination below the threshold still flattens and delays the epidemic; reducing helps only if it happens early (day : infected; day : ).
- SEIR has the same final size but a smaller growth rate and a lower, later peak ( on day for a four-day latent period).
- With births the endemic point is a spiral sink with trace and determinant : a damped oscillation of period days for .
- The model ignores heterogeneity, networks and chance at small ; the same law reappears as mass action in chemistry.