-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathREADME.Rmd
131 lines (95 loc) · 4.64 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
---
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
<!-- badges: start -->
[![Lifecycle: retired](https://img.shields.io/badge/lifecycle-retired-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#retired)
![GitHub R package version](https://img.shields.io/github/r-package/v/epiverse-trace/bpmodels)
[![R-CMD-check](https://github.com/epiverse-trace/bpmodels/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/epiverse-trace/bpmodels/actions/workflows/R-CMD-check.yaml)
[![codecov](https://codecov.io/github/epiverse-trace/bpmodels/branch/main/graph/badge.svg)](https://app.codecov.io/github/epiverse-trace/bpmodels)
![GitHub contributors](https://img.shields.io/github/contributors/epiverse-trace/bpmodels)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/license/MIT/)
<!-- badges: end -->
## Note
> `{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://epiverse-trace.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://epiverse-trace.github.io/bpmodels/), under "Articles".
## Reporting bugs
To report a bug please open an [issue](https://github.com/epiverse-trace/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/epiverse-trace/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/epiverse-trace/.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")
```