Lab: Compartmental Modeling
Compartmental models are at the process end of the "pattern and
process" dichotomy. We may use these models to
- model known disease processes;
- serve as a playground, where we can experiment with a variety of effects
in attempting to capture the behaviors of a system;
- simulate a process, creating data to study.
As Dr. Jacquez says in his lecture, spatial processes can be modelled in at
least two different ways:
- one way is to create a grid of compartments (representing space), with
each cell in the grid connected to its neighbors to create diffusion;
- another way is to represent each "county" as a compartment, and allow
for flows between all compartments (providing for dispersal
behavior, as he mentioned).
Today we won't be doing anything so complicated. But it is not too grand a
step from what we do here to what is proposed above. In fact, this
might make an interesting project for someone.
In this lab, you'll be doing the exercises
suggested by Dr. John Jacquez (you should have already received a copy
of these). We will be using STELLA to do the exercises. STELLA is a piece
of software designed for creating and solving (approximately) the types of
compartmental models discussed in class this week.
Lab Objectives:
You will use compartmental models and the software STELLA to
- represent an SIS
(Susceptible Infected Susceptible) model of an epidemic in a closed
system.
- represent an SIR (Susceptible Infected Resistant) model of
an epidemic in an open system.
Lab
I'll talk you through setting up Problem 1 from the
exercises. You're on your own for problem 2 (with the exception of one hint
that I give you down below).
- The first thing you'll need to do is find STELLA (you may need
to download the demo), and fire it up (at the University of Michigan, we
access the Windows version via: Start -> Course Software -> Political
Science -> Political Science 488 -> STELLA).
- When STELLA is ready, notice that there are two windows open: the
top one is called the "High-level Mapping layer";
the inner layer is called the "Model Construction
Layer", and has those hazy buttons forming a menu system
[For a description of these layers, go to the Help -> Contents -> Controls].
- We'll start with the model construction layer
[For info on the buttons, see Help -> Contents -> Building Blocks].
Click on the little "World" icon on the left side of the Screen (under the
up and down arrows). It will toggle to a "chi-square", which means that we
are in modelling mode (where do they get these symbols, and what do they
mean???!). Away you go!
- You'll recall that there are compartments and flows. We'll start
with the compartments. Click on the "Stock"
(compartment) button (the rectangle in the upper left of the modelling
screen). Click somewhere on your modelling canvas to deposit the stock. It's
easiest to name items as you create them, so call that one "X". Do
it once again for the second stock you'll need for Problem 1.
- By the way, if you make a mistake, and add an element that you
don't want (e.g. an extra compartment), you can "blow it out of the model"
with the stick of dynamite among the menu
buttons. Cute.
- Now introduce the flows between the compartments: go to the "Flow" button (the arrow to the right over the
magnifying glass). You need to click on that button, click the mouse
inside the starting stock, and drag the cursor inside the target
stock. Now you have a flow defined. At the moment, however, it does not
relate to either of the variables. If you want to make the flow a function
of one or the other of the variables, you need to add a connector (the arrow pointing northwest near
the stock and flow buttons) into the flow from the stocks which will figure
in the flow.
- In the case of Problem 1, the top flow (from Y into
X) will be simply a constant times Y, so you add a connector
from Y into the flow: click on the connector button, click inside the
Y stock, and drag the cursor until you end inside the target
flow.
The second flow (from X into Y) is a function of both
stocks, so you need connectors from each stock into the flow.
Remember that in Dr. Jacquez's diagrams there is an implicit factor
of X or Y in any flow out of a compartment: the flow parameter
delta that he has represented in Problem
1 should be represented in STELLA as delta*Y.
- Once you have created the stocks, the flows, and connected them
appropriately, then you are ready to actually
- set the initial conditions, or initial values of the stocks, and
- write the equations of the flows.
To do the former, simply click on each stock: a window should come up, asking
you for the initial values. To do the latter, clicking on the flows will pop
up a dialog window, showing the variables which must figure in the flow
(based on the connectors you established). You should create the proper
equation with the equation editor.
- If all is right in the world, you are about ready to graph. You
need to "grab a graph" by clicking on the menu button that looks like a plot of two variables against time. Drop it into
your model environment. You'll need to tell it what variables you want to
plot. Under the main layer's Model menu item, you'll find "Define
Graph". Choose this, and select the X and Y variables to plot.
- You're almost ready to Run. Click on the Run menu item of the main
layer: you'll need to set the "Time Specs" that you want to use in your plot.
Under Time Specs, you'll decide how long you want to run your
simulation. Start with a To of 50, and leave DT at .25. You
also have the choice of a method, and by default that method is Euler's
Method. Switch to Runge-Kutta 4, which is a much better method in general
(Euler's method is only used for pedogogical reasons anymore - not for
"real" problems). You can ignore the other parameters.
- Let 'er rip! Select "Run" from the Run menu.
- One additional note, r.e. Problem 2: because that system
is open, there are flows in that model to and from the "outside world". Once
again, you use the flow button: for an "inflow", you click from the outside
and drag into a compartment; for an outflow, click inside the compartment
and drag out.
- If you time and interest, you might use STELLA to
attempt to solve the famous Lorenz Equations. These are the
simple and beautiful equations which led to the popularization of
chaos. This has nothing to do with epidemiology (as far as I know), but is
just fun.... Any scientist should at least know of these equations.
Please
evaluate this lab. We appreciate your comments!
This has been an introduction to compartmental modeling with STELLA,
and does not include examples of explicit spatial modeling. We hope,
however, that you realize that this method can be applied to create explicit
simulations of spatial processes, by incorporating space into the
compartments. For example, suppose that you had five counties, and you were
studying the spread of a disease between those counties. You might model
each county as a compartment, with flows of vectors or people between
counties (and inflows and outflows into the world beyond the
compartments).
If you have time and interest, or would like to go beyond this
exercise (as a project, say), you might consider how to create realistic
models of spatial processes using compartmental models.
- Software: STELLA
- Featured techniques: Compartmental modeling
- Readings:
none
- Data:
none
- Links:
- STELLA is marketed by High Performance Systems,
Inc.. A demo version of STELLA (suitable for these exercises) is
available from their web page. It is available for both PC and Mac platforms.
- Dr. Jim Koopman teaches a course at the University of Michigan
in
Compartmental
Model Analysis of Epidemiologic Processes. He uses STELLA in the course.
- Here's a bit on the Lorenz
Equations, which demonstrate the mathematical concept of chaos (and show
that one should be a little skeptical of the results of programs like
STELLA).
Page by Andy Long.
Comments appreciated.
aelon@sph.umich.edu