generated from epiverse-trace/packagetemplate
-
Notifications
You must be signed in to change notification settings - Fork 1
/
README.Rmd
241 lines (182 loc) · 14 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file. -->
<!-- The code to render this README is stored in .github/workflows/render-readme.yaml -->
<!-- Variables marked with double curly braces will be transformed beforehand: -->
<!-- `packagename` is extracted from the DESCRIPTION file -->
<!-- `gh_repo` is extracted via a special environment variable in GitHub Actions -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# _simulist_: Simulate line list data <img src="man/figures/logo.svg" align="right" width="120" />
<!-- badges: start -->
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/license/mit)
[![R-CMD-check](https://github.com/{{ gh_repo }}/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/{{ gh_repo }}/actions/workflows/R-CMD-check.yaml)
[![Codecov test coverage](https://codecov.io/gh/{{ gh_repo }}/branch/main/graph/badge.svg)](https://app.codecov.io/gh/{{ gh_repo }}?branch=main)
[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)
[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.10471459.svg)](https://doi.org/10.5281/zenodo.10471459)
<!-- badges: end -->
`{simulist}` is an R package to simulate individual-level infectious disease outbreak data, including line lists and contact tracing data. It can often be useful to have synthetic datasets like these available when demonstrating outbreak analytics techniques or testing new analysis methods.
`{simulist}` is developed at the [Centre for the Mathematical Modelling of Infectious Diseases](https://www.lshtm.ac.uk/research/centres/centre-mathematical-modelling-infectious-diseases) at the [London School of Hygiene and Tropical Medicine](https://www.lshtm.ac.uk/) as part of [Epiverse-TRACE](https://data.org/initiatives/epiverse/).
## Key features
`{simulist}` allows you to simulate realistic line list and contact tracing data, with:
:hourglass_flowing_sand: Parameterised epidemiological delay distributions <br>
:hospital: Population-wide or age-stratified hospitalisation and death risks <br>
:bar_chart: Uniform or age-structured populations <br>
:chart_with_upwards_trend: Constant or time-varying case fatality risk <br>
:clipboard: Customisable probability of case types and contact tracing follow-up <br>
## Installation
You can install the development version of `{simulist}` from
[GitHub](https://github.com/) with:
``` r
# check whether {pak} is installed
if(!require("pak")) install.packages("pak")
pak::pak("epiverse-trace/simulist")
```
## Quick start
```{r load-simulist}
library(simulist)
```
A line list can be simulated by calling `sim_linelist()`. The function provides sensible defaults to quickly generate a epidemiologically valid data set.
```{r, sim-linelist-defaults}
set.seed(1)
linelist <- sim_linelist()
head(linelist)
```
However, to simulate a more realistic line list using epidemiological parameters estimated for an infectious disease outbreak we can use previously estimated epidemiological parameters. These can be from the `{epiparameter}` R package if available, or if these are not in the `{epiparameter}` database yet (such as the contact distribution for COVID-19) we can define them ourselves. Here we define a contact distribution, period of infectiousness, onset-to-hospitalisation delay, and onset-to-death delay.
```{r load-epiparameter}
library(epiparameter)
```
```{r create-epidists}
# create COVID-19 contact distribution
contact_distribution <- epiparameter::epiparameter(
disease = "COVID-19",
epi_name = "contact distribution",
prob_distribution = create_prob_distribution(
prob_distribution = "pois",
prob_distribution_params = c(mean = 2)
)
)
# create COVID-19 infectious period
infectious_period <- epiparameter::epiparameter(
disease = "COVID-19",
epi_name = "infectious period",
prob_distribution = create_prob_distribution(
prob_distribution = "gamma",
prob_distribution_params = c(shape = 1, scale = 1)
)
)
# get onset to hospital admission from {epiparameter} database
onset_to_hosp <- epiparameter::epiparameter_db(
disease = "COVID-19",
epi_name = "onset to hospitalisation",
single_epiparameter = TRUE
)
# get onset to death from {epiparameter} database
onset_to_death <- epiparameter::epiparameter_db(
disease = "COVID-19",
epi_name = "onset to death",
single_epiparameter = TRUE
)
```
To simulate a line list for COVID-19 with an Poisson contact distribution with a mean number of contacts of 2 and a probability of infection per contact of 0.5, we use the `sim_linelist()` function. The mean number of contacts and probability of infection determine the outbreak reproduction number, if the resulting reproduction number is around one it means we will likely get a reasonably sized outbreak (10 - 1,000 cases, varying due to the stochastic simulation).
***Warning***: the reproduction number of the simulation results from the contact distribution (`contact_distribution`) and the probability of infection (`prob_infection`); the number of infections is a binomial sample of the number of contacts for each case with the probability of infection (i.e. being sampled) given by `prob_infection`. If the average number of secondary infections from each primary case is greater than 1 then this can lead to the outbreak becoming extremely large. There is currently no depletion of susceptible individuals in the simulation model, so the maximum outbreak size (second element of the vector supplied to the `outbreak_size` argument) can be used to return a line list early without producing an excessively large data set.
```{r sim-linelist}
set.seed(1)
linelist <- sim_linelist(
contact_distribution = contact_distribution,
infectious_period = infectious_period,
prob_infection = 0.5,
onset_to_hosp = onset_to_hosp,
onset_to_death = onset_to_death
)
head(linelist)
```
In this example, the line list is simulated using the default values (see `?sim_linelist`). The default hospitalisation risk is assumed to be 0.2 (i.e. there is a 20% probability an infected individual becomes hospitalised) and the start date of the outbreak is 1st January 2023. To modify either of these, we can specify them in the function.
```{r sim-linelist-diff-args}
linelist <- sim_linelist(
contact_distribution = contact_distribution,
infectious_period = infectious_period,
prob_infection = 0.5,
onset_to_hosp = onset_to_hosp,
onset_to_death = onset_to_death,
hosp_risk = 0.01,
outbreak_start_date = as.Date("2019-12-01")
)
head(linelist)
```
To simulate a table of contacts of cases (i.e. to reflect a contact tracing dataset) we can use the same parameters defined for the example above.
```{r, sim-contacts}
contacts <- sim_contacts(
contact_distribution = contact_distribution,
infectious_period = infectious_period,
prob_infection = 0.5
)
head(contacts)
```
If both the line list and contacts table are required, they can be jointly simulated using the `sim_outbreak()` function. This uses the same inputs as `sim_linelist()` and `sim_contacts()` to produce a line list and contacts table of the same outbreak (the arguments also have the same default settings as the other functions).
```{r, sim-outbreak}
outbreak <- sim_outbreak(
contact_distribution = contact_distribution,
infectious_period = infectious_period,
prob_infection = 0.5,
onset_to_hosp = onset_to_hosp,
onset_to_death = onset_to_death
)
head(outbreak$linelist)
head(outbreak$contacts)
```
## Help
To report a bug please open an [issue](https://github.com/epiverse-trace/simulist/issues/new/choose).
## Contribute
Contributions to `{simulist}` are welcomed. Please follow the [package contributing guide](https://github.com/epiverse-trace/.github/blob/main/CONTRIBUTING.md).
## Code of Conduct
Please note that the `{simulist}` 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("simulist")
```
## Complimentary R packages
:package: :left_right_arrow: :package: [{epiparameter}](https://epiverse-trace.github.io/epiparameter/) <br>
:package: :left_right_arrow: :package: [{epicontacts}](https://www.repidemicsconsortium.org/epicontacts/) <br>
:package: :left_right_arrow: :package: [{incidence2}](https://www.reconverse.org/incidence2/) <br>
## Related projects
This project has some overlap with other R packages. Here we list these packages and provide a table of features and attributes that are present for each package to help decide which package is appropriate for each use-case.
In some cases the packages are dedicated to simulating line list and other epidemiological data (e.g. {simulist}), in others the line list simulation is one part of a wider R package (e.g. {EpiNow}).
- [`{LLsim}`](https://github.com/jrcpulliam/LLsim) simulates line list data using a stochastic SIR model with a fixed population with observation and reporting delays. Line list data is generated in two steps, 1) the SIR model simulates the outbreak (`simpleSim()`), 2) the outbreak data is converted into a line list (`createLineList()`).
- [`{simulacr}`](https://github.com/reconhub/simulacr) uses a branching process model to simulate cases and contacts for an outbreak. It simulates transmission of infections using other epidemiological R packages (`{epicontacts}` and `{distcrete}`) to parameterise and plot simulated data.
- [`{epidict}`](https://github.com/R4EPI/epidict) is a package that can be used to simulate outbreak data, including line lists, in a DHIS2 format, and survey data that mimics the format by Kobo, using the function `gen_data()`. In addition, MSF outbreak data are available in this package as data dictionaries for Acute Jaundice Syndrome, Cholera, Measles and Meningitis, accessible through the function `msf_dict()`.
- [`{EpiNow}`](https://github.com/epiforecasts/EpiNow) - a now deprecated R package - includes the `simulate_cases()` and `generate_pseudo_linelist()` functions for generating line list data.
- [generative-nowcasting](https://github.com/adrian-lison/generative-nowcasting) is a set of R scripts and functions to perform epidemiological nowcasting. There are [functions to simulate line list data](https://github.com/adrian-lison/generative-nowcasting/blob/bf48e027e82ce9d42de468d0b708d010253b7475/code/utils/utils_simulate.R) within the repository, but the repository is not (and does not contain) an R package. Functions can be sourced. Cases are simulated with a renewal process and the simulation can incorporate epidemiological delays and ascertainment.
<details>
<summary> Table of line list simulator features </summary>
| | {simulist} | {LLsim} | {simulacr} | {epidict} | {EpiNow} | generative-nowcasting |
| -------------- | -------------- | -------------- | -------------- | -------------- | -------------- | -------------- |
| Simulates line list | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| Simulates contacts | :white_check_mark: | :white_check_mark: | :white_check_mark: | :x: | :x: | :x: |
| Parameterised with epi distributions[^dist] | :white_check_mark: | :white_check_mark: | :white_check_mark: | :x: | :white_check_mark: | :white_check_mark: |
| Interoperable with {epicontacts} | :white_check_mark: | :white_check_mark: | :white_check_mark: | :x: | :x: | :x: |
| Explicit population size[^pop] | :x: | :white_check_mark: | :white_check_mark: | :x: | :x: | :x: |
| R package | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :x: |
| Actively maintained[^active] | :white_check_mark: | :x: | :x: | :x: | :x: | :white_check_mark: |
| On CRAN | :x: | :x: | :x: | :x: | :x: | NA |
| Unit testing[^tests] | :white_check_mark: | :white_check_mark: | :x: | :white_check_mark: | :x: | NA |
[^dist]: In this context _Parameterised with epi distributions_ means that the simulation uses epidemiological distributions (e.g. serial interval, infectious period) to parameterise the model and the parameters of these epi distributions can be modified by the user.
[^pop]: _Explicit population size_ refers to the simulation using a finite population size which is controlled by the user for the depletion of susceptible individuals in the model.
[^active]: We define _Actively maintained_ as the repository having a commit to the main branch within the last 12 months.
[^tests]: _Unit testing_ is ticked if the package contains any form of testing, this can use any testing framework, for example [{testthat}](https://CRAN.R-project.org/package=testthat) or [{tinytest}](https://CRAN.R-project.org/package=tinytest).
</details>
If there is another package with this functionality missing from the list that should be added, or if a package included in this list has been updated and the table should reflect this please contribute by making an [issue](https://github.com/epiverse-trace/simulist/issues) or a [pull request](https://github.com/epiverse-trace/simulist/pulls).
Some packages are related to {simulist} but do not simulate line list data. These include:
- [`{outbreaks}`](https://CRAN.R-project.org/package=outbreaks) an R package containing a library of outbreak data sets, including line list data, for a variety of past and simulated outbreaks, e.g. Ebola and MERS.
- [`{ringbp}`](https://github.com/epiforecasts/ringbp) an R package to simulate cases using an individual-level transmission model with contact tracing.
- [`{epichains}`](https://github.com/epiverse-trace/epichains) an R package with functionality to simulate transmission chains using a branching process model.
The {outbreaks} package is useful if data from a past outbreak data or generic line list data is required. The {ringbp} and {epichains} packages can be used to generate case data over time which can then be converted into a line list with some manual post-processing.