Guides‎ > ‎

Social networks and vaccination

BehaviourComposer: ignore everything before this.

Here we will model a disease by building interactions of individuals rather than modelling mathematically with variables that represent entire populations. This is variously called Individual-based modelling (IBM) or Agent-based modelling (ABM).

In the first part (1-6), you will build a model equivalent to the SIR (Susceptible, Infected, and Recovered) model. After modelling the infected, recovered, and vaccinated, you'll explore the influence of social heterogeneity on the spread of diseases. This would be very hard to model analytically with equations that model populations.

In the final part of the practical you'll model a vaccination policy that targets super-spreaders.

Please go through the instructions carefully, step-by-step. There might be slight differences depending upon the web browser that you are using. You can use the browser's back and forward buttons to undo and redo. You can refresh the page to restart everything (only the open tabs will be lost -- your model will be restored).

Everything you'll need to construct the model is in this page. If you want to explore other behaviours visit the library of micro-behaviours.

Step 1. Getting started

You'll be constructing the IBM using a tool called the BehaviourComposer that you access via a web browser. The software enables you to build a computer model by pulling together (or composing) blocks of computer code called micro-behaviours, which are simply web pages that contain NetLogo code with explanatory text. 

  1. First, to make it easier to move between this guide and the Composer scroll down to the bottom of this page and click on the check box labelled Split screen between this panel and everything elseThis will make it easier to work through the steps below and build up your model. 
  2. Click on INITIAL MODEL and select Replace current model to load a model containing only a population of susceptible individuals and some technical machinery. This model has no infected individuals nor a mechanism for spreading an infection. You'll build on this initial model in the steps below.

Step 2. Explore the initial model

The micro-behaviours you have just brought into the Build area of the BehaviourComposer can be compiled into a computer program using the Send to NetLogo tab. Clicking this tab causes the BehaviourComposer to strip the NetLogo code from all the micro-behaviours and combine them to run in NetLogo.

Image of composer panel
Image of run panel
 You compose your model by assembling micro-behaviours  The code in the micro-behaviours is assembled into a computer program. The program is loaded into NetLogo (when launched as BC2NetLogo).
  1. Click on the Send to NetLogo  tab in the Composer Area
  2. Once the program has loaded (might take a few seconds) click on the SETUP button to initialise the model. 
  3. Change the slider labelled the-initial-susceptible-population and click on the SETUP button again to see what happens. 


  • To change the slider by small increments use the mouse to click on the slider to the left or right of its current value.
  • Only the Person prototype is an agent within the model, the others contain micro-behaviours that support the model or create graphs and sliders.

Step 3. Create some infected individuals

  1. Open the Initial infection cases micro-behaviour web page (by clicking this link) and add it to your model:
    1. Click on the button at the top of the page labelled Initial infection cases 
    2. Select the menu item Add to a Prototype
    3. Once taken to the Composer area of the BehaviourComposer click on the upper area of  the prototype called Observer.
  2. Run your model in the Composer Area again and you'll see an infected individual displayed in yellow after clicking the SETUP button. 
  • It is important that Infect initial cases be added to a prototype with only one instance (e.g. Observer) since it selects the-initial-infected-population number of individuals from the set of Persons and sets their state to infected and hence should only happen once.

Step 4. Create a social network

Rather than model perfect mixing of people within the population we will model a network where each individual has a limited number of contacts. Here we model each individual to have the same number of potential contacts, called acquaintances. Diseases can be transmitted between individuals that are acquaintances in our model.

  1. Open the Constant social network micro-behaviour web page and add it to the Observer prototype (the position in list does not matter). This gives every individual the same number of acquaintances.
  2. Run your model in the Composer Area and click the SETUP button. You should see grey lines that represent the acquaintance relationships between individuals.
  • You may wish to take some time to read the micro-behaviour pages you add to your model. The micro-behaviour you just added has important information about how the NetLogo code works e.g. see the section "How this works" at the bottom of the page.

