SIR Epidemic Model Calculator

Simulate the spread of an infectious disease using the classic SIR (Susceptible-Infected-Recovered) compartmental model. Visualize epidemic curves, calculate the basic reproduction number (R₀), peak infection day, and herd immunity threshold.

BASIC REPRODUCTION NUMBER (R₀)
--
Peak Infection Day
--
Peak Infected
--
Herd Immunity Threshold
--
Total Infected (End)
--

What is the SIR Model?

The SIR model is one of the simplest and most fundamental mathematical models for understanding the spread of infectious diseases through a population. It divides the total population into three compartments:

  • S (Susceptible): Individuals who have not yet been infected and are vulnerable to the disease.
  • I (Infected): Individuals who are currently infected and can transmit the disease to susceptible individuals.
  • R (Recovered): Individuals who have recovered from the infection and are assumed to be immune (or removed from the population through death or quarantine).

The model assumes a closed population (no births, deaths from other causes, or migration), and that recovered individuals gain permanent immunity.

History of Compartmental Models

The SIR model was first proposed by William Ogilvy Kermack and Anderson Gray McKendrick in 1927. Their seminal paper "A Contribution to the Mathematical Theory of Epidemics" laid the foundation for mathematical epidemiology. The model has since been extended into many variants including SEIR (adding an Exposed compartment), SIS (no immunity), SIRS (temporary immunity), and more complex agent-based models.

Despite being nearly a century old, the basic SIR framework remains a cornerstone of epidemiological modeling and was widely used during the COVID-19 pandemic to understand disease dynamics and inform public health policy.

SIR Differential Equations

The SIR model is governed by three coupled ordinary differential equations:

dS/dt = −β × S × I / N
dI/dt = β × S × I / N − γ × I
dR/dt = γ × I

Where:

  • β (beta) = contact rate — the average number of adequate contacts per unit time that lead to transmission
  • γ (gamma) = recovery rate — the reciprocal of the average infectious period (e.g., if infectious for 10 days, γ = 0.1)
  • N = total population (S + I + R = N at all times)

This calculator uses Euler's method with a time step of dt = 0.1 days for numerical integration.

SIR Flow Diagram

SIR Model Compartment Flow S Susceptible I Infected R Recovered βSI/N γI R₀ = β / γ   |   Herd Immunity = 1 − 1/R₀

Basic Reproduction Number (R₀)

The basic reproduction number R₀ (pronounced "R-naught") is arguably the most important parameter in epidemiology. It represents the average number of secondary infections caused by a single infected individual in a fully susceptible population.

R₀ = β / γ
  • If R₀ > 1: The epidemic will grow — each infected person infects more than one other person on average.
  • If R₀ = 1: The epidemic is at equilibrium — it persists but doesn't grow.
  • If R₀ < 1: The epidemic will die out — each infected person infects fewer than one other person.

R₀ is not an intrinsic property of the pathogen alone; it depends on the contact rate in the population, which can be modified by public health interventions.

Herd Immunity

Herd immunity occurs when a sufficient proportion of the population is immune (through vaccination or prior infection) that the disease can no longer spread effectively. The herd immunity threshold is:

Herd Immunity Threshold = 1 − 1/R₀

For example, with R₀ = 3 (like measles), the threshold is 1 - 1/3 = 66.7%, meaning about two-thirds of the population must be immune to prevent sustained transmission.

Flattening the Curve

"Flattening the curve" refers to public health interventions (social distancing, masks, lockdowns) that reduce the contact rate β, thereby lowering R₀ and spreading out infections over a longer period. This doesn't necessarily reduce the total number of infections but prevents the healthcare system from being overwhelmed by a sharp peak.

In the SIR model, reducing β (while keeping γ constant) produces a lower, broader infection curve with a later peak. The area under the infection curve (total cases) may remain similar, but the peak height is reduced.

R₀ Values for Known Diseases

DiseaseR₀ (Estimate)Herd Immunity ThresholdInfectious Period
Measles12 – 1892 – 95%8 days
Chickenpox10 – 1290 – 92%10 – 21 days
Mumps4 – 775 – 86%7 – 10 days
COVID-19 (original)2 – 350 – 67%10 – 14 days
COVID-19 (Omicron)8 – 1588 – 93%5 – 7 days
Influenza (seasonal)1.2 – 1.817 – 44%5 – 7 days
Ebola1.5 – 2.533 – 60%6 – 16 days
Smallpox5 – 780 – 86%14 – 21 days

Limitations of the SIR Model

  • Homogeneous mixing: Assumes every individual has an equal probability of contacting every other individual, which is unrealistic in structured populations.
  • No latent period: The SIR model does not account for an incubation/exposed period (the SEIR model addresses this).
  • Permanent immunity: Assumes recovered individuals never become susceptible again (not true for all diseases).
  • Constant parameters: β and γ are assumed constant, but in reality they change with interventions, seasonality, and behavioral changes.
  • No demographics: No births, natural deaths, or age structure are considered.
  • No spatial structure: Does not account for geographic spread or travel patterns.
  • Deterministic: Produces the same output for the same inputs; does not capture stochastic effects important in small populations.

Worked Example

With N = 10,000, I₀ = 10, R₀ = 0, β = 0.3, γ = 0.1:

R₀ = β / γ = 0.3 / 0.1 = 3.0

Herd Immunity Threshold = 1 − 1/3 = 66.7%

Infectious Period = 1/γ = 1/0.1 = 10 days

With these parameters (similar to measles-like transmission), the epidemic peaks around day 46 with approximately 2,975 individuals simultaneously infected. By the end of the simulation, roughly 9,415 people (94.2%) will have been infected.

Frequently Asked Questions

What is the difference between SIR and SEIR models?

The SEIR model adds an "Exposed" (E) compartment between Susceptible and Infected. Individuals in the E compartment have been infected but are not yet infectious (they are in the incubation period). This is important for diseases like COVID-19 where there is a significant latent period before a person becomes contagious.

How do I choose β and γ values?

γ is typically 1 divided by the average infectious period in days. For example, if a person is infectious for 10 days, γ = 0.1. β can be estimated from R₀ since R₀ = β/γ, so β = R₀ × γ. If you know the R₀ and infectious period for a disease, you can derive both parameters.

Why does the epidemic eventually stop even without intervention?

As more people become infected and recover (becoming immune), the pool of susceptible individuals shrinks. Eventually, each infected person encounters mostly immune individuals, and the effective reproduction number drops below 1, causing the epidemic to decline. This is the natural herd immunity effect.

What does "flattening the curve" mean in terms of the model?

Flattening the curve means reducing β (the contact rate) through interventions like social distancing, mask-wearing, or lockdowns. This lowers R₀, which pushes the peak infection to a later date and reduces its height, spreading the cases over a longer time period. This helps prevent healthcare system overload.