knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = file.path("man", "figures", "README-"), out.width = "100%" )
{bpmodels}
is now retired and will no longer be maintained. We recommend using{epichains}
instead. If you need help converting your code to use{epichains}
, please open a discussion on epichains.
knitr::opts_chunk$set(echo = TRUE)
bpmodels is an R package to simulate and analyse the size and length of branching processes with a given offspring distribution. These models are often used in infectious disease epidemiology, where the chains represent chains of transmission, and the offspring distribution represents the distribution of secondary infections caused by an infected individual.
The latest development version of the bpmodels package can be installed via
# check whether {pak} is installed if (!require("pak")) install.packages("pak") pak::pkg_install("epiforecasts/bpmodels")
To load the package, use
library("bpmodels")
bpmodels provides three main functions:
chain_ll()
: calculates the likelihoods of observing a vector of chains
of given sizes or lengths.
Here is a quick example of estimating the loglikelihood of an observed chain:
# example of observed chain sizes chain_sizes <- c(1, 2, 3, 4) # estimate loglikelihood of the observed chain sizes chain_ll_eg <- chain_ll(x = chain_sizes, offspring = "pois", stat = "size", lambda = 0.5) chain_ll_eg
chain_sim()
: simulates transmission chains until all chains stop producing
offspring.
Below is a quick example where we simulate the chain sizes of $5$ chains with a poisson offspring with mean, $\text{lambda} = 0.5$:
set.seed(123) chain_sim_eg <- chain_sim(n = 5, offspring = "pois", stat = "size", lambda = 0.5, tree = TRUE) head(chain_sim_eg)
chain_sim_susc()
: simulates transmission chains from a specified population
size with pre-existing immunity until the susceptible pool runs out.
Below is a quick example where we simulate chains with a poisson offspring with mean, $\text{lambda} = 0.5$, and serial interval of $3$:
set.seed(1234) chain_sim_susc_eg <- chain_sim_susc(pop = 1000, offspring = "pois", mn_offspring = 0.5, serial = function(x) {3} ) head(chain_sim_susc_eg)
See the "Get started vignette" for a detailed illustration of each function.
Specific use cases of bpmodels can be found in the online documentation as package vignettes, under "Articles".
To report a bug please open an issue.
We welcome contributions to enhance the package's functionalities. If you wish to do so, please follow the package contributing guide.
Please note that the bpmodels project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.
citation("bpmodels")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.