AnyLearn
All lessons
Scienceintermediate

Modelling Spread: SIR, SEIR, R0, Rt, and the Herd Immunity Threshold

Derive the basic reproduction number from the SIR equations, see why the herd immunity threshold is 1 - 1/R0 and why epidemics overshoot it, simulate one in Python, and learn how Rt is estimated in real time and what heterogeneity does to the averages.

Updated · AI-authored, review-gated · how lessons are made

Progress1 / 10

Compartments are bookkeeping, not biology

A compartmental model ignores everything about individuals except which box they are in. The classic version, from Kermack and McKendrick's 1927 paper in the Proceedings of the Royal Society, uses three:

  • S, susceptible: can be infected.
  • I, infectious: infected and able to pass it on.
  • R, removed: recovered with immunity, or dead. Either way, out of the transmission chain.

The model then tracks only the flows between boxes. That is a severe simplification, and also the source of its power: a handful of parameters yields thresholds, peak timing, and final epidemic size that hold across very different diseases. The equations form a small nonlinear system of differential equations; the differential-equations path on this site (lessons ode-what-a-differential-equation-says and ode-phase-plane) covers the tools for reading them, so this lesson uses them without re-deriving the mathematics.

Sign in free to save your progress and earn certificates.

Full lesson text

All 10 steps on one page, for reading, reference, and search.

Show

1. Compartments are bookkeeping, not biology

A compartmental model ignores everything about individuals except which box they are in. The classic version, from Kermack and McKendrick's 1927 paper in the Proceedings of the Royal Society, uses three:

  • S, susceptible: can be infected.
  • I, infectious: infected and able to pass it on.
  • R, removed: recovered with immunity, or dead. Either way, out of the transmission chain.

The model then tracks only the flows between boxes. That is a severe simplification, and also the source of its power: a handful of parameters yields thresholds, peak timing, and final epidemic size that hold across very different diseases. The equations form a small nonlinear system of differential equations; the differential-equations path on this site (lessons ode-what-a-differential-equation-says and ode-phase-plane) covers the tools for reading them, so this lesson uses them without re-deriving the mathematics.

2. SIR, SEIR, and their relatives

Adding an E (exposed: infected but not yet infectious) box turns SIR into SEIR, which matters whenever there is a latent period, because it delays and stretches each generation of spread. Adding a flow from removed back to susceptible gives SEIRS, for immunity that wanes. Other common variants add maternal immunity, vaccinated compartments, or split each box by age group. The shape of the model should follow the natural history being described, and each added box is another parameter that has to be estimated from data.

stateDiagram-v2
  [*] --> Susceptible
  Susceptible --> Exposed: infection
  Exposed --> Infectious: latent period ends
  Infectious --> Removed: recovery or death
  Removed --> Susceptible: immunity wanes

3. The SIR equations

Write SS, II, RR as fractions of a population that mixes at random. Each infectious person makes effective contacts at rate β\beta, a fraction SS of which land on susceptibles, and stays infectious for an average of 1/γ1/\gamma days:

dSdt=−βSI,dIdt=βSI−γI,dRdt=γI\frac{dS}{dt} = -\beta S I, \qquad \frac{dI}{dt} = \beta S I - \gamma I, \qquad \frac{dR}{dt} = \gamma I

The term βSI\beta S I is mass action: new infections are proportional to how many infectious and susceptible people there are, as if every pair were equally likely to meet. That homogeneous-mixing assumption is the model's largest simplification, and the last step of this lesson returns to what it hides.

Definition: β\beta bundles contact frequency and the chance a contact transmits; γ\gamma is the recovery rate, so 1/γ1/\gamma is the mean infectious period. Behaviour and interventions act through β\beta; treatment and isolation of cases can act through either.

4. R0 falls out of one inequality

Factor the infectious equation: dI/dt=I(βS−γ)dI/dt = I(\beta S - \gamma). Infections grow exactly when βS>γ\beta S > \gamma. At the start of an epidemic almost everyone is susceptible, S≈1S \approx 1, so growth needs β/γ>1\beta/\gamma > 1. That ratio is the basic reproduction number:

R0=βγ,Reff=R0 SR_0 = \frac{\beta}{\gamma}, \qquad R_{\text{eff}} = R_0 \, S

Anderson and May's Infectious Diseases of Humans (1991) defines R0R_0 as the average number of secondary infections produced by one infectious individual introduced into a wholly susceptible population. Once immunity builds, the relevant quantity is the effective reproduction number, R0R_0 times the susceptible fraction, also affected by anything that changes β\beta.

Key idea: R0R_0 is not a constant of the pathogen. It is a property of a pathogen in a population: the same infection has a different R0R_0 in a dense city than in a dispersed rural area, because contact rates differ. Guerra and colleagues' 2017 systematic review in The Lancet Infectious Diseases found measles estimates spread well beyond the often-quoted range of 12 to 18 for exactly this reason.

5. The herd immunity threshold

