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=βSIN\frac{dS}{dt} = -\beta \cdot \frac{S \cdot I}{N} dIdt=βSINγ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 R02\mathcal{R}_0 \approx 233. Measles has R012\mathcal{R}_0 \approx 121818.

Herd Immunity Threshold

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

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

For R0=3\mathcal{R}_0 = 3: need 11/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.