Massachusetts Institute of Technology
Sloan School of Management
15.871 Introduction to System Dynamics
15.874 System Dynamics for Business Policy
Fall 2007
Understanding Epidemics Using
VensimPLE
For use with VensimPLE, version 5.7
Originally developed by Professor Nelson Repenning, MIT System Dynamics Group.
Revised by John Sterman (MIT) and Professor Hazhir Rahmandad (Virginia Tech, ISE Department).
Last revision: August 2007 by John Sterman
I. Getting Started
The purpose of this tutorial is to help you develop some familiarity with building and analyzing
system dynamics models using the VensimPLE software. To do so you are going to build a
simple model that captures the dynamics of an infectious disease like SARS.
Background: SARS, a corona-virus, emerged in Asia in 2003. To focus our modeling effort, we
will build a model to capture the course of the epidemic in Taiwan. The graphs below show the
incidence (rate at which new cases were reported, measured in people/day) and cumulative
prevalence (cumulative number of cases reported, measured in people) for SARS in Taiwan.
2
To begin you need to get VensimPLE ready for modeling. The latest version of Vensim PLE is
available for free download from [Link] . When you first open VensimPLE on
your computer, the screen should look like this:
To start working on a new model go to the File menu and select Open Model…. When the
dialog box opens, select the file SARS_Tutorial_F07. This is the template file for developing the
model in this tutorial. In general you can also start a new model by selecting File>New Model
menu.
Now save your model under a new name by selecting the File>SAVE AS menu and entering the
desired name in the File Name field and clicking on SAVE. (VensimPLE will automatically
supply the .mdl extension)∗
To begin you must choose the time horizon of your model (when your simulation will start and
finish), the appropriate time step (how accurately you wish to simulate your model), and the
units of time. To do this, select the Model menus, and then Settings…. You should get the
following dialog box:
∗
VENSIM saves every simulation run and custom graph you produce as a separate file. It supplies a .vdf
extension for simulation runs and a .vgd extension for custom graphs. These files cannot be opened from
outside the VENSIM application; they can be opened from inside VENSIM through the Control Panel.
3
Start your model of the Taiwanese SARS epidemic at day 0 (enter 0 in the INITIAL TIME box)
and simulate for 120 days (enter 120 the Final Time box). Select a time step of 0.25 days.
Check the box saying Save results every TIME STEP. Also select the Units for Time to
be Day.
Finally, before beginning to develop your model, make sure the SARS data are loaded. To do
this, first click on the icon to get the control panel (which should look like this):
If you see something different, click on the Datasets tab. To load the data file, SARSDATA,
select it by clicking and then hit the >> button which will move it to the Loaded column. The
data set is now available.
4
Note: to access that data you must use the variable names exactly as specified in this tutorial.
Now you are ready to start building your model.
II. Developing the Stock, Flow, and Feedback Structure
The VensimPLE software is designed using the metaphor of a “workbench.” The large blank
area in the middle of the screen is your work area, where you develop and analyze your model.
The different buttons on the border of the work area represent the different tools available as you
work on your model. The tools on the top horizontal row are for building your model. The tools
on the left vertical row are for model analysis. The tools on the bottom horizontal row allow you
to change the formatting of the model diagram. You will become familiar with many of these
tools as you build the epidemic model.
To begin, add a stock representing the population susceptible to SARS to your model. Click on
the button (the one with the box in it) on the top horizontal toolbar and then click in the right
center of the screen. You use this tool whenever you want to add a stock or level variable to
your model. VensimPLE then returns an empty text box and a blinking cursor. Type the
variable name Population Susceptible to SARS and then hit the return key. If the variable
name does not fit comfortably within the stock, you can re-size the stock by “grabbing” the
handle in the lower right corner (place the mouse of the small circle and hold down the left
mouse button) and moving the mouse. Your screen should now look like this:
You have just created the first variable in your model, the stock of people that could potentially
contract SARS.
5
Now add the stock of people that have contracted the disease. To do so, click on the stock tool
button, and then click again about two inches to the right of the susceptible stock. Name this
variable, Population Infected with SARS. Your screen should now look like this:
Now add the flow of infections that connects the two stocks. Click on the button in the top
horizontal tool menu. Now, click and release inside the stock of susceptible people, then move
the cursor so that it sits inside the infected stock and click and release again. VensimPLE then
gives you an empty text box and a blinking cursor. Type Infection Rate and hit the return key.
Your screen should now look like this:
6
You have now created the flow, Infection Rate, which decreases the stock of people susceptible
to SARS and increases the stock of those infected. Now you need to add the variables that close
the loops between that infection rate and the states of the susceptible and infected stocks. Begin
by adding the two auxiliary variables that determine the infection rate, Infectivity and Contacts
Between Infected and Uninfected People. To add Infectivity click on the button and then
click again approximately an inch above the infection rate flow. When the text box appears, type
Infectivity and hit return. To add the next variable, click again, this time about an inch below
the infection flow. When the text box appears, type Contacts Between Infected and
Uninfected People. Unlike the previous variables—which were either stocks or flows--the new
variables are not attached to a valve or a box. These are called auxiliary variables.
To show pictorially that the Infection Rate is determined by Infectivity and Contacts Between
Infected and Uninfected People, we connect them with causal arrows. First click on the
button to select the causal arrow tool. Now, click and release on the variable Infectivity and
then click and release again on Infection Rate. Do the same for Contacts Between Infected
and Uninfected People and Infection Rate. Make sure your causal arrows actually end on the
word Infectivity. They should not be attached to the stocks. You can delete arrows or other
model objects and variables using the tool.
Clicking on the button allows you to select the variables you have created and move them to
different places on the screen. To do this, place the arrow cursor over the variable you wish to
move, hold down the mouse button, move the variable to the desired place, and then release the
mouse button. You can also select the “handles” of the causal arrows (the small circles in the
middle of the arrow) and change the curvature of the arrow. Arrange your variables and arrows
so that your diagram looks approximately like this:
7
Now, update your diagram to show the polarity of the causal connections. First click on the
button. Then select the “handle” of the arrow you wish to label by clicking and releasing on the
small circle in the middle of the arrow (the handle darkens when selected). Now, with the handle
selected, click and release the button on the bottom horizontal toolbar. You then see a pop-
up menu that looks like this:
Click and release on the desired label, and it will show up in the diagram. Label your two causal
arrows so your diagram looks like this:
Infectivity
Population + Population
Susceptible to Infected with
SARS Infection Rate SARS
+
Contacts Between
Infected and Uninfected
People
Now, using the same steps discussed above, add the necessary variables, links and labels so that
your diagram looks like this:
8
Note that you can select multiple links or variables at the same time, by holding down the SHIFT
key while selecting the objects. This is useful for assigning multiple polarities at the same time.
You may want to slide the handle of each arrow close to its arrowhead, so each label is clearly
associated with its causal arrow. Also, to move the polarity labels (the ”+’s” and “-‘s”) to the
other side of the arrow, right click on the arrow handle (the small circle) and you will get the
following menu:
With this menu, you can change the location of the arrow polarity and arrow width.
Finally, you may wish to label the loops you have just created. To do this, click on the
button and then click in the center of the feedback loop. You can use this tool to create
comments that, while having no structural use, can greatly help someone else understand your
9
model diagram. After clicking in the center of the reinforcing loop (the one linking the infection
rate and the infected population), you should see the following dialog box:
To label the reinforcing loop click, on the Loop Clkwse button in the Shape box; click on
Center in the Word Position box; and type R in the Comment box. Click on the OK button or
hit return. The loop identifier will be displayed. Now select the comment tool again and
click below the loop identifier labeled you just created. Type the name of the loop into the
Comment field. A good name for this loop is the “Contagion” loop. Click on the OK button or
hit return. Now you will see the loop type and name together. Repeat this process to label the
balancing feedback on the left side of your model diagram, noting that this feedback moves
counterclockwise. Name that loop the “Depletion” loop. Your model should now look like:
IMPORTANT: Note that the arrow around each loop identifier flows in the same direction as
the loop to which it refers. The reinforcing Contagion loop is clockwise in your diagram, so its
loop identifier is also clockwise; the Depletion loop on the left moves counterclockwise, so its
identifier moves clockwise. Labeling and naming your loops is an important step to help your
audience see the feedback structure of your model.
10
III. Specifying Equations for Your Model
Now that you have developed a complete stock, flow, and feedback representation for the SARS
epidemic, you need to write equations for each of the variables.
To begin, click on the button on the top horizontal toolbar. The variables in your diagram
become highlighted.
A highlighted variable indicates that the equation for that variable is incomplete.
Variables in system dynamics models are classified as either exogenous or endogenous.
Exogenous variables are those that are defined independent of other variables of the model.
They are functions of time: Exogenous Variable = f(t). Of course the exogenous variables may
be constants, in which case they are called parameters. Endogenous variables are members of
determined based on other variables: Endogenous Variable = f(x, y, z) where x, y, z are other
variables in the model (endogenous or exogenous). Your model has three exogenous inputs—
Infectivity, Contact Frequency, and the Total Population—and six endogenous variables—
Population Susceptible to SARS, Infection Rate, Population Infected with SARS,
Probability of Contact with Infected Person, Susceptible Contacts, and Contacts Between
Infected and Uninfected People.
Start by writing the equations for the endogenous variables. Begin by clicking on the Infection
Rate. You then see the following dialog box:
11
Good modeling practice requires that each equation in a model have three elements: (1) the
equation itself; (2) specified units of measure; and (3) complete documentation.
You enter the equation in the box to the right of the = sign. You enter the units of measure in the
text field to the right of the word Units. Equation documentation is entered in the box to the
right of the word Comment.
Write the equation first. Begin by clicking in the box to the right of the equal sign. Now, look in
the box in the middle right. Here Vensim has provided you with the two variables that your
model diagram shows as influencing the infection rate, Contacts Between Infected and
Uninfected People and Infectivity. A simple and plausible formulation for the infection rate is
simply to multiply the number of contacts by the infectivity (which, by definition, is the fraction
of contacts that result in transmission of the disease, or equivalently, the conditional probability
of transmission given a contact between an infected and susceptible individual). To enter this
equation first click on the Contacts Between Infected and Uninfected People variable, which
will now appear in the equation box to the right of the = sign. Now either click on or type “*” to
represent multiplication. Complete the equation by clicking on Infectivity. Your dialog box
should now look like this:
12
Now fill in the units. Infection Rate represents flow of people through time, so the appropriate
unit of measure for this equation is people/time unit. Since you already chose to run the model
in time steps of 1 day, the appropriate unit is people/day. Type People/Day in the units field.
(The next time you specify the units for a variable in this model, People/Day will appear in the
units pull-down menu. You can click on the arrowhead to the right of the units field to see units
already specified for other variables in the model, and then select units you’ve already defined
from that list as appropriate.)
Finally, provide a description of this equation in the comment field. A good comment will be
brief but also give the reader some sense of the logic behind the equation as well as state the key
assumptions. For example, one might write for this equation:
The infection rate is determined by the total number of contacts between infected
and uninfected people each day and the probability that each such contact results in
transmission from the infected to unifected person (denoted infectivity).
Your dialog box should now look like this:
13
Click on OK or hit return and your diagram will look like this:
The Infection Rate is no longer highlighted, since you have just specified its equation.
14
Now write the equation for the stock of susceptible people. Begin by clicking on the susceptible
stock. You should get a dialog box that looks like the following:
You enter the equation for the stock in the box to the right of the word Integ. Integ stands for
“integrate” and simply means that the stock at any moment in time is equal to the integral of all
the inflows to less all the outflows from the stock, from the start time of the simulation (plus, of
course, the initial value.*
When you created the stock, flow, and feedback diagram, you made the Infection Rate an
outflow from the stock of People Susceptible to SARS. VensimPLE captures this stock-flow
relationship by showing the equation for the susceptible stock as Integ(-Infection Rate). This
means that at any point in time the susceptible stock is equal to its initial condition less all the
people that have flowed out of it up to that point in time.
Now we need to specify the initial value for the susceptible stock. You enter it in the box just to
the right of the words Initial Value. Initial conditions can either be numbers or other variables
in a model. It is usually better to initialize a stock in terms of a parameter, because you can then
alter that parameter easily for sensitivity and policy testing. In this case it is a good idea to
initialize the stock based on another variable, specifically the Total Population (since there was
*
Stock = INTEG(Inflow – Outflow) with an Initial Value of Stock(t0) is equivalent to:
T
Stock(T ) = # ( Inflow(t) " Outflow(t))dt + Stock(t )
0
t0
! 15
no vaccine for SARS, no one had prior immunity). Enter Total Population in the Initial Value
box.
Your equation for the Population Susceptible to SARS indicates that the susceptible population
is the initial value at the start of the simulation less all of those people who contract the disease.
You still need to specify the unit of measure and document your equation in the comment field.
The Population Susceptible to SARS is a stock and its units are people. A sample comment for
Population Susceptible to SARS is:
The Population Susceptible to SARS is the equal to the population susceptible prior
to the onset of the disease less all of those that have contracted it. It is initialized to
the Total Population, which assumes that all individuals are initially susceptible (no
prior natural or vaccine-conferred immunity).
After completing the dialog box, click OK or press return. Your model diagram should now
look like this:
Following a similar process to the one outlined above, you should now be able to specify the
equations for the remaining endogenous variables, Susceptible Contacts, Contacts Between
Infected and Uninfected People, and Probability of Contact with Infected Person:
Susceptible Contacts= Population Susceptible to SARS*Contact Frequency
(People/Day)
Contacts Between Infected and Uninfected People=
Susceptible Contacts*Probability of Contact with Infected Person
(People/Day)
Probability of Contact with Infected Person= Population Infected with SARS/Total Population
(Dimensionless)
16
Finally, you need to specify equations for the exogenous variables, Infectivity, Contact
Frequency, and Total Population. Begin with Total Population. Clicking on it should bring
up the following dialog box:
Note first that there are no inputs to Total Population, just as you specified in the diagram,
indicating that Total Population will be a constant. The data suggest that in Taiwan, the
cumulative number of cases eventually rose to approximately 350, so start with that value for
Total Population (you may want to revisit this assumption later). You also need to specify units
of measure and provide a comment. When you are finished your dialog box will look like this:
17
Following this example, complete the equations for the other two parameters, Contact
Frequency (people/day) and Infectivity (dimensionless). You do not have hard data for the
values of these parameters so you will need to use your judgment to determine appropriate
values. Later we will discuss how you can test the model’s sensitivity to these assumptions.
Finally, set an appropriate initial value, units, and comment for the Population Infected with
SARS.
Now we will add the structure to allow us to compare the behavior of the model to the data for
the SARS epidemic in Taiwan. We have created a file containing these data (the file
[Link]). To compare the model against the data we need to create variables that
correspond to the incidence of new cases, denoted New Reported Cases, and the prevalence of
SARS, denoted Cumulative Reported Cases. Because the data file uses these variable names
you must create variables in your model with exactly the same names.
Using the stock variable tool create a new stock called Cumulative Reported Cases, placed
a few inches below the current structure. Then use the flow tool to create an inflow to that
stock called New Reported Cases. This structure captures the relationship between incidence
and prevalence: As new cases are reported the cumulative number of cases increases. Your
diagram should look like this:
18
Now you need to define New Reported Cases. For simplicity we will assume that new cases
(the infection rate) are immediately diagnosed and reported. In reality, of course, there is a delay
between the infection rate, diagnosis, and reporting through the public health system. To define
New Reported Cases as equal to the infection rate you could simply draw a causal arrow from
the Infection Rate to New Reported Cases. However, doing so would clutter the diagram.
Instead, we will use a Shadow Variable. Select the Shadow Variable tool from the top
toolbar. Click about an inch to the left of New Reported Cases. The following dialog will pop
up, listing all variables in the model. Select the Infection Rate, then click OK.
Vensim creates a copy (Shadow) of the Infection Rate. Shadow variables are gray and placed
within braces: <Infection Rate>. Your diagram should now look like this:
19
Shadow variables enable you to keep your model diagrams clean and readable. Now draw a
causal arrow from the shadow <Infection Rate> to New Reported Cases:
Use the equation tool to define New Reported Cases as equal to the Infection Rate. The units
for New Reported Cases are People/Day. Add an appropriate comment (point out that you are
assuming that new cases are reported immediately). Now define the stock of Cumulative
Reported Cases. You will see that Cumulative Reported Cases is already defined as the
integral (accumulation) of New Reported Cases. You need to supply the initial number of
reported cases, which is zero. Specify the units as People and add an appropriate comment.
Note that in this initial model Cumulative Reported Cases will equal the actual population
infected with SARS, because you have assumed that New Reported Cases equals the actual
Infection Rate. Why then bother to define Cumulative Reported Cases separately from the
Population Infected with SARS? There are two reasons: (1) They are conceptually different: the
actual number of people infected with SARS differs from the number reported through the public
health surveillance system (there may be delays and measurement errors you might want to
capture later); (2) you might later alter the model structure so that the equivalence of the two
stocks no longer holds (for example, capturing the rates of recovery and mortality from SARS.
IV. Using the Model Structure Analysis Tools
You are now ready to analyze your model. VensimPLE provides several tools for analyzing and
understanding the structure of your model.
By far the most important of these is the unit-checking function. To access this tool, go to the
Model menu and select Units Check. An important feature of any system dynamics equation
is dimensional consistency. This is just a fancy way of saying that the units of measure must be
the same on both the left and right sides of the equation. For example, if you have followed the
instructions in the tutorial so far and you run the units check, you will get the following message:
Followed by:
20
The problem is that the equation for Susceptible Contacts is not dimensionally consistent: The
right and left sides of the equation have different units. Susceptible Contacts is measured in
contacts per day, but, in the current formulation, multiplying the Population Susceptible to
SARS by the Contact Frequency yields a value with units of people*people/day.
The cause of the problem is that unit of measure for Contact Frequency is incorrect. The
Contact Frequency represents the number of contacts each person makes per day, not the total
number of contacts (which is captured by the variable Susceptible Contacts). To fix this
problem, change the units of measure for contact frequency to be people/person/day. After you
do this, run the units check again.
21
Unfortunately, this change doesn’t quite fix the problem. You will still find a unit error with the
following diagnostics:
The problem now is that Vensim does not recognize that people and person represent the same
unit of measure. Fortunately, this problem can be fixed. Go to the Model menu and select
Settings…. When the dialog box appears, select the Units Equiv button, which should then
produce the following dialog box:
The units equivalent feature allows you to specify which units you wish Vensim to recognize as
the same. This feature is often used to match singular and plural forms of the same word, such
as person and people. To use this feature simply type people and person separated by a comma,
“people, person” and click on the Add Editing button. When you are done click OK. Now
when you run the units check you should get the following:
22
The units in your model now balance.
The other tools are also useful. The and the buttons create “causes” and “uses” trees
for the selected variable. To use these tools, you need to first “select” a variable. Do this by first
clicking on the button and then clicking on the variable you wish to select. Clicking on a
variable selects that variable to the workbench. You can tell which variable is selected by
looking at the top border of the VensimPLE window. If you select the variable Infection Rate,
the top border will look like this.
Having selected Infection Rate, clicking on the two “causes” and “uses” buttons in sequence
gives you:
Probability of Contact with Infected Person
Contacts Between Infected and Uninfected People
Susceptible Contacts Infection Rate
Infectivity
and
Population Infected with SARS Probability of Contact with Infected Person
Infection Rate
Population Susceptible to SARS Susceptible Contacts
The tool identifies all the feedback loops in which the selected variable is a member, and the
button creates a documented listing of the equations in your model.
23
V. Simulating Your Model
VensimPLE also has tools to help you analyze the behavior of your model. Before doing this,
however, you must actually simulate the model so you have some behavior to analyze.
To run a simulation, you first need to choose a name for this particular model run. It is helpful to
choose names that suggest some idea of what is being tested rather than using names like SIM1,
SIM2, etc. Since this is the base case run for your model, you might choose to call the run
BASE.* The name of the simulation is entered in the white box in the analysis tool bar. The
default name for any simulation run is Current. Change this to Base.
To run a simulation, click the button and your model will start simulating.
Once the simulation run is completed, you can look at the results of your simulation.
VensimPLE provides many tools with which to view simulation output. The most basic of these
is the graph. To create a graph of the Cumulative Reported Cases, first click on the tool
and then click on the desired variable.
To see a strip graph, click on the button in the left toolbar. You will then see the output of
your model, compared against the data. The behavior of your model will depend on the
parameters you have chosen. My parameter values and initial conditions generated the following
graph:
*
Advanced Tip: VensimPLE also offers you the choice of two numerical integration methods, Euler and Runge-Kutta 4.
Runge-Kutta 4 is a more accurate simulation method, but it is also more computationally intensive. Generally it is better to
use the Euler method and change only if you believe you are seeing integration error. Read Business Dynamics, Appendix A,
for further details.
24
Besides the graph, VensimPLE provides many other ways to examine simulation output. The
button displays a strip graph of the currently selected variable, along with graphs of all the
variables that determine the selected variable (the causes). Clicking this button gives you:
VensimPLE also can present the output in the form of a table rather than a graph. To see a table
simply click on the button.
Having examined the output of this simulation, you may wish to run additional simulations under
different assumptions. For example, what would happen if you cut the contact frequency in half?
One way to do this is simply to change the model equation in the variable’s equation box. This
is time-consuming and error-prone, however, since you must remember to go back and change
the parameter back to its original value before testing another assumption. If you change a
variable’s formulation in its equation box, it remains as you specify until you change it again.
So, if you want to alter a variable’s value only once, to observe its effect on the simulation, and
then have the variable revert to its original value, you can use the Parameter Changes button,
accessible on the analysis tool bar.
25
Test the effect of a change in the Contact Frequency by clicking the button. Your screen
should now look like this:
To change the contact frequency for this simulation, click on Contact Frequency and its current
value will appear in a box. Type in a smaller value (such as a 50% reduction) and hit return.
Before simulating, make sure you the name of the simulation so that you can compare the two
different runs. Select a name that helps describe the changes you made, for example, “Low
Contact Frequency”.
To run the simulation with your new value for the contact frequency just click on the
button. Note that you have changed the contact frequency for that run only, and have not
changed it in the underlying model equations.
26
Now when you select any of the model output tools, they show the results from both simulations
(along with the data). For example, the graph tool displays:
If you do not wish to see the previous (base) run displayed with the new simulation run, then
click on the button. This is the Control Panel. Click on the Datasets tab and the dialog
box will display the three data sets you have created so far:
To de-select a run, simply double-click on it. The run you de-select will now appear on the left
side of the dialog, in the “available” column. It remains stored on your hard disk and can be re-
loaded again any time you wish to display it. Clicking on a run in the “loaded” column will also
move it to the top of the list of loaded runs so you can control the order in which runs are listed
in output such as graphs.
27
The control panel also allows you to select a given variable (chose the Variable tab). Modify
the horizontal axis of your graphs (the Time Axis tab), and create custom graphs (the Graph
tab). See the help menu for more information on all of these features.
Vensim also offers another simulation mode, called SyntheSim, to help you analyze your model.
To activate Synthesim click on the button at the top of your screen. When you do this,
SyntheSim is activated and your screen should now look like this:
All the constants in your model will now appear with sliders while the other variables will have
small graphs superimposed on them showing the behavior of each variable under the current
slider settings. With Synthesim activated you can now change any of the constants in your
model using the sliders and Vensim will automatically re-simulate the model and provide
updated output.
For small models such as this one, the response is almost instantaneous. Synthesim can be
extremely useful in developing intuition as to how your model’s behavior changes as its
underlying parameters are adjusted. You may wish to use synthesim now to find parameter
values that provide a good fit of your model output to the data for cumulative reported cases.
28
VI Summary of Learning Points
In this tutorial you learned the basic mechanics of working with Vensim PLE software to build
simulation models. You also learned how to simulate a model and analyze its behavior. Besides
learning to work with the software, you also became familiar with some of the vital practices in
building robust simulation models. These include:
- Documenting your model as you build it by putting appropriate polarity on the links,
distinguishing major feedback loops, and leaving comments to explain the equations.
- Specifying the units for your equations.
- Distinguishing between different concepts, even if they can be similarly formulated (e.g.
the “Cumulative Reported Cases” and “Population Infected with SARS”).
- Making sure your model passes the unit consistency test.
- Exploring the behavior of your model using a variety of output tools
- Learning how to vary parameters to explore the sensitivity of your model to assumptions.
Following the procedures described here will speed your learning and save you time in the long
run. Cutting corners causes confusion and delay.
Finally, save your model often and always make backups of your work.
29