Search

Search papers and lessons

Compartmental Model

Level 3 · 9 min read

A compartmental model splits a population into groups such as susceptible, infected and recovered, and writes differential equations for how people move between them.

On this page

  • Colour = topic mix
  • Calculus
  • Discrete math
  • Epidemiology
  • Sign in to see your progress

TL;DR

This lesson is an explanation of a mathematical model. It is not medical advice.

A compartmental model divides a population into groups, called compartments, according to their disease state. The classic version uses susceptible (S), infected (I) and recovered (R) people. It then writes a differential equation for how fast people flow from one compartment to the next, so the whole outbreak becomes a small system of equations that can be solved or simulated. The model is simple on purpose: it captures the feedback between how many people can be infected and how many are infected, and little else.

Where you'll see it: forecasting how an outbreak might grow, comparing vaccination strategies, and estimating the basic reproduction number that many public health analyses start from.

Intuition

Buckets and flows

Picture the population as three buckets of water. The first bucket holds the people who can still catch the disease. The second holds the people currently sick and able to pass it on. The third holds the people who have recovered and are protected for now. Infection moves water from the first bucket to the second. Recovery moves it from the second to the third. Nothing else changes the totals, so the three buckets always add up to the population.

The rates of flow depend on the state of the buckets. The more people are infected, the faster new infections happen, because each infected person meets susceptible people. That feedback is what makes an outbreak rise and fall, and it is the reason a differential equation is the natural description. A model with constant rates of change cannot produce a peak.

Why compartments at all

Tracking every person and every contact is impossible for a whole country, and most of the detail does not change the big picture. Grouping people by state turns a huge problem into a handful of numbers. Each compartment is an average, and the model answers questions about averages: how large the peak is, when it arrives, and how much faster it moves if the transmission rate drops. The price is that the model assumes people in a compartment are alike, which is only roughly true.

The flow

flowchart LR
  S[Susceptible] -->|infection| I[Infected]
  I -->|recovery| R[Recovered]

The math

Let NN be the total population, and let S(t)S(t), I(t)I(t) and R(t)R(t) be the numbers of susceptible, infected and recovered people at time tt in days. Then S+I+R=NS + I + R = N at all times. Two rates describe the flow. The transmission rate β\beta is the number of new infections per infected person per day when everyone is susceptible. The recovery rate γ\gamma is the fraction of infected people who recover each day, so an average infection lasts 1/γ1/\gamma days.

Definition: SIR model

The equations are

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

The term βSI/N\beta S I / N is the rate of new infections. It is proportional to the number of susceptible people times the number of infected people, divided by NN, because the chance that a given contact is with an infected person is I/NI/N. These are ordinary differential equations (see Ordinary Differential Equation), with the three compartments as the unknowns.

Checking the equations add up

Add the three derivatives. The infection term appears once with a minus sign in dS/dtdS/dt and once with a plus sign in dI/dtdI/dt, so it cancels. The recovery term appears with a minus sign in dI/dtdI/dt and a plus sign in dR/dtdR/dt, so it cancels too. The sum is zero, which means S+I+RS + I + R stays constant. This is the conservation law that makes the model consistent.

The basic reproduction number

At the start of an outbreak almost everyone is susceptible, so S≈NS \approx N. The infected group then grows at rate β−γ\beta - \gamma per day, from the equation for dI/dtdI/dt. The ratio

R0=βγR_0 = \frac{\beta}{\gamma}

is the basic reproduction number. It is the average number of secondary infections caused by one infected person in a fully susceptible population, and it is the quantity that decides whether the outbreak grows. If R0>1R_0 \gt 1, the infected count rises at the start. If R0<1R_0 \lt 1, it falls from the start.

The herd immunity threshold

Infection grows only while SS is large enough. Setting dI/dt=0dI/dt = 0 with I>0I \gt 0 gives S=N/R0S = N/R_0 at the peak. The fraction of the population that must be immune for the outbreak to stop growing is therefore

pc=1−1R0.p_c = 1 - \frac{1}{R_0}.

This is the herd immunity threshold in this simple model. Real populations are not uniform and immunity is not perfect, so the threshold is an approximation.

Worked examples

Example
One step of a tiny outbreak

Take a population of N=1000N = 1000 with one infected person, so S0=999S_0 = 999, I0=1I_0 = 1, and nobody has recovered yet. Use β=0.3\beta = 0.3 per day and γ=0.1\gamma = 0.1 per day, so R0=3R_0 = 3. Use a one-day Euler step, which replaces each derivative by its value at the start of the day. This is crude, but it is easy to follow.

  1. Compute the new infections. βS0I0/N=0.3×999×1/1000=0.2997\beta S_0 I_0 / N = 0.3 \times 999 \times 1 / 1000 = 0.2997.
  2. Compute the recoveries. γI0=0.1×1=0.1\gamma I_0 = 0.1 \times 1 = 0.1.
  3. Update the compartments. S1=999−0.2997=998.7003S_1 = 999 - 0.2997 = 998.7003, I1=1+0.2997−0.1=1.1997I_1 = 1 + 0.2997 - 0.1 = 1.1997, and R1=0+0.1=0.1R_1 = 0 + 0.1 = 0.1.
  4. Check the total. 998.7003+1.1997+0.1=1000.0000998.7003 + 1.1997 + 0.1 = 1000.0000, so the population is conserved.

