-
Notifications
You must be signed in to change notification settings - Fork 3
/
README.Rmd
206 lines (136 loc) · 6.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
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r setup, echo = FALSE, message=FALSE, results='hide'}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.align = "center",
fig.path = "man/figures/README-",
echo = TRUE,
fig.width = 8,
fig.height = 6
)
```
<!-- badges: start -->
[![R build status](https://github.com/reconhub/earlyR/workflows/R-CMD-check/badge.svg)](https://github.com/reconhub/earlyR/actions)
[![Codecov test coverage](https://codecov.io/gh/reconhub/earlyR/branch/master/graph/badge.svg)](https://codecov.io/gh/reconhub/earlyR?branch=master)
[![CRAN status](https://www.r-pkg.org/badges/version/earlyR)](https://CRAN.R-project.org/package=earlyR)
<!-- badges: end -->
# Welcome to the *earlyR* package!
This package implements simple estimation of infectiousness, as measured by the
reproduction number (R), in the early stages of an outbreak. This estimation requires:
- **prior knowledge**: the **serial interval** distribution, defined as the *mean* and
*standard deviation* of the (Gamma) distribution. In general, these parameters
are best taken from the literature.
- **data**: the daily **incidence** of the disease, including **only confirmed
and probable** cases.
## Installing the package
To install the current stable, CRAN version of the package, type:
```{r install, eval = FALSE}
install.packages("earlyR")
```
To benefit from the latest features and bug fixes, install the development,
*github* version of the package using:
```{r install2, eval = FALSE}
devtools::install_github("reconhub/earlyR")
```
Note that this requires the package *devtools* installed.
# What does it do?
The main features of the package include:
- **`get_R`**: a function to estimate *R* as well as the force of infection over
time, from incidence data; output is an object of class `earlyR`
- **`sample_R`**: a function to obtain a sample of likely *R* values
- **`plot`**: a function to visualise `earlyR` objects (*R* or force of infection).
- **`points`**: a function using `earlyR` objects to add the force of infection
to an existing plot.
# Resources
## Worked example
This example is a simplified version of the
[*introductory vignette*](http://www.repidemicsconsortium.org/earlyR/articles/earlyR.html)
(see section below), where `earlyR` is used in conjunction with other packages
to assess infectiousness and growth potential of an early Ebola Virus Disease
(EVD) outbreak. Here, we simply illustrate how `earlyR` can be used for
assessing infectiousness based on a few confirmed/probable cases.
In this example we assume a small outbreak of Ebola Virus Disease (EVD), for
which the serial interval has been previously characterised. We study a fake
outbreak, for which we will quantify infectiousness (R), and then project future
incidence using the package
[*projections*](https://github.com/reconhub/projections).
The fake data we consider consist of confirmed cases with the
following symptom onset dates:
```{r data}
onset <- as.Date(c("2017-02-04", "2017-02-12", "2017-02-15",
"2017-02-23", "2017-03-01", "2017-03-01",
"2017-03-02", "2017-03-03", "2017-03-03"))
```
We assume the current date is 21st March.
We compute the daily incidence using the package
[*incidence*](https://github.com/reconhub/incidence):
```{r incidence}
library(incidence)
today <- as.Date("2017-03-21")
i <- incidence(onset, last_date = today)
i
plot(i, border = "white")
```
**Note:** It is **very important to make sure that the last days without cases are
included here**. Omitting this information would lead to an over-estimation of the
reproduction number (*R*).
For estimating *R*, we need estimates of the mean and standard deviation of the
serial interval, i.e. the delay between primary and secondary symptom onset
dates. This has been quantified durin the West African EVD outbreak (WHO Ebola
Response Team (2014) NEJM 371:1481–1495):
```{r si}
mu <- 15.3 # mean in days days
sigma <- 9.3 # standard deviation in days
```
The function `get_R` is then used to estimate the most likely values of *R*:
```{r estimate}
library(earlyR)
library(ggplot2)
res <- get_R(i, si_mean = mu, si_sd = sigma)
res
plot(res)
```
The first figure shows the distribution of likely values of *R*, and the
Maximum-Likelihood (ML) estimation. To derive other statistics for this
distribution, we can use `sample_R` to get a large sample of likely *R* values,
and then compute statistics on this sample:
```{r samples}
R_val <- sample_R(res, 1000)
summary(R_val) # basic stats
quantile(R_val) # quartiles
quantile(R_val, c(0.025, 0.975)) # 95% credibility interval
hist(R_val, border = "grey", col = "navy",
xlab = "Values of R",
main = "Sample of likely R values")
```
Finally, we can also represent infectiousness over time using:
```{r lamdbas}
plot(res, "lambdas", scale = length(onset) + 1) +
geom_vline(xintercept = onset, col = "grey", lwd = 1.5) +
geom_vline(xintercept = today, col = "blue", lty = 2, lwd = 1.5)
```
This figure shows the global force of infection over time, with vertical grey
bars indicating the dates of symptom of onset. The dashed blue line indicates
current day. Note that the vertical scale for the bars is arbitrary, and only
represents the relative force of infection.
## Vignettes
`Currently available vignettes can be accessed from *R* using:
- `vignette("earlyR")`: an
[introduction to `earlyR`](http://www.repidemicsconsortium.org/earlyR/articles/earlyR.html)
using a simulated Ebola Virus Disease (EVD) outbreak; includes projections of
future incidence using *projections*.
## Websites
A dedicated website is still in development.
## Getting help online
Bug reports and feature requests should be posted on *github* using the
[*issue*](http://github.com/reconhub/earlyR/issues) system. All other questions
should be posted on the **RECON forum**: <br>
[http://www.repidemicsconsortium.org/forum/](http://www.repidemicsconsortium.org/forum/)
Contributions are welcome via **pull requests**.
Please note that this project is released with a [Contributor Code of
Conduct](CONDUCT.md). By participating in this project you agree to abide by its
terms.