The S-I-R Epidemic Model

by
K. D.  Stroyan
University of Iowa

copyright 2007 by Keith Stroyan - All rights reserved.

NoteBook Overview

The purpose of this NoteBook is to show you how to perform basic computations of the S-I-R model using Mathematica and to get some practice editing with the "mouse."  A later NoteBook will take a more sophisticated "loop" approach to the computations.  Use this NoteBook to check your own calculations from Exercise 2.1.5, check your understanding of how Mathematica works, and practice using the mouse.

What follows is a partial program that will do the calculations you have already done by hand in Exercise 2.1.5.  Once you replace the question marks with correct expressions and <Enter> the computatons, you will have a check on your work.

References to the Text

This NoteBook compares the hand computations of Exercise 2.1.1 with computer calculation.  This is  Exercise 2.1.5.

Step-by-step Computation

The disease-specific parameters:

First we will define the parameters a and b in the cell below.  The question marks ?? need  to be replaced by the correct computation, in this case  a = b *c.

To replace question marks with a correct expression, position the cursor to the right of the question marks, hold down the mouse button, and drag the cursor over the question marks.  When the question marks are all darkened, start typing the correct expression.

When you have eliminated the question marks from this cell, "compute" it by pressing the <Enter> key on the number pad or holding <Shift> and pressing the <Return> key.

Complete the commands and press <Enter> for the rate parameters.

b=N[(1/11)]
c=6.8
a=??

The initial values of the variables:

Now provide Mathematica with the starting values for the number of people in the population that are susceptible, infected, and recovered.  In the cell below we will let sNr denote the number of people susceptible, iNr denote the number of people infected, and rNr denote the number of people recovered.  We let  n  denote the total population.  We will also define a variable t which will denote the number of days that have passed.  Enter the cell below after you have removed the question marks.

We did not use upper case letters S, I, and R for the numbers as in the text, because Mathematica reserves some uppercase letters for special things (such as I = Sqrt[ -1].)

Complete the commands and press <Enter> for the initial values.

t=0;
sNr=10000;
iNr=??
rNr=19000;
n=sNr+??

The first day:

Remember how you performed the hand calculations for the S-I-R model.  First you used the above values of "S", "I" and "R" to calculate the change in the number of people in each category,  and then added the changes to the above values to update them.  The cell below will perform the calculation in the same way.  First it computes the changes, then it computes the new values.  It will also keep track of the day.  Enter it when you have completed the commands, by typing the formulas from the text in Mathematica syntax.

Complete the commands and press <Enter> for the new values at the start of day 2.

tChange = 1 ;
sChange = - a (sNr/n) iNr ;
iChange = a (sNr/n) ???? - ???? iNr ;
rChange = ???? ;

t = t + tChange ;
sNr = sNr + sChange ;
iNr = ???? ;
rNr = rNr + rChange ;

Print[ "Day ", t ] ;
Print[ sNr ] ;
Print[ ???? ] ;
Print[ rNr ];

These results (after <Enter>ing) should match your own calculations of the number susceptible, infected, and recovered after the 1st day of the epidemic in the first column of the table in text Exercise 2.1.1.

The second day:

To get the values after the 2nd day of the epidemic you could simply enter the above cell again since it has updated the values of t, sNr, iNr, and rNr already.  If you did this, however, the day 2 results above would disappear and be replaced by the new results.  To avoid losing the above results you can make a new cell below that will perform the same calculation.

Here is a quick review of  the copy-paste method:

1.  First  highlight the cell to be copied.

2.  Once it is highlighted hit the <Command> key and the <C> key (for copy) at the same time.  Now the computer has a memory of this cell.

3.  Now move cursor to where you wish to put the information and click the mouse. (There should be a grey line if it is done between existing cells.)

4.  Now you are ready to paste by hitting <Command> and <V> (for paste) at the same time.

Now you can enter the next day's numbers without losing your original work.

Subsequent days:

Copy and paste the calculation cell above 2 more times below.  Do this to practice some more with the mouse, and save all of Mathematica's calculations so you can compare them with your own.  Enter the computations in sequence and compare the results with your hand computations.

Complete Sample Computation

See the NoteBook SecondSIR.nb

Exercises

Exercise 2.1.5

Run the Mathematica computations above to check the values you computed by hand for the table in Exercise 2.1.5.