You are on page 1of 12

Lab 10 - Coupled Autonomous Differential Equations

In epidemiology, SIR models are are used to predict how infectious diseases spread through popula-
tions. They split the population into different compartments (Suscptible, Infected, Recovered) and
count the number of individuals residing in each. The SIR model (and its more complicated/realistic
variants) are used to explore the impact of policies like social distancing, which are used to minimize
the spread of disease.
Susceptible individuals, S(t), can catch the disease from an infectious individual, I(t), while recov-
ered/immune people, R(t), have already had the disease and are no longer infectious or susceptible.
β > 0 is the infection rate, or the average fraction of the population infected per day by each
infectious person. γ > 0 is the average recovery rate, so that 1/γ is the average period of time (in
days) an individual is infectious. This can be modeled by the following system of three nonlinear
differential equations:
dS
= −βSI,
dt
dI
= βSI − γI,
dt
dR
= γI.
dt

Because neither S nor I depend on R, we don’t need to look at the third equation to understand
the disease dynamics. Unless otherwise asked in the questions to follow, consider only the S, I
equations.

Question 1

Find the S and I nullclines for the above system and plot them in the S-I phase plane for β = 0.0005,
N = 1000, and γ = 1/5. Find the nullclines by hand, write/type them here, and complete/run the
code below to check your answer:

#don't forget to set eval=TRUE when you complete the code

require(phaseR) #you might need to install this package!!

## Loading required package: phaseR

## Warning: package ’phaseR’ was built under R version 4.1.2

1
## -------------------------------------------------------------------------------
## phaseR: Phase plane analysis of one- and two-dimensional autonomous ODE systems
## -------------------------------------------------------------------------------
##
## v.2.1: For an overview of the package’s functionality enter: ?phaseR
##
## For news on the latest updates enter: news(package = "phaseR")

#parameters to use?
beta <- 0.0005
gamma <- 1/5
N <- 1000
I0 <- 2

#change the window for nice viewing. If things run off the page, change this!
x.axis.max <- N
y.axis.max <- N/2

x.axis.min <- 0
y.axis.min <- 0

#you can change how much time you simulate the trajecotry.
# If it looks like the epidemic never finished, make this larger

t.max <- 50

#shouldn't need to edit anything in here!

#this draws the vector/arrow field


sirflow <- flowField(SIR,
xlim = c(x.axis.min, x.axis.max),
ylim = c(y.axis.min, y.axis.max),
parameters = c(beta,gamma),
points = 19,
add = FALSE)

#this draws the nullclines


sirnullclines <- nullclines(SIR,
xlim = c(x.axis.min, x.axis.max),
ylim = c(y.axis.min, y.axis.max),
parameters = c(beta,gamma),
points = 500)

#this draws the trajectory


sirtraj <- trajectory(SIR,
y0 = c(N-I0,I0),
tlim = c(0, t.max),
parameters = c(beta,gamma))

2
400
y

200

x nullclines
y nullclines
0

0 200 400 600 800 1000

# Hint: sirtraj has the numerical solution in it. We can extract t, S(t), and I(t)
# from it using the $ function, and we can plot S and I against t:

times <- sirtraj$t


S <- sirtraj$x
I1 <- sirtraj$y

The mathematics of R0

This model can be used to predict whether an epidemic will occur or not. In the physical world,
an epidemic is said to occur if a single infectious individual within a wholly susceptible population
seeds an outbreak of cases which grows over time. In the context of the model, this means that I
increases, or that dI
dt > 0:

