Finding Example Models
The macpan2
comes with a set of example model
definitions, which can be listed with the show_models
function.
Directory | Title | Description |
---|---|---|
awareness | Awareness Models | Behaviour modifications in response to death |
hiv | HIV | A simple HIV model |
lotka_volterra_competition | Lotka-Volterra | Simple two-species competition model |
lotka_volterra_predator_prey | Lotka-Volterra | Simple predator-prey model |
macpan_base | Macpan Base | Re-implementation of the McMaster group’s COVID-19 model |
nfds | NFDS and Vaccine Design | An ecological model using population genomics to design optimal vaccines as implemented in Colijn et al. (2020) |
seir | Basic SEIR | Simple epidemic model with an exposed class |
shiver | SHIVER = SEIR + H + V | A modified SEIR model with Hospitalization and Vaccination |
si | Basic SI | A very simple epidemic model |
sir | Basic SIR | A very simple epidemic model |
sir_demog | SIR with Demography | An SIR model with birth and death |
sir_mosquito | Mosquito-Vector SIR | SIR model for mosquito vectors |
sir_waning | SIR with Waning Immunity | A basic SIR model with a flow from R back to S |
ww | Wastewater Model | Macpan base with an additional wastewater component |
There are three things that you can do with the items on this list: read them, use them, and modify them. To read them, just click on the links above to take you to each model. To use them and modify them, please continue reading.
Using Examples
To use the sir
example it can be read into R using the
following code.
sir_dir = system.file("starter_models", "sir", package = "macpan2")
sir = mp_tmb_library(sir_dir)
print(sir)
#> ---------------------
#> Default values:
#> ---------------------
#> matrix row col value
#> beta 0.2
#> gamma 0.1
#> N 100.0
#> I 1.0
#> R 0.0
#>
#> ---------------------
#> Before the simulation loop (t = 0):
#> ---------------------
#> 1: S ~ N - I - R
#>
#> ---------------------
#> At every iteration of the simulation loop (t = 1 to T):
#> ---------------------
#> 1: mp_per_capita_flow(from = "S", to = "I", rate = infection ~ I *
#> beta/N)
#> 2: mp_per_capita_flow(from = "I", to = "R", rate = recovery ~ gamma)
To see how to actually generate simulations from this model see this
article. To use another model, again, replace sir
with
another entry in the dir
column above.
Modifying Examples
To take sir
as a jumping-off point for producing your
own model one may use the following code.
my_sir_dir = file.path(tempdir(), "my_sir")
mp_model_starter("sir", my_sir_dir)
#> ---------------------
#> Default values:
#> ---------------------
#> matrix row col value
#> beta 0.2
#> gamma 0.1
#> N 100.0
#> I 1.0
#> R 0.0
#>
#> ---------------------
#> Before the simulation loop (t = 0):
#> ---------------------
#> 1: S ~ N - I - R
#>
#> ---------------------
#> At every iteration of the simulation loop (t = 1 to T):
#> ---------------------
#> 1: mp_per_capita_flow(from = "S", to = "I", rate = infection ~ I *
#> beta/N)
#> 2: mp_per_capita_flow(from = "I", to = "R", rate = recovery ~ gamma)
After running this code you can go to the files in
my_sir_dir
and modify what you see there. Note that you
typically want to chose a specific directory for your model instead of
using tempdir
. You still need to read your own model in the
usual way.
my_sir = mp_tmb_library(my_sir_dir)
print(my_sir)
#> ---------------------
#> Default values:
#> ---------------------
#> matrix row col value
#> beta 0.2
#> gamma 0.1
#> N 100.0
#> I 1.0
#> R 0.0
#>
#> ---------------------
#> Before the simulation loop (t = 0):
#> ---------------------
#> 1: S ~ N - I - R
#>
#> ---------------------
#> At every iteration of the simulation loop (t = 1 to T):
#> ---------------------
#> 1: mp_per_capita_flow(from = "S", to = "I", rate = infection ~ I *
#> beta/N)
#> 2: mp_per_capita_flow(from = "I", to = "R", rate = recovery ~ gamma)
These look identical to what came before, but that’s just because it hasn’t been modified … yet …