Growth stops when R0S<1R_0 S < 1, that is, once the immune fraction exceeds 1−1/R01 - 1/R_0. Fine, Eames and Heymann's review "Herd immunity: a rough guide" (Clinical Infectious Diseases, 2011) credits this threshold theorem to Smith in 1970 and Dietz in 1975, and states its two conditions: immunity delivered at random, and a population that mixes at random.

R0R_0Herd immunity threshold 1−1/R01 - 1/R_0
1.533%
250%
367%
580%
1593%

If a vaccine protects only a fraction EE of those who receive it, Anderson and May give the coverage needed as (1−1/R0)/E(1 - 1/R_0)/E; above an R0R_0 where that exceeds 100%, vaccination alone cannot reach the threshold. How vaccines build immunity in the first place is the subject of the immunology lesson immuno-memory-vaccines-tolerance.

Gotcha: The same review notes Fox and colleagues argued in 1971 that population heterogeneity makes simple thresholds a poor guide for public health. Pockets of low immunity can sustain outbreaks even when the national average is above the threshold.

6. Simulating SIR

A forward-Euler integration with a 7-day infectious period, seeded with one infection in 10,000. It records the peak and the susceptible fraction at the peak, and checks the total against the final-size equation of the next step.

import math

def sir(R0, gamma=1/7, days=365, dt=0.1, i0=1e-4):
    beta = R0 * gamma
    s, i, r = 1 - i0, i0, 0.0
    peak_i, peak_day, s_at_peak = 0.0, 0, s
    for step in range(int(days / dt)):
        new_inf = beta * s * i * dt
        new_rec = gamma * i * dt
        s, i, r = s - new_inf, i + new_inf - new_rec, r + new_rec
        if i > peak_i:
            peak_i, peak_day, s_at_peak = i, step * dt, s
    return peak_i, peak_day, s_at_peak, 1 - s

def final_size(R0):
    z = 0.5
    for _ in range(200):                 # fixed point of z = 1 - exp(-R0 z)
        z = 1 - math.exp(-R0 * z)
    return z

for R0 in (1.5, 2.0, 3.0):
    peak, day, s_pk, total = sir(R0)
    print(f"R0={R0}: HIT {1 - 1/R0:.0%} | peak {peak:.1%} infected on day {day:.0f}, "
          f"S at peak {s_pk:.3f} (1/R0={1/R0:.3f}) | ever infected {total:.1%} "
          f"(final-size eq {final_size(R0):.1%})")
R0=1.5: HIT 33% | peak 6.3% infected on day 113, S at peak 0.666 (1/R0=0.667) | ever infected 58.3% (final-size eq 58.3%)
R0=2.0: HIT 50% | peak 15.4% infected on day 64, S at peak 0.498 (1/R0=0.500) | ever infected 79.8% (final-size eq 79.7%)
R0=3.0: HIT 67% | peak 30.2% infected on day 35, S at peak 0.331 (1/R0=0.333) | ever infected 94.1% (final-size eq 94.0%)

Prevalence peaks exactly when the susceptible fraction hits 1/R01/R_0, the moment the threshold is crossed. Yet the share ever infected ends far above the threshold.

7. Overshoot: the threshold is not the finish line

Predict first

With R0=2R_0 = 2 the threshold is 50%. Once half the population is immune, does the epidemic stop?

Kermack and McKendrick's 1927 analysis gives the total directly. If zz is the fraction ever infected in an unmitigated SIR epidemic, it satisfies the final-size relation:

z=1−e−R0zz = 1 - e^{-R_0 z}

For R0=2R_0 = 2 that gives z≈0.797z \approx 0.797; for R0=3R_0 = 3, about 0.94. The gap between zz and 1−1/R01 - 1/R_0 is the overshoot, and it is why reaching the threshold through uncontrolled infection costs far more infections than the threshold itself suggests. Anything that slows transmission near the peak shrinks the overshoot, because fewer people are infectious when the threshold is crossed.

8. Growth rate is observed, R is inferred

Early in an outbreak nobody observes RR. What appears in the data is the exponential growth rate rr, the slope of log cases over time. Wallinga and Lipsitch (Proceedings of the Royal Society B, 2007) showed that converting rr into RR depends entirely on the shape of the generation interval, the time from one infection to the infections it causes, and that assuming every interval equals the mean gives an upper bound. Three textbook shapes, all with an 8-day mean and the same r=0.1r = 0.1 per day:

Generation interval assumptionFormulaRR
Fixed at exactly 8 dayserTe^{rT}2.23
SEIR: 3-day latent, 5-day infectious, exponential(1+rTE)(1+rTI)(1 + r T_E)(1 + r T_I)1.95
SIR: exponential infectious period, mean 8 days1+rT1 + r T1.80

Gotcha: The same epidemic curve is compatible with an RR from 1.8 to 2.2 here, and the implied herd immunity threshold moves from 44% to 55%. A growth rate alone does not pin down RR; the generation interval has to be measured separately, usually from contact-tracing pairs.

9. Rt: estimating R as it changes

The time-varying reproduction number RtR_t is usually estimated from the renewal equation: today's new infections are yesterday's infectious people, weighted by how infectious they are at each age of infection. Cori and colleagues (American Journal of Epidemiology, 2013) turned this into the widely used EpiEstim method:

