Interactive SIR/SEIR outbreak simulation — how R₀, vaccination, and treatment reshape the epidemic curve and hospital burden
Every compartmental epidemic model starts from a deceptively simple idea, first formalized by Kermack and McKendrick in 1927: divide a population into Susceptible, Infectious, and Recovered boxes, and let differential equations describe the flow between them. The single number that governs whether an outbreak takes off or dies out — the basic reproduction number R₀ — falls directly out of this framework.
The SIR model tracks three mutually exclusive states as functions of time t:
• S(t) — Susceptible: individuals who can catch the disease • I(t) — Infectious: individuals currently infected and capable of transmitting • R(t) — Recovered (or removed): individuals who have recovered with immunity, or died — either way, no longer part of transmission
The governing ordinary differential equations (with population N = S+I+R held constant):
dS/dt = −β S I / N dI/dt = β S I / N − γ I dR/dt = γ I
β is the transmission rate (contacts per unit time × probability of transmission per contact); γ is the recovery rate, with 1/γ equal to the mean infectious period. Every new infection is drawn out of S and into I at rate βSI/N — the mass-action term that assumes well-mixed random contact, exactly what the particle simulation on this page animates directly: dots wandering, colliding, and converting color on contact.
Kermack and McKendrick's 1927 paper proved the "threshold theorem": an epidemic can only grow if the susceptible fraction exceeds a critical value. This single insight — 100 years old — still underlies every modern outbreak model, from COVID-19 dashboards to pandemic-preparedness simulations.
R₀ = β/γ is the expected number of secondary infections produced by a single infectious individual in an entirely susceptible population. It is the single most consequential number in epidemiology because it sets the qualitative behavior of the whole system:
• R₀ < 1 — each case produces less than one new case on average; the chain of transmission shrinks and dies out • R₀ = 1 — endemic equilibrium; cases neither grow nor shrink • R₀ > 1 — exponential growth; every generation of infection is larger than the last
Early in an outbreak, when S ≈ N, the growth of infectious cases is approximately exponential: I(t) ≈ I₀ e^{(β−γ)t} = I₀ e^{γ(R₀−1)t}. This is why the first weeks of any new outbreak look deceptively slow, then suddenly explosive — exponential curves are flat until they are not.
Historical R₀ estimates vary enormously by disease: measles 12–18, smallpox 5–7, SARS-CoV-2 (original Wuhan strain) ≈2.5–3, Delta variant ≈5–8, Omicron ≈8–10, seasonal influenza ≈1.2–1.4, Ebola ≈1.5–2.5. R₀ is not a fixed biological constant — it depends on contact rates, population density, and behavior, which is exactly why lockdowns and mask mandates work: they lower the effective β, and therefore the effective R.
The canvas above runs two synchronized but independently computed views of the same process. In the upper particle field, ~130 agents perform a bounded random walk. Each Infectious (red) agent has an infection radius; any Susceptible (blue) agent that wanders inside it has a per-frame chance of transmission, calibrated so that higher R₀ produces visibly faster, denser color-changes. This is a literal, stochastic, individual-based realization of the same mass-action assumption baked into βSI/N.
Below it, the analytical S/I/R curves are produced by numerically integrating the ODEs above using fourth-order Runge–Kutta (RK4) — the same numerical method used in professional epidemic-modeling software (e.g. compartmental cores inside CDC/ECDC forecasting hubs) because it is far more accurate per step than simple Euler integration for stiff, fast-changing systems like early exponential growth.
Most real pathogens do not make a person infectious the instant they are infected. There is a latent (incubation) period during which the pathogen is replicating inside the host but has not yet reached transmissible levels. Adding this Exposed compartment — turning SIR into SEIR — dramatically changes both the shape of outbreaks and how contact tracing and quarantine can interrupt them.
SEIR splits "infected" into two stages: Exposed (infected, not yet infectious) and Infectious (can transmit). The system becomes:
dS/dt = −β S I / N dE/dt = β S I / N − σ E dI/dt = σ E − γ I dR/dt = γ I
σ is the rate of progression from exposed to infectious, with 1/σ equal to the mean incubation (latent) period — exactly the slider on this page. R₀ is still β/γ in the simplest SEIR formulation (the exposed period does not change the total number of secondary infections one infectious case eventually causes — it only delays when transmission starts), but it profoundly changes the epidemic's timing and controllability.
A long incubation period is a double-edged sword: it gives contact tracers more time to find and quarantine exposed contacts before they become infectious, but it also means an outbreak can spread silently and widely before anyone shows symptoms — exactly what made COVID-19 so hard to contain compared to, say, Ebola, which has a shorter serial interval and more overt early symptoms.
The incubation period reflects how long a pathogen needs to replicate to a transmissible viral/bacterial load, and where in the body it must travel to reach transmission-ready tissue:
• Influenza (~2 days): replicates explosively in upper respiratory epithelium; short generation time • SARS-CoV-2 (~5 days, wide range 2–14): replicates in respiratory tract; variants shortened this considerably (Omicron ≈3 days vs original strain ≈5–6 days) • Measles (10–12 days to rash, infectious ~4 days before rash): must disseminate systemically via lymphatics before returning to the respiratory tract for transmission • Ebola (mean ≈9 days, range 2–21): requires substantial systemic viral replication before symptomatic, contagious illness • Smallpox (~12 days): similarly systemic before the infectious rash phase
On this page, moving the "Incubation Period" slider directly changes σ = 1/incubation days. Watch how a longer incubation period stretches out the amber (Exposed) phase for each particle before it turns red — and note it also delays, but does not eliminate, the eventual epidemic peak in the analytical curve below.
Two related but distinct quantities matter for real-world outbreak response:
• Generation time — the average time between when a person is infected and when they infect someone else. Roughly incubation period + a fraction of the infectious period. • Serial interval — the observable time between symptom onset in a primary case and symptom onset in a secondary case (easier to measure from surveillance data than generation time).
Short generation times (flu, ~3 days) mean epidemics can double very fast even at modest R₀, leaving little time to react. Long generation times (measles, ~11–12 days) mean slower case-count growth per calendar day even though R₀ is far higher — control interventions have more calendar time to take effect per generation, but each missed generation compounds a much larger multiplier.
Plotting S, E, I, and R against time reveals the full shape of an outbreak: a rising phase, a peak, and a falling phase — even with zero intervention. The peak occurs at a precise, calculable point: the moment the susceptible fraction drops to exactly 1/R₀. Beyond that point, herd immunity is doing the work, and the epidemic shrinks on its own.
The epidemic peak is not a coincidence of running out of people to infect — it happens precisely when dI/dt = 0, i.e. σE = γI at the E→I flow balance, and more fundamentally when the growth term itself flips sign. Using dI/dt = σE − γI together with dS/dt = −βSI/N, the peak of infectiousness occurs exactly when:
S(t) / N = 1 / R₀
This is the single most important geometric fact about any compartmental epidemic curve: the peak is not at S=0, it is at S = N/R₀. After that point, even though plenty of susceptible people remain, there are no longer enough of them, relative to R₀, for the outbreak to keep accelerating — each infectious person now infects fewer than one new person on average, purely due to herd immunity accumulated so far.
This is why an unmitigated epidemic never infects 100% of a population. The final-size relation (also derivable from the SIR equations) shows that even with no intervention at all, a meaningful susceptible remainder survives every outbreak — for R₀=3, roughly 6% of the population is mathematically never infected, purely due to epidemic self-limitation via herd immunity, not luck.
The herd immunity threshold (HIT) is the fraction of the population that must be immune (via infection or vaccination) for R_effective to fall to 1, halting sustained transmission:
HIT = 1 − 1/R₀
This single formula explains why some diseases require near-universal vaccination while others do not:
• Measles: R₀ ≈ 12–18 → HIT ≈ 92–95%. This is why measles vaccination coverage below ~95% reliably produces outbreaks — it is one of the least forgiving diseases in public health. • Smallpox: R₀ ≈ 5–7 → HIT ≈ 80–86%, achieved through the WHO global eradication campaign (last natural case, 1977). • Polio: R₀ ≈ 5–7 → HIT ≈ 80–85%, the target of ongoing global eradication efforts. • COVID-19 (original strain): R₀ ≈ 2.5–3 → HIT ≈ 60–67%. Later, more transmissible variants (Delta R₀≈5–8, Omicron R₀≈8–10) pushed the naive HIT toward 80–90%, a major reason COVID-19 herd immunity via vaccination proved elusive — immune evasion and waning immunity compounded the problem further. • Seasonal influenza: R₀ ≈ 1.2–1.4 → HIT ≈ 17–29%, one reason flu remains endemic at manageable levels without eradication efforts.
The lower panel numerically integrates the SEIR system with RK4 across a 240-day horizon every time you move a slider, then redraws all four compartment curves as the animation plays a moving "day" marker across it. A dashed horizontal line marks S = N/R₀ — the herd immunity threshold level — so you can watch the Infectious curve peak exactly where the Susceptible curve crosses that line. Push R₀ up and watch the peak arrive earlier, higher, and sharper; push it toward 1 and watch the whole epidemic flatten into a long, low ripple that barely registers as an outbreak at all.
| Product | Indication | Trial Design | Key Result |
|---|---|---|---|
| Measles | R₀ ≈ 12–18 | Airborne, extremely stable virus, long infectious aerosol persistence | HIT ≈ 92–95% |
| Smallpox (historical) | R₀ ≈ 5–7 | Respiratory droplet + direct contact, eradicated via vaccination 1980 | HIT ≈ 80–86% |
| Polio | R₀ ≈ 5–7 | Fecal-oral transmission, mostly asymptomatic carriage | HIT ≈ 80–85% |
| COVID-19 (Omicron) | R₀ ≈ 8–10 | Airborne, immune-evasive spike protein, short generation time | HIT ≈ 89–90% |
| Seasonal influenza | R₀ ≈ 1.2–1.4 | Respiratory droplet, seasonal antigenic drift | HIT ≈ 17–29% |
Vaccination works, in model terms, by moving people directly from Susceptible into Recovered/immune before the outbreak ever reaches them — without anyone having to get sick. This single mechanism is what allows public health systems to suppress R_effective below 1 even while R₀ (an intrinsic property of the pathogen and contact behavior) stays exactly the same.
Vaccinating a fraction v of the population before an outbreak begins effectively re-labels those individuals as Recovered/immune from t=0, changing initial conditions to S(0) = N(1−v), R(0) = Nv (for a perfect vaccine). The effective reproduction number becomes:
R_eff = R₀ × S(0)/N = R₀ × (1 − v)
Setting R_eff = 1 and solving for v recovers exactly the herd immunity threshold: v* = 1 − 1/R₀. This is the same HIT formula from Stage 3 — vaccination is simply the deliberate, controlled way of reaching that threshold without paying the price of mass infection.
Vaccination and natural-infection-acquired immunity are mathematically interchangeable in the basic model — both move people from S to R. The entire ethical and public-health case for vaccination is that it achieves the same herd-immunity mathematics without the deaths, long-COVID-style sequelae, and hospital strain that natural-infection immunity would require.
Real vaccines are not 100% effective. If a vaccine has efficacy VE (the fraction of vaccinated people who are fully protected), then the coverage needed for herd immunity increases:
v_required = HIT / VE = (1 − 1/R₀) / VE
For measles (HIT≈95%) with the highly effective MMR vaccine (VE≈97% after two doses), required coverage is still ≈95–98% — extremely demanding, and exactly why local MMR coverage dips below ~95% reliably trigger outbreaks (as seen repeatedly in under-vaccinated communities worldwide).
For COVID-19, original mRNA vaccines had VE≈90–95% against the ancestral strain, but efficacy against infection (as opposed to severe disease) waned over months and dropped substantially against Delta and especially Omicron due to immune escape — while R₀ simultaneously rose with each new variant. The combined effect (rising R₀, falling effective VE) is why COVID-19 herd immunity via vaccination alone proved mathematically much harder to reach than for measles or polio, and why "vaccination debated as HIT strategy" became a genuine, contested scientific question rather than settled arithmetic.
The particle field above demonstrates this directly: move the vaccination slider up and a share of agents begin the simulation already green (Recovered/immune) rather than blue (Susceptible). Even unvaccinated (still-blue) agents benefit — they are now surrounded by a higher density of immune neighbors, so their own individual chance of ever encountering an infectious contact drops. This indirect protection is what shields infants too young to vaccinate, immunocompromised patients for whom vaccines are less effective, and the small percentage for whom a vaccine simply does not "take" — herd immunity is a genuinely collective, non-individual good, which is also precisely what makes coordinating it a hard policy problem.
Even without eliminating an outbreak, two levers change the equations enough to save lives: antiviral treatment that shortens the infectious period (raising γ) or reduces transmissibility, and non-pharmaceutical interventions (masking, distancing, closures) that reduce contact rate β. Both lower R_effective — but the most immediately visible consequence for a hospital system is keeping the Infectious curve's peak under the capacity line.
Since R₀ = β/γ, there are exactly two multiplicative levers to bring R_effective below 1 without vaccination:
1. Reduce β (transmission rate): masks, physical distancing, ventilation improvements, isolation of cases, and school/venue closures all reduce the effective contact rate or the probability of transmission per contact. This is the mechanism behind essentially all non-pharmaceutical interventions (NPIs).
2. Increase γ (recovery/removal rate): antiviral drugs that shorten how long a person remains infectious pull people out of the Infectious compartment faster. Oseltamivir (Tamiflu) for influenza and nirmatrelvir/ritonavir (Paxlovid) for COVID-19 both reduce viral load and duration of infectiousness when given early, which — at a population level — is mathematically identical to raising γ in the model.
On this page, selecting this stage raises γ from 1/7 to 1/5 per day (a 7-day infectious period cut to 5 days), directly reducing R₀'s realized value and reshaping the curve, exactly mirroring how early antiviral treatment shrinks an outbreak even without changing anyone's susceptibility.
Paxlovid clinical trials (EPIC-HR, 2021) showed an 89% relative reduction in hospitalization or death among high-risk, unvaccinated COVID-19 patients treated within 5 days of symptom onset — one of the most effective outpatient antiviral results in modern infectious disease medicine, driven largely by shortening and blunting the infectious/severe-disease window.
"Flatten the curve" became the defining visual of the COVID-19 pandemic response, but the underlying logic predates it by over a decade — it originates in 2007 CDC pandemic-influenza community mitigation guidance. The idea: total cumulative infections may be similar with or without intervention, but spreading them out over more calendar time keeps the simultaneous number of severe cases under the number of available hospital beds, ICU beds, and ventilators.
On the chart below, a fixed fraction of the Infectious compartment (≈4%, a COVID-like average across age groups) is treated as requiring hospitalization at any given time. The dashed purple line marks hospital bed capacity as a percentage of the population — move the "Hospital Capacity" slider and watch how a taller, sooner Infectious peak (high R₀, no intervention) blows through that line, while a flattened, delayed peak (higher γ, lower β via NPIs, or vaccination) can stay under it.
The abstract "capacity line" on this chart corresponds to real, documented crises. During the winter 2020–2021 COVID-19 surge in the United States, several regions (Southern California, the Upper Midwest, parts of the Southeast) reported ICU occupancy exceeding 90–100% of licensed capacity, forcing crisis-standards-of-care protocols, field hospitals in convention centers and parking structures, and documented instances of ambulances being unable to offload patients for hours. Northern Italy in March–April 2020 was the starkest early example: Lombardy ICUs exceeded capacity within roughly two weeks of sustained community transmission, forcing explicit triage decisions about who would receive ventilator support.
The policy lesson embedded directly in the mathematics: because the Infectious (and therefore hospitalized) curve's height scales roughly with how far R₀ exceeds 1, and its timing compresses as R₀ rises, even modest reductions in β or increases in γ — achieved early — disproportionately reduce peak hospital load compared to the same intervention applied late, after exponential growth has already compounded for several generations.