Example 4: Agent SIR

From Nova Documentation
Jump to: navigation, search

An agent-based SIR model of disease spreading. SIRs are commonly used in disease modeling. They consist of three components: the number of susceptible individuals (S), the number of infected individuals (I), and the number of recovered - or immune - individuals (R).

Viewing this model in Nova

To run this model:

  1. Launch Nova
  2. Select Menu Item File | Browse Model Library
  3. Open folder 5-Agent-Based Models and double-click AgentSIR

Agent-based SIR model

The model demonstrates a simple protocol for the spread of a disease through a population. Each individual may be in one of three states: susceptible, infected, or resistant. In the academic literature such a model is sometimes referred to as the SIR model for epidemics.

How it Works

As time progresses the individuals wander randomly through the population (individuals wandering off of one edge return on the opposite edge). At the end of each time step (tick), if a susceptable individual (colored green) is within a given radius of an infected individual (colored red), the susceptable individuual will be infected with a probability given by the INFECTION-PR-1 slider. Resistant individuals (colored blue) cannot be infected. When an individual is infected, there is a probability that it will recover and become immediately resistant (given by the GAIN-RESIST-1 slider). A resistant individual may become susceptable at any time (with probability given by the LOSE-RESIST-1 slider). The INIT-INFECTION-1 slider controls the probabilistic percentage of individuals that are initially infected. The INIT-RESIST slider controls the probabilistic percentage of individuals that are initially resistant. The controls are initially set to achieve an equilibrium.

Model Components and Layers

Universe AgentVector

The main component of this model is the Universe agentVector at the top-level. Right click to see the Universe Properties to understand how this model works from a top-down approach. We see that the Initializer component of the Universe Properties is set to "Individual" - the Individual sublayer. The Count parameter also tells us that this model calls 10 instances of Individual agents. Universe outputs to the World Raster plugin, which allows us to visualize the agents moving in space. The size of World is equivalent to the size determined in the Universe Properties: Rows and Cols is set to 50 x 50 in the Universe Properties in the model canvas and in the World properties in the dashboard.

Properties of the Universe agentVector

The agent Sublayer


Each agent in the Universe agentVector at the top-layer is determined by the Individual sublayer. Each individual agent has a disease component and a movement component. The disease component contains a State sequence which determines the disease state - S vs I vs R - by the change in the Next State Flow. The movement component has its own Theta Stock and ThetaDot Flow. These components are defined in the mover sublayer.

Distance codeChip.png

In the top left corner of the Individual sublayer we can see the contagion radius input pin, the distance to 1 codeChip, and the in radius 1 codeChip. The contagion radius input pin is set by the contagion 1 slider at the top-level. We can see in the distance to 1 codeChip that a DISTANCE() function is calculated and passed to a f variable. The coordinates for each agent are determined in the in radius 1 codeChip from the distanceTo (f) and rad (contagion radius) inputs. This code is used to find the closest agents to the current one - all the current agent's neighbors.

Returning a function from a CodeChip can be an extremely useful method within models. This allows us to pass functions like they are variables to various inputs and outputs. You can get more information about this method through the Cascade Example.

In radius codeChip.png

The mover Sublayer


In the 'Individual sublayer there is a blue mover chip which contains the mover sublayer. This sublayer takes four inputs:


This takes the Theta Stock - determined by the ThetaDot Flow.


This parameter is determined by the Speed property (yellow) at the top-layer.

InitX Properties.png

Determined by the InitX term which is calculated based on the cols parameter.

InitY Properties.png

Determined by the InitY term which is calculated based on the rows parameter.

The mover sublayer has two Stocks, X and Y, with two Flows, Xdot and Ydot, respectively. In addition to the four inputs from the Individual sublayer, X and Y movement is determined by the Xdir and Ydir terms. These direction terms are simply the Theta values transformed by cosine and sine. Cosine and sine transformations are used for two dimensional rotation.

Slider Summary

This model consists of a number of parameters controlled by their respective sliders.


Percentage of infected individuals at startup.


Percentage of resistant individuals at startup.


Probability of a susceptible individual within the radius of contagion becoming infected.


Probability that an infected individual recovers and becomes resistant.


Probability that a resistant individual becomes susceptible.

Running the Model

To run this model follow these steps at the toplayer:

  1. Click on the Capture button in the tool bar.
  2. Click Load next to "Capture".
  3. Click Exec to run the model through multiple iterations. Click Stop to stop the run before completion.
  4. To run the model step by step, click Capture, Load, Init, then Step.
  5. To rerun the model you may omit the Capture, Load steps.
  6. To have the model run more slowly adjust the speed slider above the Dashboard