https://github.com/epiforecasts/bpmodels
[RETIRED. Use the epichains package instead]. Methods for simulating and analysing the sizes and lengths of chains from branching process models
https://github.com/epiforecasts/bpmodels
branching-process epidemic-dynamics epidemic-modelling epidemic-simulations epidemiology epiverse outbreak-simulator r r-package transmission-chain transmission-chain-reconstruction
Last synced: 4 months ago
JSON representation
[RETIRED. Use the epichains package instead]. Methods for simulating and analysing the sizes and lengths of chains from branching process models
- Host: GitHub
- URL: https://github.com/epiforecasts/bpmodels
- Owner: epiforecasts
- License: other
- Created: 2019-01-09T06:42:06.000Z (almost 7 years ago)
- Default Branch: main
- Last Pushed: 2025-02-05T12:25:57.000Z (8 months ago)
- Last Synced: 2025-06-08T03:44:03.518Z (4 months ago)
- Topics: branching-process, epidemic-dynamics, epidemic-modelling, epidemic-simulations, epidemiology, epiverse, outbreak-simulator, r, r-package, transmission-chain, transmission-chain-reconstruction
- Language: R
- Homepage: https://epiforecasts.io/bpmodels/
- Size: 5.42 MB
- Stars: 7
- Watchers: 3
- Forks: 7
- Open Issues: 6
-
Metadata Files:
- Readme: README.Rmd
- Changelog: NEWS.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE
- Citation: CITATION.cff
Awesome Lists containing this project
README
---
output: github_document
bibliography: vignettes/references.json
link-citations: true
---```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = file.path("man", "figures", "README-"),
out.width = "100%"
)
```# _bpmodels_: Methods for simulating and analysing the size and length of transmission chains from branching process models
[](https://lifecycle.r-lib.org/articles/stages.html#retired)

[](https://github.com/epiforecasts/bpmodels/actions/workflows/R-CMD-check.yaml)
[](https://app.codecov.io/github/epiforecasts/bpmodels)

[](https://opensource.org/license/MIT/)## WARNING
> `{bpmodels}` is now *retired and will no longer be maintained*. We recommend using [`{epichains}`](https://github.com/epiverse-trace/epichains) instead. If you need help converting your code to use `{epichains}`, please [open a discussion on epichains](https://github.com/epiverse-trace/epichains/discussions).
```{r setup, include=FALSE}
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.# Installation
The latest development version of the _bpmodels_ package can be installed via
```{r eval=FALSE}
# check whether {pak} is installed
if (!require("pak")) install.packages("pak")
pak::pkg_install("epiforecasts/bpmodels")
```To load the package, use
```{r eval=TRUE}
library("bpmodels")
```# Core functionality
_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:
```{r}
# 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$:
```{r}
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$:
```{r}
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"](https://epiforecasts.github.io/bpmodels/articles/bpmodels.html) for a detailed illustration of
each function.## Package vignettes
Specific use cases of _bpmodels_ can be found in
the [online documentation as package vignettes](https://epiforecasts.github.io/bpmodels/), under "Articles".## Reporting bugs
To report a bug please open an [issue](https://github.com/epiforecasts/bpmodels/issues/new/choose).
## Contribute
We welcome contributions to enhance the package's functionalities. If you
wish to do so, please follow the [package contributing guide](https://github.com/epiforecasts/bpmodels/blob/main/.github/CONTRIBUTING.md).## Code of conduct
Please note that the _bpmodels_ project is released with a [Contributor Code of Conduct](https://github.com/epiforecasts/.github/blob/main/CODE_OF_CONDUCT.md).
By contributing to this project, you agree to abide by its terms.## Citing this package
```{r message=FALSE, warning=FALSE}
citation("bpmodels")
```