-
Notifications
You must be signed in to change notification settings - Fork 14
/
README.Rmd
153 lines (115 loc) · 5.17 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
---
output:
- rmarkdown::github_document
#- rmarkdown::html_document
always_allow_html: true
#bookdown::html_document2:
#number_sections: false
#toc: false
---
# sars2pack
<!-- badges: start -->
[![Launch Rstudio Binder](http://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/seandavi/sars2pack/master?urlpath=rstudio)
[![R-CMD-check](https://github.com/seandavi/sars2pack/workflows/R-CMD-check/badge.svg)](https://github.com/seandavi/sars2pack/actions)
<!-- badges: end -->
```{r init, include=FALSE}
knitr::opts_chunk$set(warning=FALSE,message=FALSE, cache=TRUE,
fig.width=9, fig.height=6, out.width = '100%'
)
knitr::opts_knit$set(upload.fun = knitr::imgur_upload)
```
## Questions immediately addressed by sars2pack datasets
- What are the current and historical total, new cases, and deaths of COVID-19 at the city, county, state, national, and international levels?
- What are the non-pharmacological interventions in place at the local and national levels?
- In the United States, what is the geographical distribution of healthcare capacity (ICU beds, total beds, doctors, etc.)?
- What are the published values of key epidemic parameters, as curated from the literature?
- When, where, and how are communities changing their movement patterns?
## Installation
```{r eval=FALSE}
# If you do not have BiocManager installed:
install.packages('BiocManager')
# Then, if sars2pack is not already installed:
BiocManager::install('seandavi/sars2pack')
```
After the one-time installation, load the packge to get started.
```{r}
library(sars2pack)
```
## Available datasets
```{r echo=FALSE}
library(knitr)
library(kableExtra)
library(tibble)
library(dplyr)
library(purrr)
library(sars2pack)
library(yaml)
b = available_datasets()
b %>% dplyr::mutate(url=sprintf('[LINK](%s)',url)) %>%
mutate_all(linebreak) %>%
arrange(data_type) %>%
kable(booktabs=TRUE, escape=FALSE) %>%
kable_styling("striped")
```
## Case tracking
Updated tracking of city, county, state, national, and international confirmed cases, deaths,
and testing is critical to driving policy, implementing interventions, and measuring their effectiveness. Case tracking datasets include date, a count of cases, deaths, testing, hospitalizations, and usually numerous other pieces of information related to location of reporting, etc.
Accessing case-tracking datasets is typically done with one function per dataset. The example here is data from the European Centers for Disease Control, or ECDC.
```{r worldwide}
ecdc = ecdc_data()
```
Get a quick overview of the dataset.
```{r}
head(ecdc)
```
The `ecdc` dataset is just a `data.frame` (actually, a `tibble`), so applying standard R or tidyverse functionality can get answers to basic questions with little code. The next code block generates a `top10` of countries with the most deaths recorded to date. Note that if you do this on your own computer, the data will be updated to today's data values.
```{r results='asis'}
library(dplyr)
top10 = ecdc %>% filter(subset=='deaths') %>%
group_by(location_name) %>%
filter(count==max(count)) %>%
arrange(desc(count)) %>%
head(10) %>% select(-starts_with('iso'),-continent,-subset) %>%
mutate(rate_per_100k = 1e5*count/population_2019)
```
Finally, present a nice table of those countries:
```{r}
knitr::kable(
top10,
caption = "Reported COVID-19-related deaths in ten most affected countries.",
format = 'pandoc')
```
Examine the spread of the pandemic throughout the world by examining cumulative deaths
reported for the top 10 countries above.
```{r plotcases}
ecdc_top10 = ecdc %>% filter(location_name %in% top10$location_name & subset=='deaths')
plot_epicurve(ecdc_top10,
filter_expression = count > 10,
color='location_name')
```
Comparing the features of disease spread is easiest if all curves are shifted to
"start" at the same absolute level of infection. In this case, shift the origin for
all countries to start at the first time point when more than 100 cumulative cases
had been observed. Note how some curves cross others which is evidence of less infection
control at the same relative time in the pandemic for that country (eg., Brazil).
```{r}
ecdc_top10 %>% align_to_baseline(count>100,group_vars=c('location_name')) %>%
plot_epicurve(date_column = 'index',color='location_name')
```
## Contributions
Pull requests are gladly accepted on [Github](https://github.com/seandavi/sars2pack).
### Adding new datasets
See the **Adding new datasets** vignette.
## Similar work
- <https://github.com/emanuele-guidotti/COVID19>
- [Top 25 R resources on Novel COVID-19
Coronavirus](https://towardsdatascience.com/top-5-r-resources-on-covid-19-coronavirus-1d4c8df6d85f)
- [COVID-19 epidemiology with
R](https://rviews.rstudio.com/2020/03/05/covid-19-epidemiology-with-r/)
- <https://github.com/RamiKrispin/coronavirus>
- [Youtube: Using R to analyze
COVID-19](https://www.youtube.com/watch?v=D_CNmYkGRUc)
- [DataCamp: Visualize the rise of COVID-19 cases globally with
ggplot2](https://www.datacamp.com/projects/870)
- [MackLavielle/covidix R
package](https://github.com/MarcLavielle/covidix/)