sir - package for running stochastic SIR models
About
The models in this package are generated by odin. I hope this isn't cheating, considering they're lifted straight out of the examples there!
Installation
Install from GitHub with devtools::install_github("hillalex/sir")
or clone this repo and run R CMD INSTALL .
Quick start
To run 100 simulations of a discrete time step stochastic SIR model with infection rate 0.2
, recovery rate 0.1
, 1000
susceptible individuals and 1
infectious individual at time 0:
sir::run_model(1:100, nsim = 100, beta = 0.2, sigma = 0.1, S_ini = 1000, I_ini = 1)
To automatically plot the results include plot = TRUE
. See the man directory for complete function documentation.
Testing
Broadly speaking I can think of 3 approaches to testing:
- unit tests - Test any deterministic logic; mock stochastic elements or use set seeds where needed. Include regression tests against known working versions of a model.
- statistical tests - Use what's known about the expected distribution of results to write probabilistic tests. In this example we know a lot about the dynamics of the model already but in general this is presumably not the case, e.g. there won't usually be a nice analytical solution to compare to.
- manual tests - Build tooling that facilitates manual review of model outputs (e.g. can CI auto-generate reference plots for visual inspection)
The test directory here includes some simple smoke tests and unit tests (trivial since there is very little internal logic here), and then some more speculative attempts at validating the model dynamics in test-stochastic.R. A domain scientist who understood the model dynamics better than me could likely generate some better ideas for the latter.
To run tests locally from this directory:
testthat::test_local(".")
Further development ideas
- Fleshing out the testing, including CI, ideas for tooling around manual tests
- Extending the interface, e.g. with a GUI
- Expanding the documentation