The aim of this tutorial is to run scenario analyses with an individual-based model in R that accounts for location specific mixing.
In this session, you will
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.
The individual-based model will make use of a virtual population in which each individual is part of a household, school/work (based on age), and the general community. Each day (= time step), individuals can interact at home, school/work and in the community. We specify for each location a contact probability or average number of contacts per day.
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
If the curl
package is not installed yet, you can do so
by
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 yourselves.
## [1] "MODEL PARAMETERS"
## [1] "pop_size: 2000"
## [1] "num_days: 50"
## [1] "num_infected_seeds: 3"
## [1] "vaccine_coverage: 0"
## [1] "rng_seed: 28"
## [1] "num_days_infected: 7"
## [1] "transmission_prob: 0.1"
## [1] "num_contacts_community_day: 4"
## [1] "contact_prob_household: 1"
## [1] "contact_prob_school: 0.5"
## [1] "contact_prob_workplace: 0.3"
## [1] "num_schools: 2"
## [1] "target_school_ages: 3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18"
## [1] "num_workplaces: 150"
## [1] "bool_show_demographics: TRUE"
## [1] "-------------"
## [1] "MODEL RESULTS"
## [1] "total incidence: 100%"
## [1] "Peak prevalence: 60%"
## [1] "Peak day: 12"
## [1] "Total run time: 3s"
# increase num_contacts_community_day to 6
run_ibm_location(num_contacts_community_day = 6)
# set num_schools to 5
run_ibm_location(num_school = 6)
# set transmission_prob to 0.15 (and switch off the demographic plots)
run_ibm_location(transmission_prob = 0.15,
bool_show_demographics = FALSE)
(TIP: the run_ibm_location
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.)