You are on page 1of 4

Compartment (SIR) models of epidemics

1. Description of the model


A major assumption of many mathematical models of epidemics is that the population can be divided into a
set of distinct compartments. These compartments are defined with respect to disease status. The simplest
model was described by Kermack and McKendrick (1927) and is known as the Kermack-McKendrick model.
The Kermack-McKendrick model (or SIR model) consists of three compartments: susceptible (S), infected
(I), recovered (R).
• Susceptible Individuals that are susceptible have, in the case of the basic SIR model, never been
infected, and they are able to catch the disease. Once they have it, they move into the infected
compartment.
• Infected individuals can spread the disease to susceptible individuals. The time they spend in the
infected compartment is the infectious period, after which they enter the recovered compartment.
• Recovered Individuals are assumed to be immune for life.
The SIR model is easily written using ordinary differential equations (ODEs), which implies a deterministic
model (no randomness is involved, the same starting conditions give the same output), with continuous time
(as opposed to discrete time). Analogous to the principles of reaction kinetics, we assume that encounters
between infected and susceptible individuals occur at a rate proportional to their respective numbers in the
population. The rate of new infections can thus be defined as βSI, where β is a parameter for infectivity.
Infected individuals are assumed to recover with a constant probability at any time, which translates into a
constant per capita recovery rate that we denote with r, and thus an overall rate of recovery rI. Based on
these assumptions we can draw the scheme of the model:

Figure 1: Scheme of the basic SIR model. Boxes represent compartments, and arrows indicate flux between
the compartments.

The scheme can also be translated into a set of differential equations:


dS
= −βSI
dt
dI
= βSI − rI
dt

1
dR
= rI
dt
Using this model, we will consider a mild, short-lived epidemic, e.g. influenza, in a closed population. Closed
means that there is no immigration or emigration. Moreover, given the time scale of influenza epidemics, we
will not consider demographic turnover (birth or death), and all infections are assumed to end with recovery.
The size of the population (S + I + R) is therefore constant and equal to the initial population size, which
we denote with N . Let us now consider a population which is naive with respect to the disease we are
considering. What happens if a single infected individual is introduced into such a population? Is there going
to be an epidemic? How many people will be infected? We will answer these questions by implementing and
simulating the model in R.

2. Implementation in R

We use the same package deSolve as previously.


library("deSolve")

SIRderivs <- function(t, x, parms) {


S <- x[1]
I <- x[2]
R <- x[3]
dS <- -parms$beta * S * I
dI <- +parms$beta * S * I - parms$r * I
dR <- parms$r * I
out <- list(c(dS, dI, dR))

}
parms <- list(beta = 0.001, r = 0.1)
inits <- c(S = 499, I = 1, R = 0)
dt <- seq(0, 100, by = 0.1)

sir.out <- as.data.frame(ode(inits, dt, SIRderivs, parms = parms))


head(sir.out)

## time S I R
## 1 0.0 499.0000 1.000000 0.00000000
## 2 0.1 498.9491 1.040706 0.01020255
## 3 0.2 498.8961 1.083061 0.02082004
## 4 0.3 498.8410 1.127133 0.03186937
## 5 0.4 498.7836 1.172993 0.04336852
## 6 0.5 498.7240 1.220712 0.05533550
and I use the base R function matplot to plot the output. If you know ggplot or other packages, you can
use those for plotting instead.
matplot(sir.out$time, sir.out[2:4], type = "l", col = c("red", "blue", "black"),
lty = c("solid", "dashed", "dotted"))

2
500
400
300
sir.out[2:4]

200
100
0

0 20 40 60 80 100

sir.out$time
Run the model with the preset parameters. Now take some time to think about the interpretation of the
simulation. What is the population size with these settings? What is the time frame of the simulation? Is it
possible to tell? What defines the time scale? Would you expect to get such a smooth curve in a real life
epidemic?
Explore the model: play around with initial conditions and parameters and see what happens in the simulations
. Observe the effect of each parameter and the possible courses of simulated epidemics. Is it possible to
simulate a sustained endemic disease in this model?

3. Analysis and Exploration


A key parameter in epidemiology is the basic reproductive ratio, R0 . It is defined as the average number of
secondary cases transmitted by a single infected individual that is placed into a fully susceptible population.
In other words, R0 tells us about the initial rate of spread of the disease. Hence, if R0 > 1 , there will
be an epidemic, and if R0 < 1, the introduced infecteds will recover (or die) without being able to replace
themselves by new infections. In this model, it is pretty easy to derive R0 The disease-free state corresponds
to: S = N, I = 0, R = 0. If one infected individual appears in the population, there will be an epidemic if
and only if dI/dt > 0. This yields βS
r > 1 so :

βS
R0 =
r

Note that this result R0 = βSr derived above, applies only to the basic Kermack-McKendrick model, with
alternative SIR models having different formulas for dI/dt and hence for R_0. Check this formula by
simulating the model for a couple of different sets of parameters. Fix N , and vary β and/or r. Choose your
values such as to have combinations with R0 > 1 and R0 < 1. Run the model for each parameter combination
and see what happens.

3
4. Modifications to the model
Make modifications to the model diagram above. What parameters do you need to add for each? Try to
identify your assumptions as you make each modification. Write down the modified equations of the model.
For one of the modified models you create, write the code to numerically solve the model. How does your
modification change the dynamics?

A. Loss of Immunity

The “Recovered” state is not permanent. After some time, the recovered individuals return to being
susceptible.

B. Open population

Include immigration and emigration.

C. Longer-Term demographic model

Modify the model diagram and equations so as to include births and deaths.

Literature Cited
Kermack, W O, and A G McKendrick. 1927. “A Contribution to the Mathematical Theory of Epidemics.”
Proceedings of the Royal Society of London. Series A, Containing Papers of a Mathematical and Physical
Character 115 (772): 700–721.

You might also like