Three compartments, one closed population
The SIR model divides a population of fixed size N into three boxes that every individual passes through in order: Susceptible (S) — has never had the disease and can catch it; Infectious (I) — currently infected and able to spread it; and Removed (R) — recovered with immunity, or deceased, either way no longer part of transmission. The model rests on three idealisations: homogeneous mixing (any susceptible is equally likely to contact any infectious individual), a closed population (S+I+R = N stays constant — no births, deaths or migration), and permanent immunity after recovery.
The system of ODEs
Let β be the transmission rate and γ the recovery rate (1/γ is the mean infectious duration). New infections occur at rate β·S·I/N — the frequency-dependent mass-action term appropriate when contact rate is limited by time rather than density:
dS/dt = −β·S·I/N dI/dt = β·S·I/N − γ·I dR/dt = γ·I // check: dS/dt + dI/dt + dR/dt = 0 ⟹ S+I+R = N stays constant
R₀ and the herd immunity threshold
The basic reproduction number R₀ = β/γ is the average number of secondary infections one infectious person causes in a fully susceptible population. Near the start S ≈ N, so dI/dt ≈ (β−γ)·I: the epidemic grows exactly when R₀ > 1. Measles sits at R₀ ≈ 12–18, seasonal influenza at R₀ ≈ 1.2–1.4, and original-strain COVID-19 at R₀ ≈ 2.5–3.
Setting dI/dt = 0 at the epidemic peak gives the critical susceptible fraction S*/N = γ/β = 1/R₀, so the immune fraction needed to stop the epidemic from growing at all — herd immunity — is:
h = 1 − 1/R₀ measles (R₀=15): h ≈ 93% COVID-19 (R₀=3): h ≈ 67% influenza(R₀=1.3):h ≈ 23%
SEIR: adding a latent period
Many diseases have an incubation period during which a person is infected but not yet contagious. SEIR inserts an Exposed compartment between S and I, governed by rate σ = 1/(mean latent period):
dS/dt = −β·S·I/N dE/dt = β·S·I/N − σ·E dI/dt = σ·E − γ·I dR/dt = γ·I // R₀ = β/γ is unchanged — the latent period shifts timing, not the threshold
A fourth-order Runge-Kutta (RK4) integrator advances the state vector [S,E,I,R] one time step at a time — the same numerical method used throughout this site's dynamical-system simulations, because Euler's method is too inaccurate for a stiff, exponentially growing system like an outbreak.
Beyond the closed, deterministic model
Adding a birth/death rate μ produces an endemic equilibrium where the pathogen persists indefinitely rather than burning out. Waning immunity (SIRS) lets R flow back to S, producing the seasonal waves seen in influenza. Real-world epidemics are also stochastic and spatial: agent-based models simulate individual contact networks, and metapopulation models apply SIR dynamics within each city or region and couple them through a mobility matrix — the approach behind airline-borne pandemic forecasting.
Frequently asked questions
Why is the R compartment called "Removed" instead of "Recovered"?
Because the compartment pools together anyone who no longer transmits the disease — the recovered-and-immune along with the deceased — since both behave identically from the model's point of view. Models with explicit vital dynamics track deaths as a separate flow.
What exactly does R₀ measure?
R₀ is the average number of secondary infections one infectious person produces after being introduced into a fully susceptible population. R₀ = β/γ. R₀ > 1 means the epidemic grows, R₀ < 1 means it dies out on its own, and R₀ = 1 is the knife-edge endemic threshold.
Why does SEIR add an Exposed compartment instead of just using SIR?
Many real diseases have a latent period where a person is infected but not yet contagious — five days for COVID-19, roughly ten for measles. SEIR's E compartment captures that delay explicitly, which matters for the design of contact tracing: exposed individuals can be isolated before they ever become infectious.
Try it live
Change β, γ and the starting infected count and watch the S/I/R curves respond in SIR Epidemic Model — entirely client-side, nothing uploaded.
▶ Open SIR Epidemic Model simulation