dI
= βSI − γI > 0.
dt
We imagine that an infectious individual is introduced at time t = 0, so that I(0) = 1 and
S(0) = N − 1, where N is the size of the population. We assume nobody is immune to start, so
R(0) = 0. Then at time t = 0 the ODE just above becomes
dI
(0) = β(N − 1) − γ > 0.
dt
β(N −1)
The condition β(N − 1) − γ > 0 is equivalent to γ > 1. If N is a large number, so that
β(N −1) βN βN
N − 1 ≈ N , then γ ≈ γ . The quantity γ is called R0 , pronounced “R-not”. (Really,

3
pronounced “R nought”. The word “nought” is British vernacular for zero.) R0 is different from
the initial condition for the recovered class R(t), which we would denote R(0). It’s unforunate that
the words “reproduction” and “removed” start with the same letter. For SARS-CoV-2, it seems
that R0 ≈ 2.5 at the beginning of the pandemic.
Later in the course of the epidemic (t > 0), provided that I ̸= 0 it is still possible to divide both
sides of the dI/dt equation by I to obtain the expression Ref f = βS(t) N . This is the “effective
reproduction number’ ’. When Ref f > 1, the epidemic is growing and when Ref f < 1 the epidemic
is contracting.

Question 2

By examining the ODEs, we were able to determine that an epidemic can occur if R0 > 1. It
turns out that R0 = βN γ has a physical meaning. The βN in the numerator represents the rate
at which an infectious individual produces new infections in the susceptible population. The γ in
the denominator is the rate at which infected people tend to recover; γ1 is the average amount of
time a person remains infected. So, βN
γ is a rate multiplying a time to give the average number of
new infections produced by an infectious person. With this in mind, why does it make sense that
R0 > 1 will lead to epidemics, and R0 < 1 will not? What happens if R0 = 1?
If R0 > 1 the average rate of infections produced by an infected person is big enough to cause expo-
nential growth in infections because patient 0 is infecting more than one other person, ultimately
leading to an outbreak. The opposite is true for R0 < 1 because patient 0 won’t even be expected
to infect one person. If R0 = 1 there would be a constant rate of infection, the infection wouldn’t
grow or decrease.

Question 3

Suppose the total population is N = 1000 people, the length of the infectious period is 5 days, so
γ = 1/5 per day, and the infection rate is β = 0.0005 per person per day. If there are initially
10 infectious individuals but everyone else is susceptible, what is R0 ? Follow the steps from the
discussion above Question 2 to arrive at an answer. Will an epidemic occur?
β = 0.0005 γ = 1/5 S(0) = 990 I(0) = 10
β∗S(0)
γ = 2.475 > 1
An epidemic will occur with these parameters.

Question 4

The code you completed/ran for question 1 ran a numerical simulation of the scenario in Question
3. Plot S and I as functions of time here:

plot(I1~times)

4
150
I1

50
0

0 10 20 30 40 50

times

plot(S~times)
1000
600
S

200

0 10 20 30 40 50

times

Question 5

Suppose the total population is N = 1000, the length of the infectious period is 1 day, so γ = 1
per day, and the infection rate is β = 0.0005 per person per day. If there are initially 10 infected
people, what is R0 ? Will an epidemic occur?

5
β = 0.0005 γ = 1 S(0) = 990 I(0) = 10
β∗S(0)
γ = 0.495 < 1
An epidemic will not occur with these parameters.

Question 6

Copy-and-paste the code from above to numerically compute the solutions to the SI equations to
verify your answer to the previous problem. Plot S and I as functions of time.

#don't forget to set eval=TRUE when you complete the code

require(phaseR) #you might need to install this package!!

#parameters to use?
beta <- 0.0005
gamma <- 1/1
N <- 1000
I0 <- 10

#change the window for nice viewing. If things run off the page, change this!
x.axis.max <- N
y.axis.max <- N/2

x.axis.min <- -50


y.axis.min <- -50

#you can change how much time you simulate the trajecotry.
# If it looks like the epidemic never finished, make this larger

t.max <- 50

#shouldn't need to edit anything in here!

#this draws the vector/arrow field


sirflow <- flowField(SIR,
xlim = c(x.axis.min, x.axis.max),
ylim = c(y.axis.min, y.axis.max),
parameters = c(beta,gamma),
points = 19,
add = FALSE)

#this draws the nullclines


sirnullclines <- nullclines(SIR,
xlim = c(x.axis.min, x.axis.max),
ylim = c(y.axis.min, y.axis.max),

6
parameters = c(beta,gamma),
points = 500)

#this draws the trajectory


sirtraj <- trajectory(SIR,
y0 = c(N-I0,I0),
tlim = c(0, t.max),
parameters = c(beta,gamma))
500
300
y

