Over the next few weeks, we will learn about how to model the spread of an infectious diseases through the population. We will begin with the simplest model, and slowly add more features to our model to make it more expressive of the real world.
The simplest model of infection is known as the SIR model. The three letters stand for:
The SIR model does not apply to all diseases: for example, you can catch a cold or a flu again after catching it once. In such a case, we would use an SIS model (the last S is Susceptible) instead.
However, for diseases like chicken pox and measles, where getting the disease once offers immunity against getting it again, the SIR model is suitable.
Before reading on, watch the following video (11 minutes) to get a better understanding of the SIR model. Pay particular attention to how they determine the rates of infection ($b$ and $a$ in the video):
from IPython.display import YouTubeVideo
YouTubeVideo('XWXqXzAYe4E', width=800, height=300)
The parameters of the SIR model may be summarized in the following diagram:
$$ S \xrightarrow{\quad \beta\,SI\quad} I \xrightarrow{\quad \gamma\,I \quad} R $$This diagram includes:
The state variables $S,I,R$ depend on time $t$, so they will sometimes be written $S_t, I_t, R_t$ (or $S(t), I(t), R(t)$) if we wish to emphasize this. So the diagram should really look like:
In contrast, the parameters $\beta$ and $\gamma$ are constant and do not change with time.
For our purposes, we will assume that time is discrete and takes values $0,1,2,\dots$, rather than being continuous.
Let's look at each of the arrows in the diagram one at a time.
Let's start with the second arrow: $I \xrightarrow{\gamma I} R$. This tells us that Infectives become Removed at a rate proportional to the number of Infectives.
Which of the following equations describes how $I$ changes over one time step? (ignore any effects from the first arrow)
It might be clearer if you move $I_t$ to the RHS of the equations
Which of the following equations describes how $R$ changes over one time step?
Now let's look at the first arrow $S \xrightarrow{\beta SI} I$. This is a bit more complicated.
Which of the following equations describes how $I$ changes over one time step? (ignore any effects from the second arrow)
Which of the following equations describes how $S$ changes over one time step?
Putting it all together, complete the following equations:
Using your answers to question 5, replace the 3 question marks in the function update(S,I,R)
with the appropriate code. You may just write out those 3 lines when submitting your answer (instead of the whole code).
# Parameters
beta = 0.6
gamma = 0.2
# Initial state (represented as fraction of the total population)
S = 0.99
I = 1-S
R = 0
# Total population
N = 10000
# Number of iterations
iters = 50
# Function to update state
def update(S,I,R):
newS = ?
newI = ?
newR = ?
return (newS, newI, newR)
# Run the simulation and print the numbers at every time step
print("t", "\t", "S", "\t", "I", "\t", "R")
print("---------------------------------")
for t in range(iters):
print(t, "\t", int(S*N), "\t", int(I*N), "\t", int(R*N))
S,I,R = update(S,I,R)
if S < 0: # If number of susceptibles goes below zero, stop the simulation
break
beta
and gamma
(and also N
, iters
and the initial S
). How do these values affect what happens in the long run? Next time, we will try to answer some of these questions. We will also learn how to make nice graphs showing the progress of infection over time - this makes it easier to quickly see what's happening, instead of having to look at a table of numbers.