SIR Epidemic Model Simulator Back
Epidemiology · Mathematical Biology

SIR Epidemic Model Simulator — Herd Immunity & Outbreak Dynamics

Drag β and γ to watch R₀ change in real time. Raise vaccination coverage until herd immunity kicks in. Compare COVID-19, influenza, and measles to see just how contagious each disease really is.

Presets
Model Type
Parameters
Population N
Initial infected I₀
Transmission rate β (/day)
Recovery rate γ (/day)
Basic reprod. number R₀ = β/γ 3.50
Vaccination & Options
Vaccination coverage V (%)
%
Simulation duration (days)
d
Seasonal forcing ε
Key Metrics
Results
Peak infection
Attack rate
Days to peak
Herd immunity
Time Series: S / I / R vs Days
Theory & Key Formulas
$$\frac{dS}{dt}= -\frac{\beta S I}{N}$$ $$\frac{dI}{dt}= \frac{\beta S I}{N}- \gamma I$$ $$\frac{dR}{dt} = \gamma I$$

N = S + I + R = const (conservation)

What is the SIR Model & Herd Immunity?

🙋
What exactly is this R₀ number I keep hearing about in the news? It seems super important for pandemics.
🎓
Basically, R₀ (pronounced "R-naught") is the reproduction number. It tells you, on average, how many other people one infected person will pass the disease to in a population where everyone is susceptible. In practice, if R₀ > 1, the outbreak grows; if it's less than 1, it fizzles out. In this simulator, you can see it directly: R₀ = β/γ. Try moving the "Transmission rate (β)" slider up for COVID-19 and watch how the infected curve explodes!
🙋
Wait, really? So if R₀ is fixed for a disease, how do we ever stop an outbreak? That seems hopeless.
🎓
Great question! That's where herd immunity comes in. R₀ assumes everyone is susceptible (S ≈ N). But as people recover or get vaccinated, they move to the Recovered (R) group. The effective reproduction number, R_t, becomes R₀ * (S/N). When enough people are immune, S/N gets so small that R_t drops below 1. For instance, slide the "Vaccination coverage" up to 70% for measles (R₀~15) and see the outbreak collapse—that's herd immunity in action.
🙋
Okay, that makes sense. But what about the "Incubation period" and "Seasonal forcing" parameters? They weren't in the basic SIR equations you showed earlier.
🎓
Sharp observation! The classic SIR model is a foundation, but real diseases are more complex. Adding an "Exposed" (E) compartment creates an SEIR model, where 1/σ is the incubation period. Seasonal forcing (ε) models how transmission (β) can wobble with seasons, like flu in winter. Try adding a 20% seasonal forcing to the flu preset and run a 2-year simulation—you'll see recurring winter waves, just like in real life.

Physical Model & Key Equations

The core SIR model is a set of coupled Ordinary Differential Equations (ODEs) that track the flow of people between three compartments: Susceptible (S), Infectious (I), and Recovered (R). The rate of new infections depends on the contact rate (β) and the probability that a contact is with a susceptible person (S/N).

$$ \begin{align*}\frac{dS}{dt}&= -\frac{\beta S I}{N}\\[6pt] \frac{dI}{dt}&= \frac{\beta S I}{N}- \gamma I \\[6pt] \frac{dR}{dt}&= \gamma I \end{align*}$$

β is the transmission rate (per day). γ is the recovery rate (per day); its inverse, 1/γ, is the average infectious period. N is the total constant population (S + I + R = N).

From these equations, we derive the critical threshold for herd immunity and the basic reproduction number R₀. The outbreak peaks when the effective reproduction number R_t = R₀ * (S/N) falls to 1.

$$ R_0 = \frac{\beta}{\gamma}, \quad \text{Herd Immunity Threshold}= 1 - \frac{1}{R_0} $$

R₀: Basic reproduction number. If R₀ > 1, epidemic grows. Herd Immunity Threshold: The fraction of the population that must be immune (via recovery or vaccination) to stop sustained transmission. For measles (R₀=15), over 93% must be immune.

Frequently Asked Questions

R₀ is calculated as the infection rate β divided by the recovery rate γ (β/γ). In this simulator, when you adjust the β and γ sliders, the R₀ value is displayed in real time. You can visually observe that when R₀ exceeds 1, the infection spreads, and when it is below 1, the infection converges toward extinction.
Increasing the vaccination rate reduces the susceptible population S, thereby lowering the effective reproduction number. Herd immunity is achieved when the vaccination rate is at least 1 − (1/R₀). For example, if R₀ = 3, a vaccination rate of approximately 67% or higher is required. You can experience this threshold by adjusting the slider in the simulator.
Each preset is based on actual epidemiological data: COVID-19 has an R₀ of about 2.5 (β = 0.5, γ = 0.2), influenza has an R₀ of about 1.5 (β = 0.45, γ = 0.3), and measles has an R₀ of about 15 (β = 1.5, γ = 0.1). By switching presets, you can compare changes in the epidemic curve due to differences in transmissibility.
The effects of countermeasures (such as vaccination or reducing β through isolation) can be tested numerically, providing estimates of the peak timing and final number of infections. However, this model is a simplified one that does not account for age structure or spatial spread. For actual policy decisions, please use it in conjunction with more detailed models and expert advice.