100

x nullclines
y nullclines
−100

0 200 400 600 800 1000

# Hint: sirtraj has the numerical solution in it. We can extract t, S(t), and I(t)
# from it using the $ function, and we can plot S and I against t:

times <- sirtraj$t


S <- sirtraj$x
I2 <- sirtraj$y

plot(I2~times)

7
10
8
6
I2

4
2
0

0 10 20 30 40 50

times

plot(S~times)
988
S

984
980

0 10 20 30 40 50

times
# Flatten the curve A
goal of social distancing is to “flatten the curve’ ’ so that the peak number of infectious individuals
does not exceed the healthcare system’s capacity. In questions 7-11, we’ll examine the outcomes of
this, and other public health measures, using the SIR model.

8
Question 7

The infection rate β can be modeled as


pC
β=
N
where C is the rate (per day) at which individuals come into contact with each other, p is the
probability of transmitting the disease during one such contact, and N is the total number of
people in the population. Which variable does social distancing affect?
Social distancing would affect variable C

Question 8

Which variable does masking affect?


Masking would affect variable p

Question 9

Suppose the total population is N = 1000 people, the length of the infectious period is 5 days
(γ = 1/5 per day) and the infection rate is β = 0.0005 per person per day (same values as in
problems 3-4). If the initial population has 10 infectious people and everybody else is susceptible,
what is the peak number of infectious people, I?
Looking at the graph in question 4, the peak number of infectious people is 300.

Question 10

Suppose that the government implements strict social distancing and masking policies immediately
after the 10 infectious cases are identified, bringing the infection rate down to β = 0.0003. Compute
the new R0 and the new peak number of infectious people I.
New R0 = 0.297

#don't forget to set eval=TRUE when you complete the code

require(phaseR) #you might need to install this package!!

#parameters to use?
beta <- 0.0003
gamma <- 1/5
N <- 1000
I0 <- 10

#change the window for nice viewing. If things run off the page, change this!

9
x.axis.max <- 1000
y.axis.max <- 500

x.axis.min <- -500


y.axis.min <- -500

#you can change how much time you simulate the trajecotry.
# If it looks like the epidemic never finished, make this larger

t.max <- 50

#shouldn't need to edit anything in here!

#this draws the vector/arrow field


sirflow <- flowField(SIR,
xlim = c(x.axis.min, x.axis.max),
ylim = c(y.axis.min, y.axis.max),
parameters = c(beta,gamma),
points = 19,
add = FALSE)

#this draws the nullclines


sirnullclines <- nullclines(SIR,
xlim = c(x.axis.min, x.axis.max),
ylim = c(y.axis.min, y.axis.max),
parameters = c(beta,gamma),
points = 500)

#this draws the trajectory


sirtraj <- trajectory(SIR,
y0 = c(N-I0,I0),
tlim = c(0, t.max),
parameters = c(beta,gamma))

10
600
200
y

−200

x nullclines
y nullclines
−600

−500 0 500 1000

# Hint: sirtraj has the numerical solution in it. We can extract t, S(t), and I(t)
# from it using the $ function, and we can plot S and I against t:

times <- sirtraj$t


S <- sirtraj$x
I3 <- sirtraj$y

Question 11

To compare these epidemics, plot I vs. time for (1) no safety measures as in problem 9, (2) with
safety measures that “flattened’ ’ the curve, as in problem 10. Hint: if you are a little more
creative about naming these variables which appear at the end of the phaseplane code in the earlier
problems, you shouldn’t need to re-simulate anything:

S <- sirtraj$x
I <- sirtraj$y

plot(I1~times, type='l', col='red')


lines(I3~times, type='l', col='blue')

11
150
I1

50
0

0 10 20 30 40 50

times

Submissions

To submit, provide answers to all of the problems. Knit this code into a PDF file and upload it to
Canvas. If you generate plots, make sure they appear in the knitted pdf. The suggested due date
is Monday by 11:59PM, but if you aren’t finished you can hold off submitting your document until
you feel it’s ready. Labs are graded on a “Good job!” or “Not yet” scale, with as many re-tries as
you need.

12

You might also like