The epidemia package allows researchers to flexibly specify and fit Bayesian epidemiological models in the style of Flaxman et al. (2020). The package itself is described in the software paper Scott et al. (2021), Epidemia: An R Package for Semi-Mechanistic Bayesian Modelling of Infectious Diseases using Point Processes, and the framework is applied in Mishra et al. (2022), A COVID-19 Model for Local Authorities of the United Kingdom (Journal of the Royal Statistical Society Series A). The package leverages R’s formula interface to parameterize the time-varying reproduction rate as a function of covariates. Multiple populations can be modeled simultaneously with hierarchical models. The design of the package has been inspired by, and has borrowed from, rstanarm (Goodrich et al. 2020). epidemia fits models with Stan via the cmdstanr backend, and represents posterior draws with the posterior package. The Stan models are compiled on first use and cached, so no compilation happens at install time.
epidemia fits models with CmdStanR. Install CmdStanR and CmdStan first, then install epidemia from GitHub:
# 1. CmdStanR + CmdStan (needs a C++ toolchain)
install.packages("cmdstanr",
repos = c("https://stan-dev.r-universe.dev", getOption("repos")))
cmdstanr::check_cmdstan_toolchain(fix = TRUE)
cmdstanr::install_cmdstan()
# 2. epidemia
# install.packages("remotes")
remotes::install_github("mlgh-sg/epidemia2")cmdstanr is not on CRAN, which is why it needs the stan-dev repository
above; install_cmdstan() then downloads and compiles CmdStan itself, so a
working C++ toolchain is required. The Stan models are compiled the first time
they are used and then cached. You can optionally precompile them with
epidemia::compile_epidemia().
There is also a Python port, under python/ — the same model in
PyMC, fit with nutpie.
It needs no C++ toolchain and no CmdStan:
pip install "git+https://github.com/mlgh-sg/epidemia2.git#subdirectory=python"#subdirectory=python is required — the Python package lives in a subdirectory
of this repository, and without it pip looks for a pyproject.toml at the repo
root (where the R package lives) and fails. See
python/README.md for pinning to a tag, the development
setup, and the API.
This is an early beta release of the package. As a beta release, there will be regular updates with additional features and more extensive testing. Any feedback is greatly appreciated
- in particular if you find bugs, find the documentation unclear, or have feature requests, please report them here.
To get started, please see the package website, where you can find installation instructions, function documentation, and vignettes.
This package — epidemia2, and the Python port under
python/ — is maintained by Swapnil Mishra
(ORCID), with
Claude Code (Anthropic).
It continues the original epidemia
(ImperialCollegeLondon/epidemia),
whose authors are James A. Scott, Axel Gandy, Swapnil Mishra, H. Juliette T.
Unwin, Seth Flaxman and Samir Bhatt. The model, its priors, its formula
interface and the statistical framework are their work and remain credited as
such in DESCRIPTION; this repository carries it forward rather than replacing
it.
Please cite the papers, not the repository:
- Software paper — Scott, J. A., Gandy, A., Mishra, S., Bhatt, S., Flaxman, S., Unwin, H. J. T. & Ish-Horowicz, J. (2021). Epidemia: An R Package for Semi-Mechanistic Bayesian Modelling of Infectious Diseases using Point Processes. arXiv:2110.12461
- Framework — Bhatt, S. et al. (2020). Semi-mechanistic Bayesian modelling of COVID-19 with renewal processes. arXiv:2012.00394
- Application — Mishra, S. et al. (2022). A COVID-19 Model for Local Authorities of the United Kingdom. JRSS-A. doi:10.1111/rssa.12988
citation("epidemia") in R, or inst/CITATION, gives the
authoritative list. Licensed GPL-3.