Real-World Applications

Public Health Policy & Vaccination Campaigns: This model is the bedrock for planning vaccine rollout. Officials use it to calculate the coverage needed to achieve herd immunity for diseases like measles, mumps, and polio. During the COVID-19 pandemic, SIR and SEIR models were used daily to project hospital bed needs and evaluate the impact of social distancing (which lowers β).

Pharmaceutical & Clinical Trial Planning: Drug companies use epidemic models to forecast the potential market size for a new vaccine or antiviral drug. They also model trial outcomes in different transmission scenarios to determine optimal trial size and location.

CAE & Computational Simulation: The ODEs in the SIR model are solved numerically using Runge-Kutta methods—the exact same solvers used in engineering CAE for simulating car crashes (structural dynamics), airflow over a wing (CFD), and chemical reactions in a battery. This simulator is a direct example of using computational methods to solve a real-world "physics" problem of population dynamics.

Economic Impact Forecasting: Governments and financial institutions couple SIR model outputs with economic models to estimate the cost of outbreaks and the economic benefit of intervention measures. This helps in weighing the cost of a lockdown against the projected healthcare cost of an unmitigated wave.

Common Misunderstandings and Points to Note

When you start using this simulator, there are a few key points to keep in mind. First, understand that "the basic reproduction number R₀ is not an absolute constant." For example, the R₀≈2.5 for COVID-19 is a value based on an environment where people interact normally. In reality, measures like avoiding crowds or wearing masks will lower the effective reproduction number R_t. In this tool, lowering the "infection rate β" simulates precisely the effect of such interventions.

Next, consider the realism of your parameter settings. For instance, setting the "recovery rate γ" to 1/5 (=0.2) implies an average infectious period of 5 days, but this often refers to the entire symptomatic period. The actual "period of being contagious" might be shorter. If tweaking parameters produces unrealistic curves (e.g., where the number of infected individuals I exceeds the total population N), get into the habit of reviewing your settings.

Finally, hold the understanding that "the herd immunity threshold is not the goal." While reaching a threshold like 60% will stop the epidemic, what matters is the magnitude of the infection peak (the healthcare burden) that occurs before that point. For example, relying solely on natural infection without vaccination could lead to over 20% of the population being infected simultaneously at the peak, potentially causing healthcare system collapse. A practical way to use this simulation is to observe how increasing the vaccination rate can alleviate the "peak pressure."

How to Use

  1. Set initial infected count (vI0) and susceptible population (sN)—e.g., 100 infected in 1,000,000 population for COVID-19 baseline.
  2. Adjust transmission rate (vBeta) in contacts per day and recovery rate (vGamma)—measles typically β=0.5, γ=0.1; flu β=0.3, γ=0.2.
  3. Configure vaccination coverage (vN) as percentage of population—increasing vaccination shifts the herd immunity threshold downward.
  4. Run simulation and observe peak infection count, attack rate percentage, and days to peak; compare against observed R₀ values.

Worked Example

Model an influenza outbreak: population 500,000, initial infections 50, β=0.25 (contact rate), γ=0.33 (recovery rate 3 days). Without vaccination, R₀ ≈ 0.75, peak occurs at day 45 with 89,500 concurrent infections and 32% attack rate. Introducing 60% vaccination coverage reduces peak to 21,000 infections by day 38; at 70% vaccination (above flu's herd immunity threshold of 60%), peak drops below 8,000. Measles requires 95% coverage due to R₀≈12–18.

Practical Notes

  1. R₀ calculation: multiply β by average infectious period (1/γ). Epidemic threshold occurs when R₀ > 1; herd immunity fraction = 1 − 1/R₀.
  2. COVID-19 variants shift β upward—Omicron β≈0.8 versus wild-type β≈0.4—requiring higher vaccination targets despite equal R₀.
  3. Temporal effects: γ varies by pathogen (measles infectious 8 days, COVID 10 days, flu 3–5 days); adjust sGamma accordingly for accuracy.
  4. Attack rate plateaus even without intervention once susceptible pool exhausts; vaccination prevents this depletion without infection.