Home page

Objectives

The aim of this tutorial is to perform scenario analyses with an individual-based model in R based on the random walk dynamics from the previous tutorial.

In this session, you will

  1. Run the IBM with different model parameters
  2. Discuss the impact of transmission parameters and model features

The best thing to do is to read each section and type (or copy and paste) the R commands (in grey boxes) into your own R session to check that you understand the code. Hands-on questions are indicated in red

Set working directory

The first step when creating a new R file is to specify a working directory. You need to tell the R session where you want it to work. To do this you use the command to “set the working directory” or setwd().

You can label this working directory as ‘home’, and have other locations stored for plotting or for getting data. This location should be an existing folder on your computer. For example:

home <- "~/Documents/Modelling_intro/" ## on a OS X
home <- "C:\\Documents\\Modelling_intro\\" ## on windows
setwd(home)

Load model code

If the curl package is not installed yet, you can do so by

install.packages(curl) # install the curl library (to import data)

Please load the IBM functions we prepared on the GitHub repository. Using your skills from the previous tutorial(s), you should be able to code this model with random walks and vaccination yourselves.

# load package 'curl'
library('curl')

# download R file with IBM function
curl_download("https://github.com/lwillem/modelling-intro/raw/master/lib/ibm_functions.R", destfile = "ibm_functions.R")

# load the IBM functions
source('ibm_functions.R')

Scenario analyses

First, let’s run the model with the default parameters:

# you can run the IBM with default parameters (see console)
run_ibm_random_walk()

## [1] "MODEL PARAMETERS"
## [1] "pop_size: 1000"
## [1] "num_days: 50"
## [1] "num_infected_seeds: 3"
## [1] "vaccine_coverage: 0.1"
## [1] "apply_spatial_vaccine_refusal: FALSE"
## [1] "rng_seed: 36"
## [1] "area_size: 20"
## [1] "max_velocity: 1"
## [1] "target_num_contacts_day: 10"
## [1] "max_contact_distance: 2"
## [1] "num_days_infected: 7"
## [1] "transmission_prob: 0.1"
## [1] "plot_time_delay: 0"
## [1] "-------------"
## [1] "MODEL RESULTS"
## [1] "total incidence: 90%"
## [1] "Peak prevalence: 35%"
## [1] "Peak day:        18"
## [1] "Total run time:  3s"

What can you learn from these graphs? What about the model parameters that are printed to the console?

Dynamics over time?

This IBM is able to show the location and health states of each individual over time. Therefore, you have to increase the parameter plot_time_delay to set a delay between two time steps (= default this is 0 = no time between 2 time steps = no plots)

# you can run the IBM with default parameters (see console)
run_ibm_random_walk(plot_time_delay = 0.2)

Vaccination?

This IBM is able to account for vaccination. Therefore, you have to specify the parameter vaccine_coverage. By default, vaccinated individuals are randomly distributed over the area. To make this clear, we suggest to exclude the random movement, and use a static population (with velocity = 0).

# set vaccination coverage to 60% with a population that does not move
run_ibm_random_walk(max_velocity = 0,
                    vaccine_coverage = 0.6)

## [1] "MODEL PARAMETERS"
## [1] "pop_size: 1000"
## [1] "num_days: 50"
## [1] "num_infected_seeds: 3"
## [1] "vaccine_coverage: 0.6"
## [1] "apply_spatial_vaccine_refusal: FALSE"
## [1] "rng_seed: 40"
## [1] "area_size: 20"
## [1] "max_velocity: 0"
## [1] "target_num_contacts_day: 10"
## [1] "max_contact_distance: 2"
## [1] "num_days_infected: 7"
## [1] "transmission_prob: 0.1"
## [1] "plot_time_delay: 0"
## [1] "-------------"
## [1] "MODEL RESULTS"
## [1] "total incidence: 9%"
## [1] "Peak prevalence: 2%"
## [1] "Peak day:        40"
## [1] "Total run time:  2s"

Clustered vaccine refusal?

What happens if vaccine refusal is geographically clustered and individuals do not move? Run the following and have a look at the outcomes.

# is vaccination clustered?
run_ibm_random_walk(max_velocity = 0,
                    vaccine_coverage = 0.6,
                    apply_spatial_vaccine_refusal = TRUE)

## [1] "MODEL PARAMETERS"
## [1] "pop_size: 1000"
## [1] "num_days: 50"
## [1] "num_infected_seeds: 3"
## [1] "vaccine_coverage: 0.6"
## [1] "apply_spatial_vaccine_refusal: TRUE"
## [1] "rng_seed: 42"
## [1] "area_size: 20"
## [1] "max_velocity: 0"
## [1] "target_num_contacts_day: 10"
## [1] "max_contact_distance: 2"
## [1] "num_days_infected: 7"
## [1] "transmission_prob: 0.1"
## [1] "plot_time_delay: 0"
## [1] "-------------"
## [1] "MODEL RESULTS"
## [1] "total incidence: 17%"
## [1] "Peak prevalence: 5%"
## [1] "Peak day:        30"
## [1] "Total run time:  2s"

What happens if individuals still move? Or the vaccine coverage is only 30%? If you run this multiple times, do you get the same outcome?

Scenarios…

Now, it is time to adapt the model parameters and see what happens to the total incidence and epidemic peak. The names of the parameters are listed in the box above. What happens if you…

  • change the population size to 100 or 2000?
  • decrease the area size?
  • change the velocity to 20?
  • start with 1 or 500 infected individuals?
  • increase the contact range?
  • increase the transmission probability to 0.4?
  • change the average number of contacts per day to 2 or 20?
  • change the time horizon to 100 days?
  • … etc.

(TIP: the run_ibm_random_walk function has an option to add_baseline = TRUE to add model results with the default parameters. However, this increases the run time since the model is executed twice.)