R^t=It∑s≥1ws It−s\hat{R}_t = \frac{I_t}{\sum_{s \ge 1} w_s \, I_{t-s}}

where ItI_t is incidence on day tt and wsw_s is the probability that transmission happens ss days after infection, the generation or serial interval distribution. In practice the ratio is averaged over a sliding window with a Bayesian prior to tame noise.

Gostic and colleagues' "Practical considerations for measuring the effective reproductive number" (PLOS Computational Biology, 2020) recommends the Cori approach for real-time use and names two challenges common to every method: specifying the generation interval, and reconstructing when infections happened from observations made later. In practice that means:

  • the generation interval has to be specified correctly, and errors bias RtR_t directly;
  • the formula needs infections, but surveillance sees cases days later, so the infection series must be reconstructed;
  • naively shifting reports back by a sampled delay can itself introduce bias;
  • with small counts, or when testing intensity changes, the estimate tracks the testing rather than the transmission.

10. What the average hides

R0R_0 is a mean, and transmission is rarely evenly spread. Woolhouse and colleagues (PNAS, 1997) found an empirical pattern across several disease systems: typically 20% of hosts contribute at least 80% of the transmission potential. Lloyd-Smith and colleagues (Nature, 2005), using contact-tracing data from eight directly transmitted diseases, showed that individual infectiousness is often highly skewed around R0R_0, which makes chance extinction of a new introduction more likely and outbreaks rarer but more explosive.

What the basic SIR model leaves out, and the usual extension:

  • Heterogeneous contact. Split the population into groups with a contact matrix; R0R_0 becomes the dominant eigenvalue of the next-generation matrix (Diekmann, Heesterbeek and Metz, 1990).
  • Chance in small numbers. Replace the differential equations with a stochastic branching process, so early fade-out is possible.
  • Space and travel. Metapopulation models of linked patches.
  • Changing behaviour and waning immunity. Let β\beta vary with time, and add a flow from RR back to SS.

In practice: A model's output is only as good as the assumptions in its boxes and arrows. When reading a projection, ask what mixing it assumes, where its generation interval came from, and whether it reports a range rather than a single curve.

Check your understanding

The lesson ends with a 5-question quiz. Take it in the player above to see your score.

  1. In a randomly mixing population, an infection has R0 = 4 and immunity is distributed at random. What is the herd immunity threshold?
    • 25%
    • 40%
    • 75%
    • 96%
  2. In the basic SIR model, the number of people currently infectious reaches its peak when the susceptible fraction equals what?
    • 1/R0
    • 1 - 1/R0
    • Exactly one half
    • The final epidemic size
  3. For R0 = 2 the threshold is 50%, yet an unmitigated SIR epidemic infects about 80%. Why?
    • The model double-counts reinfections
    • R0 rises as the epidemic grows
    • Immunity wanes before the peak
    • Many people are still infectious when the threshold is crossed, so infections continue past it
  4. Two outbreaks grow at the same exponential rate r. Outbreak A has a longer generation interval than outbreak B. What follows?
    • Both have the same R, because r determines R
    • A has the higher reproduction number
    • B has the higher reproduction number
    • Neither has a defined R until the peak
  5. Lloyd-Smith and colleagues found individual infectiousness is often highly skewed around R0. What does that imply for a new introduction, compared with a model that gives everyone the average?
    • Outbreaks become certain once R0 exceeds 1
    • Skew has no effect if the mean is unchanged
    • Chance extinction is more likely, and outbreaks are rarer but more explosive
    • The herd immunity threshold rises above 1 - 1/R0

Related lessons

Science
intermediate

How Epidemic Numbers Get Misread: Fatality Ratios, Testing, Delays, and Excess Deaths

Why a fatality ratio depends on who gets tested, why it creeps upward mid-epidemic, how test accuracy and reporting delays distort counts, how excess mortality bypasses diagnosis, and why five-year survival can rise with no one living longer. Ends with a nine-question checklist for any health statistic.

11 steps·~17 min
Science
intermediate

Epidemiological Study Designs: Cohort, Case-Control, and the Biases That Fool Them

How epidemiologists turn exposure and disease into a two-by-two table: cohort, case-control, cross-sectional, and ecological designs, risk and odds ratios computed from Snow's and Doll and Hill's data, and the selection, information, and immortal time biases that make observational studies mislead.

10 steps·~15 min
Science
intermediate

Counting Disease: Incidence, Prevalence, and Standardised Rates

Every epidemic figure is a ratio with a numerator, a denominator, and a time window. Learn how surveillance builds the numerator, how incidence, person-time rates, and prevalence differ, and how age standardisation stops an older population from looking sicker than it is.

10 steps·~15 min
Science
intermediate

Grid-scale storage: duration, flow batteries, and cost per cycle

How grid storage is sized and priced: power versus energy, round-trip efficiency, augmentation, why flow batteries keep their energy in tanks, what a battery price survey does and does not measure, and how levelized cost of storage decides which technology fits each duration.

10 steps·~15 min