Skip to content

Commit

Permalink
Rebuild documentation for 0.5.2
Browse files Browse the repository at this point in the history
  • Loading branch information
capnrefsmmat committed Aug 22, 2023
1 parent bb47516 commit 8fda2f6
Show file tree
Hide file tree
Showing 65 changed files with 1,637 additions and 710 deletions.
5 changes: 4 additions & 1 deletion R-packages/covidcast/NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
- `covidcast_meta()` now caches the server's response for a length of time
specified by the COVIDcast API server, based on how frequently the metadata is
recomputed. Because `covidcast_meta()` is called by `covidcast_signal()`, this
saves one API call per call to `covidcast_signal()`.
saves one API call per call to `covidcast_signal()`. (@krivard, #645)

- `covidcast_meta()` now more clearly reports errors when the API usage limit
has been reached.

# covidcast 0.5.1

Expand Down
2 changes: 1 addition & 1 deletion R-packages/covidcast/vignettes/correlation-utils.Rmd.orig
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ vignette: >
```{r, setup, include=FALSE}
knitr::opts_chunk$set(
comment = "", fig.width = 6, fig.height = 6, fig.path = "figures/corr-",
fig.cap = ""
fig.cap = "", dev = "ragg_png"
)
```

Expand Down
194 changes: 180 additions & 14 deletions R-packages/covidcast/vignettes/covidcast.Rmd

Large diffs are not rendered by default.

74 changes: 69 additions & 5 deletions R-packages/covidcast/vignettes/external-data.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ vignette: >
%\VignetteEncoding{UTF-8}
---



While the COVIDcast Epidata API provides numerous useful COVID data streams, you
may sometimes find yourself with relevant data from a different source. This
package provides the tools you need to load such data and use it alongside
Expand All @@ -25,7 +27,8 @@ results.
We've saved a sample of the data in this package to use as an example. Let's
load it and examine a few columns using `knitr::kable()` to print them nicely:

```{r, message=FALSE}

```r
library(dplyr)

data <- read.csv(system.file("extdata", "covid-tracking-project-oct-2020.csv",
Expand All @@ -38,6 +41,17 @@ data %>%
knitr::kable()
```



|date |state | death| deathIncrease| hospitalizedCurrently| hospitalizedIncrease|
|:----------|:-----|-----:|-------------:|---------------------:|--------------------:|
|2020-10-31 |AK | 82| 1| 94| 7|
|2020-10-31 |AL | 2967| 35| 960| 0|
|2020-10-31 |AR | 1925| 25| 652| 35|
|2020-10-31 |AS | 0| 0| NA| 0|
|2020-10-31 |AZ | 5979| 45| 889| 68|
|2020-10-31 |CA | 17626| 55| 3212| 0|

This is in a convenient format: Each day's observations for each state are in
one row. Suppose we would like to extract `hospitalizedIncrease` as a signal we
want to map and analyze alongside other data fetched with `covidcast_signal()`.
Expand All @@ -59,7 +73,8 @@ your data source includes multiple revisions of each observation.)
and source/signal name to apply to the data. With a bit of
[dplyr](https://dplyr.tidyverse.org/) data wrangling, we can do this easily:

```{r, message=FALSE}

```r
library(covidcast)

hospitalized <- data %>%
Expand All @@ -76,21 +91,41 @@ head(hospitalized) %>%
knitr::kable()
```



|data_source |signal |geo_value |time_value | value|issue |
|:--------------|:---------------------|:---------|:----------|-----:|:----------|
|covid-tracking |hospitalized_increase |ak |2020-10-31 | 7|2023-07-12 |
|covid-tracking |hospitalized_increase |al |2020-10-31 | 0|2023-07-12 |
|covid-tracking |hospitalized_increase |ar |2020-10-31 | 35|2023-07-12 |
|covid-tracking |hospitalized_increase |as |2020-10-31 | 0|2023-07-12 |
|covid-tracking |hospitalized_increase |az |2020-10-31 | 68|2023-07-12 |
|covid-tracking |hospitalized_increase |ca |2020-10-31 | 0|2023-07-12 |

This allows us to make maps using the same functions used for other COVIDcast
data:

```{r}

```r
plot(hospitalized, plot_type = "choro")
```

```
Warning: Metadata for signal mean and standard deviation not available;
defaulting to observed mean and standard deviation to set plot range.
```

![](figures/ext-unnamed-chunk-3-1.png)

## Analysis alongside other signals

Now that our data is loaded as a `covidcast_signal` object, we can use it
alongside other signals from the API. For example, let's examine how new COVID
hospitalizations correlate with outpatient doctor visits with deaths during
October 2020, where we use death data as reported by the API.

```{r, message=FALSE}

```r
deaths <- covidcast_signal("jhu-csse", "deaths_7dav_incidence_prop",
start_day = "2020-10-01",
end_day = "2020-10-31",
Expand All @@ -99,17 +134,46 @@ deaths <- covidcast_signal("jhu-csse", "deaths_7dav_incidence_prop",
covidcast_cor(deaths, hospitalized, by = "time_value")
```

```
# A tibble: 31 × 2
time_value value
<date> <dbl>
1 2020-10-01 0.218
2 2020-10-02 0.120
3 2020-10-03 0.147
4 2020-10-04 0.148
5 2020-10-05 0.0436
6 2020-10-06 0.0706
7 2020-10-07 0.123
8 2020-10-08 0.0300
9 2020-10-09 0.0955
10 2020-10-10 0.178
# ℹ 21 more rows
```

We can also use the tools provided by this package to place both signals into a
single data frame for analysis. For example, to build a model that uses
hospitalizations and other data to predict deaths, it may be convenient to
produce a data frame where each row represents one state on one day, and each
column is a variable (such as hospitalization or death). Using
`aggregate_signals()`, this is easy:

```{r}

```r
death_hosp <- aggregate_signals(list(deaths, hospitalized),
format = "wide")

head(death_hosp) %>%
knitr::kable()
```



|geo_value |time_value | value+0:jhu-csse_deaths_7dav_incidence_prop| value+0:covid-tracking_hospitalized_increase|
|:---------|:----------|-------------------------------------------:|--------------------------------------------:|
|ca |2020-10-01 | 0.2286116| 0|
|ca |2020-10-02 | 0.2137337| 0|
|ca |2020-10-03 | 0.2122822| 0|
|ca |2020-10-04 | 0.2122822| 0|
|ca |2020-10-05 | 0.2177254| 0|
|ca |2020-10-06 | 0.1788977| 0|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 8fda2f6

Please sign in to comment.