Epidemic ModelingCore models

Module 3Compartmental models

The workhorse of epidemic modeling. We build the SIR model from its assumptions, derive R0, the epidemic threshold and the final-size relation, and see why epidemics stop before everyone is infected. Then we add boxes (births and deaths, reinfection, latency, infectious stages, hospital outcomes, age groups, mosquitoes), let transmission change with seasons, interventions and behavior, bring in chance with stochastic simulation and early extinction, and finish with the next-generation matrix, the general recipe for R0.

By the end you should be able to write and solve an SIR-family model, compute R0 and the final size, explain early extinction in stochastic models, and build a next-generation matrix for a model with several infected types.

Key ideas, one per episode

  • Ep. 7SIR from scratch: R0 = β/γ, growth needs S > 1/R0, and the epidemic stops before everyone is infected.
  • Ep. 8Births refill susceptibles, fading immunity brings waves back, and latency changes the timing, not the total.
  • Ep. 9Stages, outcomes, groups and vectors: hidden stages sustain spread, hospitals lag, and bites count twice.
  • Ep. 10β moves: seasons as a yearly wave, interventions as steps, behavior as feedback; R(t) is not R0.
  • Ep. 11Chance decides whether an outbreak takes off (about 1/R0 fizzle); the equations describe it if it does.
  • Ep. 12The next-generation matrix: R0 is its dominant eigenvalue, and it shows where transmission lives.

Textbook: Chapter 3 of T. Lazebnik, Epidemic Modeling: Principles, Algorithms, and Applications (Academic Press, 2026). The episodes and slides follow the chapter’s topics in our own words, figures and simulations; nothing is copied from the book.

The title slide of Module 3: Compartmental models

41 slides, written to be read on your own, with worked examples, “try it” boxes, our own small simulations and check-yourself questions (answers at the end). PDF, 0.9 MB.

Watch

6 short episodes for this module. Pick one from the list, and open the transcript to read along: each timestamp plays the episode from there. The narration is generated with a voice clone of Teddy, used with his permission.

Episode 7 · 4:32

SIR from scratch and the meaning of R₀

The workhorse of epidemic modeling, built from scratch: three boxes, five assumptions, two rates.

SIR from scratch: R0 = β/γ, growth needs S > 1/R0, and the epidemic stops before everyone is infected.

TranscriptEpisode 7
0:00

Compartmental models. Welcome to Module three. For the next six episodes, we build the field's workhorse: compartmental models. We start with the simplest one, the SIR model. Three boxes, two arrows, and a surprising amount of insight.

0:20

Three boxes, five assumptions. Split the population into three groups. Susceptible people can catch it. Infected people can pass it on. Removed people are out of the game: recovered, isolated, or dead. The basic model makes five simplifying assumptions. Everyone mixes with everyone, equally. New infections follow mass action. And nobody is born, dies of other causes, or moves away. Recovery gives permanent immunity. And the time someone stays infectious is random, with the same chance of recovering every day. None of these is literally true. They give us a clean baseline, and every later model relaxes one of them.

0:55

The SIR equations. Now the equations. Susceptible people become infected at rate beta, times S, times I. Infected people recover at rate gamma, times I. Beta packs two things together: how often people meet, and the chance that a meeting passes the infection on. One over gamma is the average time someone stays infectious. One choice matters more than it looks. Written like this, transmission grows with the size of the crowd. Divide by the population, and each person makes a fixed number of contacts, however big the town is.

1:27

R0, the threshold and the peak. At the start, almost everyone is susceptible, so each case infects about beta over gamma people in total. That's the basic reproduction number, R₀. In our run, beta is 0.3 per day, and people stay infectious for ten days. So R₀ is three. Another way to see it: ten contacts a day, a three percent chance of passing it on per contact, for ten days. Ten times 0.03 times ten is three. And R₀ is not speed. Early on, infections grow at rate beta minus gamma, 0.2 per day here, so they double about every three and a half days. Two diseases with the same R₀ can grow at very different speeds. Infections grow only while the susceptible share is above one over R₀. Here, one third. As susceptibles run out, the effective number, R₀ times the susceptible share, falls. It crosses one exactly at the peak. In our run, around day thirty eight. So the peak isn't when the virus gets tired. It's when there aren't enough susceptible people left for each case to replace itself.

2:30

Final size and overshoot. Here's the second surprise. The epidemic ends while some people were never infected. Take time out of the equations and you get the final size relation. The total share infected depends only on R₀. An R₀ of 1.5 infects about fifty eight percent. Two, about eighty percent. Three, about ninety four percent. And notice the overshoot. With R₀ three, herd immunity is reached when two thirds are immune, but the epidemic runs on to ninety four percent, because so many people are still infected at that moment. That gap matters for policy. Vaccinating two thirds before an outbreak prevents it. Reaching two thirds immune by infection costs another quarter of the town on top.

3:12

Counts can't go negative. One sanity check before we build bigger models: counts can't go negative. In the exact equations, they never do. S can only shrink toward zero, R only grows, and I can never cross below zero. So if your simulation shows a negative number of susceptible people, the model isn't wrong. Your numerical method is. Take ten-day steps with the simplest method, and S drops below zero. More in Module twelve.

3:35

What we observe. And in real life, we never see S, I and R. We see reported cases, hospital admissions and deaths. So applied models add an observation layer on top: only a share of infections gets reported, with delays and noise. The SIR flows stay the same; the layer links them to the data. Modules seven and eight live there.

3:55

Recap. So: three boxes, two rates. R₀ is beta over gamma, the threshold is a susceptible share of one over R₀, and the final size depends only on R₀. Next time, we add more boxes: births and deaths, reinfection, and a latent period.

Interactive lab

SIR-family builder and chance

Build SIR, SEIR, SIRS and seasonal models from the same controls, and run hundreds of stochastic outbreaks to compare chance with the equations.

The builder re-solves the equations as you change R0 and the boxes; the chance panel runs Gillespie simulations in your browser and compares the share of outbreaks that fizzle with the 1/R0 rule.

Simple math

One model, many boxes

Shares of a town, one in a thousand infected on day 0. Switch boxes on and off; the transmission rate β₀ is set so that R₀ is the value on the slider.

SIR
dS/dt = −β S I · dI/dt = β S I − γ I

γ = 1 / infectious period. Without other boxes, R₀ = β / γ and the epidemic stops while some people were never infected.

Extra boxes
S → E → I → R → S

Latency adds E (infected, not yet infectious). Waning immunity sends R back to S. Births and deaths (life 50 years) refill S.

Seasons
β(t) = β₀ (1 + a cos(2πt/365))

Transmission swings once a year, highest on day 0, 365, 730 and so on.

Peak infected
–
Peak day
–
Ever infected
–
Herd immunity 1 − 1/R₀
–

Solving…

All boxes

Shares of the town over time.

SEIR

Infected, zoomed

Marks: waves (peaks above 0.1%, at least 60 days apart).

Challenges

Each one is checked on your current settings, in the builder or in the chance panel below.

  1. Keep R₀ at 3, switch latency on, and push the peak past day 100.
  2. With waning immunity and seasons on, make every yearly wave after the first bigger than 15%.
  3. In the chance panel, with R₀ above 1, make more than 60% of runs fizzle.
Runs that fizzled
–
Theory (1/R₀) per first case
–
Big runs, average size
–
Equations’ final size
–

Running…

Final sizes

How many runs ended at each share infected (5% bins). A run that infects under 5% of the town counts as fizzled.