if (!requireNamespace("pak", quietly = TRUE)) install.packages("pak")
if (!requireNamespace("InsightNetApr26", quietly = TRUE)) {
pak::pkg_install("cmu-delphi/InsightNet-apr-2026/InsightNetApr26")
}
InsightNetApr26::verify_setup()
library(epidatr)
library(epiprocess)MINI-PROJECT 1: Finding indicators and fetching data
Introduction
This notebook covers the first mini-project, focusing on finding indicators and fetching data through the Delphi Epidata API.
Load packages
{InsightNetApr26} package ensures all required Delphi tools and their correct versions/branches are installed.
Finding Indicators
You can explore available indicators in the Delphi Epidata API documentation. For this example, we’ll use the “Doctor visits CLI” indicator.
Fetching Data
We’ll fetch the smoothed_adj_cli signal from the doctor-visits source for selected states over a specific time range.
res <- pub_covidcast(
source = "doctor-visits",
signal = "smoothed_adj_cli",
geo_type = "state",
time_type = "day",
geo_values = c("mi", "ny", "tx", "pa"),
time_values = epirange(20220101, 20220301)
)Processing and Visualization
We convert the raw API response into an epi_df for easier analysis and plotting.
# Convert the data into epi_df format
edf <- as_epi_df(res)
# View the header of the resulting epi_df
head(edf)An `epi_df` object, 6 x 15 with metadata:
* geo_type = state
* time_type = day
* other_keys = signal
* as_of = 2022-05-11
Latency (lag from as_of to latest observation by time series):
* lag = 129–130 days
* Empty time series detected
# A tibble: 6 × 15
geo_value signal time_value source geo_type time_type direction issue
<chr> <chr> <date> <chr> <fct> <fct> <dbl> <date>
1 mi smoothed_… 2022-01-01 docto… state day NA 2022-03-15
2 ny smoothed_… 2022-01-01 docto… state day NA 2022-03-15
3 pa smoothed_… 2022-01-01 docto… state day NA 2022-03-15
4 tx smoothed_… 2022-01-01 docto… state day NA 2022-03-15
5 mi smoothed_… 2022-01-02 docto… state day NA 2022-03-16
6 ny smoothed_… 2022-01-02 docto… state day NA 2022-03-16
# ℹ 7 more variables: lag <dbl>, missing_value <dbl>, missing_stderr <dbl>,
# missing_sample_size <dbl>, value <dbl>, stderr <dbl>, sample_size <dbl>
# Quickly plot the data using epiprocess::autoplot
autoplot(edf, value)