Interpretation: the infected count grew from 1 to about 1.2 in one day. The per-day growth factor at the start is 1+β−γ=1.21 + \beta - \gamma = 1.2, which matches R0=3R_0 = 3 through β−γ=γ(R0−1)=0.2\beta - \gamma = \gamma(R_0 - 1) = 0.2. A finer step would give a more accurate curve, but the first step already shows the feedback: the new infections depend on the number of infected people at that moment.

Example
How big a vaccination campaign has to be

Keep R0=3R_0 = 3 from the last example and ask what fraction must be immune.

  1. Use the threshold formula. pc=1−1/R0=1−1/3=2/3p_c = 1 - 1/R_0 = 1 - 1/3 = 2/3.
  2. Convert to a number of people. In a population of 1000 this is 1000×2/3≈6671000 \times 2/3 \approx 667 immune people.
  3. Compare with a smaller R0R_0. If R0=2R_0 = 2, then pc=1−1/2=0.5p_c = 1 - 1/2 = 0.5, and only 500 immune people are needed.
  4. Consider a larger R0R_0. If R0=6R_0 = 6, then pc=1−1/6=0.833p_c = 1 - 1/6 = 0.833, so five people in six must be immune.

Interpretation: the threshold rises steeply as R0R_0 grows, because each extra infection per case makes the outbreak harder to stop. Diseases with a large R0R_0, such as measles, need very high immunity, which is why estimates of R0R_0 matter so much. The model gives the threshold; it does not say how a real campaign should be designed.

Tradeoffs and failure modes

The SIR model is useful because it is small enough to solve, understand and fit. Its assumptions also set its limits.

SituationWhat goes wrongBetter choice
People are not mixing uniformlyA single β\beta hides differences between age groups, places and contact patternsAge-structured or network models
Infection has a long incubation periodThe model assumes infected people transmit at once, so it misses the lagAdd an exposed compartment, giving an SEIR model
People lose immunityRecovered people never return to susceptible in the basic model, so long-run predictions are too optimisticAdd a return flow, giving an SIRS model
β\beta and γ\gamma change over timeConstant rates miss behaviour changes and interventionsTime-varying rates, fitted to data
Small populationsThe equations describe averages, but chance dominates when counts are smallStochastic compartmental models

Estimates of R0R_0 are sensitive to these assumptions. Two studies of the same disease can give different values because they use different contact structures or different definitions of the infectious period. A large difference in R0R_0 therefore does not always mean a large difference in the disease itself.

History

The model was introduced in 1927 by William Ogilvy Kermack and Anderson Gray McKendrick, who studied the Bombay plague epidemic and other outbreaks. They wrote down the susceptible, infected and recovered groups and showed that an epidemic only grows when enough susceptible people are available. Their result is the threshold idea behind R0R_0 and herd immunity.

Later work extended it with exposed compartments, age structure and networks, and it became a standard tool in infectious disease planning. The basic equations have stayed the same in most of these extensions.

Check yourself

QuestionIn the SIR model, what does the term beta S I / N represent, and why does it depend on I?Show answer

It is the rate of new infections. It depends on I because each infected person makes contact with susceptible people at a rate that scales with how many infected people there are. More infected people means more transmission, which is the feedback that drives an outbreak.

QuestionA disease has beta = 0.5 per day and gamma = 0.25 per day. Compute R0 and the herd immunity threshold.Show answer

R0 = beta / gamma = 0.5 / 0.25 = 2. The threshold is 1 - 1/R0 = 1 - 1/2 = 0.5, so about half the population must be immune for the outbreak to stop growing in this model.

QuestionWhy does the sum S + I + R stay constant in the SIR equations?Show answer

Each flow appears once with a minus sign and once with a plus sign. The infection flow leaves S and enters I, and the recovery flow leaves I and enters R. Adding the three derivatives therefore cancels every flow, so the total does not change.

QuestionUsing the one-day Euler step with N = 1000, S = 999, I = 1, beta = 0.3 and gamma = 0.1, how many people are infected after one day under this model?Show answer

The new infections are 0.3 x 999 x 1 / 1000 = 0.2997, and the recoveries are 0.1 x 1 = 0.1. The infected count becomes 1 + 0.2997 - 0.1 = 1.1997, about 1.2.

QuestionA model with a long incubation period gives a much earlier peak than observed. Which assumption of the basic SIR model is most likely responsible, and what change would address it?Show answer

The basic model assumes that people become infectious as soon as they are infected, with no delay. A long incubation period means the real epidemic is slower to build, so the peak arrives later. Adding an exposed compartment, which gives an SEIR model, captures the delay before infected people can transmit.

Sources