Lesson 12 of 15

SIR Epidemic Model

SIR Epidemic Model

The SIR model divides a population into three compartments:

  • S (Susceptible): can get infected
  • I (Infected): currently infectious
  • R (Recovered): immune

Equations

dSdt=−β⋅S⋅IN\frac{dS}{dt} = -\beta \cdot \frac{S \cdot I}{N} dIdt=β⋅S⋅IN−γ⋅I\frac{dI}{dt} = \beta \cdot \frac{S \cdot I}{N} - \gamma \cdot I dRdt=γ⋅I\frac{dR}{dt} = \gamma \cdot I

  • β\beta: transmission rate (contacts per day ×\times probability of transmission)
  • γ\gamma: recovery rate (1/days infectious)
  • N=S+I+RN = S + I + R: total population (constant)

Key Metric: Basic Reproduction Number

R0=βγ\mathcal{R}_0 = \frac{\beta}{\gamma}

  • R0>1\mathcal{R}_0 > 1: epidemic grows (each infected person infects more than one)
  • R0<1\mathcal{R}_0 < 1: epidemic dies out

COVID-19 had R0≈2\mathcal{R}_0 \approx 2–33. Measles has R0≈12\mathcal{R}_0 \approx 12–1818.

Herd Immunity Threshold

An epidemic can't grow if enough people are immune. The threshold:

fraction immune needed=1−1R0\text{fraction immune needed} = 1 - \frac{1}{\mathcal{R}_0}

For R0=3\mathcal{R}_0 = 3: need 1−1/3=67%1 - 1/3 = 67\% immune.

Your Task

Implement sir(S0, I0, R0, beta, gamma, t_end, n) using Euler's method. Return (S, I, R) at time t_end.

Pyodide loading...
Loading...
Click "Run" to execute your code.