Skip to contents

status

Finding Example Models

The macpan2 comes with a set of example model definitions, which can be listed with the show_models function.

dir title index_entry
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 vanilla 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_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 …