Step 5. Spread the infection

  1. Add the Contact acquaintances micro-behaviour to the behaviour list called To do when infected.
  2. Now for one of the more tricky actions you need to perform with the BehaviourComposer: add a micro-behaviour to a list inside another micro-behaviour! To do this:
    1. Open the Contact acquaintances micro-behaviour and click on the button for the Possibly become infected micro-behaviour and select Open from the menu that pops up. 
    2. Open the Change colour of link with infector micro-behaviour, click on the button at the top of the page and select the menu item Add to a list
    3. Go back to the Possibly become infected micro-behaviour and click on the Behaviours list to add it to the list inside this micro-behaviour. (You should see something like the screenshot below.)
    4. Run your model from the Composer Area, click SETUP then GO and you should see the infection spread. The links that transmitted the disease should turn red because you added Change colour of link with infector. The model is programmed to stop when either no one is infected or no one is susceptible. You can manually stop the simulation by either pressing the PAUSE button or pressing GO a second time.

  • Contact acquaintances works by multiplying the value from the-encounter-fraction slider with the number of acquaintances to determine the individual's contact rate. Since at this point we are modelling a population where every individual has the same number of acquaintances the contact rate is a constant and is very similar to the aggregate SIR model's contact rate. If the value is not an exact integer then the fractional part is used to determine the odds of contacting an additional person. E.g. a contact rate of 1.2 will contact one acquaintance 80% of the time and two 20% of the time. The odds of a contact between an infected and susceptible person resulting in a new infection is determined by the-infection-odds slider.

Step 6. Add recovery

  1. Add the Schedule recovery micro-behaviour to the To do when infected behaviour list in the Composer Area . 
  2. Run your model, click the SETUP and GO buttons.
  • The Schedule recovery micro-behaviour models recovery by adding three micro-behaviours that change the state, change the display colour, and stop contacting acquaintances. Of course, real people will continue to contact people after recovery but it will have no effect on the spread of the disease. 
  • In reality when someone is infected there is, of course, no mechanism that sets a timer for when the person will recover. Since we are modelling recovery as a process that does not depend upon any interactions or later events (e.g. taking a drug) this is a simple way of implementing recovery that is equivalent to more detailed modelling. 
  • Note that graphs are being produced when you run the model - you may need to  scroll down or move the divider to see it.

Step 7. Add vaccination

Next we model a public health authority with only a limited amount of a vaccine. 

  1. Add the Randomly vaccinate a proportion of the population micro-behaviour to the prototype called Public Health Authority
  2. Run your model and experiment with different values. Even when all the parameters are left unchanged do you see different outcomes for different runs?
  • Depending on the value set on the-fraction-vaccinated slider a random fraction of the population will be vaccinated. This is modelled as setting the state to vaccinated (instead of susceptible) and changes the colour used to display the individual to green.

Step 8. Build a different social network

In reality, individuals differ in the number of other individuals with whom they are likely to be in infectious contact. Here we shall investigate how different networks can affect the spread of a disease (note, the average number of contacts will remain the same). 

  1. Go to the Composer Area and click on the Constant social network micro-behaviour and Inactivate it. 
  2. Add the Power law social network micro-behaviour to the Observer prototype.
  3. Add the Size proportional to number of acquaintances micro-behaviour to Person. Inactivate the Small size micro-behaviour.
  4. Run the model and click SETUP a few times to see a variety of starting conditions.
  • The Power law social network micro-behaviour implements a power law distribution of the number of acquaintances each individual has. A few will have very many acquaintances while most will have few. 
  • The power law distribution approximates the situation in sexually transmitted diseases such as HIV where some individuals have many sexual encounters while others have very few or none. 

Step 9. Using the model to study different approaches to vaccination

In the Public Health Authority prototype there is a micro-behaviour called Vaccinate random proportion of population which, as the name suggests vaccinates a proportion of the population randomly so that these individuals do not become infected. This behaviour can be contrasted with the Vaccinate most highly connected individuals micro-behaviour to see the effect of targeting vaccination towards the most connected individuals in the network. 
  1. Inactivate Vaccinate random proportion of population
  2. Add Vaccinate most highly connected individuals to the Public Health Authority. Note that this behaviour replies upon the report more-link-neighbors behaviour being part of the model. You can add it to Support.

Step 10. Performing a parameter sweep with the BehaviorSpace

Once you've created a model, and experimented with it for a while, you may want to explore its parameter space in a more systematic and thorough manner. We've created a quick guide to help you learn how use the BehaviorSpace which is part of the NetLogo application. 

Step 11. Further Steps

Time permitting there are many other questions you may wish to explore with your model. You can use the library of micro-behaviours for modelling epidemics and interventions. Examples include:

  • What fraction of targeted vaccinations are equally effective as the fraction of non-targeted vaccinations? 
  • What if the targeting introduces a delay in the distribution of the vaccine? What is the maximum delay where targeting is still helpful?
  • What effect do the different vaccination policies have on the duration of the epidemic?
  • What is the minimum amount of vaccine that would reduce the odds of infection below 1%?
  • How do the dynamics change if you change the average number of acquaintances per person?
  • How different would your conclusions be if the disease had different characteristics? E.g. if the infection had a very long duration but low odds of transmission?
  • Explore the effect of a social network with a normal distribution.

This guide was developed by Robert Belshaw, Ken Kahn, and Howard Noble.
BehaviourComposer: ignore everything after this.