library(learnr) knitr::opts_chunk$set(error = TRUE) set.seed(123)
In this practical we will run a stochastic version of the SIR model and compare it to the deterministic model from practical series 2.
Having created our stochastic version of the SIS model in the previous practical we are now ready to extend this framework to the SIR model.
Using the code from the previous demo d0304_run_SIS
and
timestep_stochastic_SIS()
(from Practical 3-4), create a new demo
d0305_run_SIR
and a new function, timestep_stochastic_SIR()
that will
simulate the stochastic SIR model.
To produce timestep_stochastic_SIR()
requires a small change to the update step
to move the newly recovered individuals into the recovered class rather than
back into the susceptible class. Remember also to include the recovereds in the
population size calculation.
To overlay the corresponding plot from the deterministic model you will also
need to use run_simulation()
on the timestep_deterministic_SIR()
function
from Practical 2-4, and then plot using new.graph = FALSE
.
This should be relatively straightforward. To produce d0305_run_SIR
you need
to add a "recovereds" population to the data frame, remembering to specify
initial values for this new population.
Run the code with a transmission rate of 0.2, a recovery rate of 0.1, 2 initial infecteds and 0 initial recovereds from a population size of 100. Demonstrate the variability in the results of the stochastic model and overlay the deterministic results from Practical 2-5.
Run the code for different initial conditions (number of infecteds and recovereds), and population size. Why do the plots of the stochastic simulation end before those of the deterministic simulation? What happens as you increase the population size? Illustrate these effects in your demo.
Now try increasing the transmission rate to increase the value of $R_0$. Given a default value for the recovery rate of 0.1 what would the transmission rate need to be to simulate an outbreak with an $R_0$ of 15?
As with previous exercises, you need to check that everything works correctly -- that the package installs, and the demos and help files work and you can generate reports from the demos -- and then we want you to get a couple of other people in your subgroup to check your code and make sure it works for them, and we want you to check other people's code too. We describe how to do this for packages in GitHub in Practical 3-1 (also under Check it works) if you're uncertain.
Remember, interacting like this through GitHub to help each other will count as most of your engagement marks for the course.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.