Learning Objectives

  1. Know how to translate a simple model flow diagram into equations.
  2. Know how to use a simple model scaffold to develop a more complex model.
  3. Understand how to implement your own model structure.

Outline for Session

  1. Set up (5 minutes)
  2. Practise simulating a fully implemented SEIR model (10 minutes).
  3. Add high and low risk latency to the SEIR model (10 minutes).
  4. Translate a more realistic SHLIR model flow diagram to equations (10 minutes).
  5. Implement your own model into R (20 minutes).
  6. Session wrap up (5 minutes)

Set up

If you have not installed the course package do this now with the following R code (speak to an instructor if you are having issues with this step).

Now load the course package,

library(biddmodellingcourse)

For more help getting started see the course README (https://bristolmathmodellers.github.io/biddmodellingcourse/) or ask an instructor.

Exercises

1. A Simple SEIR Model of Tuberculosis (TB)

As a first exercise we are going to run the simple SEIR model, as seen in practical 2, in R. See practical 2. for the flow diagram.

Populations and Initialisation

We first set up the initial populations for the Susceptible (\(S_0\)), Latent (\(E_0\)), Infected (\(I\)), and Recovered (\(R\)) compartments. We have initialised the model as an early stage epidemic with a single case of TB.

Parameters

We then specify the model parameters (with the units being years-1), varying these parameters will impact the model dynamics.

Equations

Finally we specify the model equations for each population compartment. This model incorporates simple demographic processes with a constant natural death rate from all compartments which is equal to the birth rate into the susceptible compartment.

Simulate and Summarise

To simulate the model we specify the starting year (begin_time) and final year (end_time) and define a sequence over all intervening years. The model is then solved using deSolve::lsoda which is used within a simple wrapper function (see ?solve_ode for details). The resulting table summarises the simulation results for the first 5 years.

We then summarise the epidemic peak (epi_peak) and epidemic duration (epi_dur), along with population sizes at the end of the time period simulated.

biddmodellingcourse::summarise_model(SEIR_sim) %>% 
  pretty_table(caption = "SEIR model summary statistics; The final size of each population at the end of the simulation, along with the time the epidemic peak was reached, the number of infected at the epidemic peak and the duration of the epidemic")

Finally we plot the population in each model compartment over time.

Explore

As we saw in practical 2, model dynamics are parameter dependent. Look back at the questions from practical 2 and check that you can implement the changes in the code above to answer them.

2. Add High and Low Risk Compartments

Now we are going to implement the SHLIR model from practical 2 and try to reproduce some of the behaviour observed using the interactive interface. See practical 2 for details on this model.

Populations and Initialisation

As in the previous model the first step is to define the model populations. There are now two new compartments, high risk latents (H), and low risk latents (L). These replace the original latent population (E) used in the SEIR model.

Simulate and Summarise

Simulation is the same as for the previous model. Does the simulation of your improved model make sense? Evaluate the summary tables and plot of model populations over time.

biddmodellingcourse::summarise_model(SHLIR_sim) %>% 
  pretty_table(caption = "SHLIR model summary statistics; The final size of each population at the end of the simulation, along with the time the epidemic peak was reached, the number of infected at the epidemic peak and the duration of the epidemic")

Explore

  1. Test your changes by setting nu = 0 and all other parameters to be the same as for the SEIR model. If everything is working correctly both models should give the same output.

  2. Can you alter the parameters defined above to answer the questions for the SHLIR model from practical 2?

3. Translate a more realistic SHLIR model flow diagram to equations

As a more advanced exercise (feel free to skip this if wanting to design your own model now) we now translate the more complex SHLIR model into code. Look back at practical 2 for a refresher on the structure of this model.

Populations and Initialisation

The new populations have been added for you. The population has now been split between low and high risk populations, with the only infectious case being in the high risk population.

Equations

Update the model equations using the model flow diagram above. The comments in the code given hints as to where changes need to be made. The equations for the low risk population have been partially provided for you.

Simulate and Summarise

Simulate the new model as previously.

biddmodellingcourse::summarise_model(real_SHLIR_sim) %>% 
  pretty_table(caption = "Realistic SHLIR model summary statistics; The final size of each population at the end of the simulation, along with the time the epidemic peak was reached, the number of infected at the epidemic peak and the duration of the epidemic")

Explore

  1. Test your changes by setting all the parameters to be the same as in the SHLIR model.

  2. Can you alter the parameters defined above to answer the questions for this model from practical 2?

4. Implement Your Own Model

Using the same structure as used in models above implement your own model into R. Talk to the instructors for tips, tricks, and potential ideas. See the idmodelr package for other example model structures (https://www.samabbott.co.uk/idmodelr/). It may help to first draw out the flow diagram for your model (potentially writing out the equations may also help).