R/load_forecasts.R
load_forecasts.Rd
If date_window_size
is 0, this function returns all available forecasts
submitted on every day in dates
.
Ifdate_window_size
is not 0, this function will look for the latest
forecasts that are submitted within window size for each day in dates
.
If source
is local_zoltar
, a valid sqlite3 object is required.
Please follow the instruction in load_forecasts_local_zoltar()
to set up
required environment.
load_forecasts(
models = NULL,
dates = NULL,
date_window_size = 0,
locations = NULL,
types = NULL,
targets = NULL,
source = "zoltar",
hub_repo_path,
local_zoltpy_path,
zoltar_sqlite_file,
data_processed_subpath = "data-processed/",
as_of = NULL,
hub = c("US", "ECDC", "FluSight"),
verbose = TRUE
)
Character vector of model abbreviations. Default all models that submitted forecasts meeting the other criteria.
The forecast date of forecasts to retrieve. A vector of one or more Date objects or character strings in format “YYYY-MM-DD” Default to all valid forecast dates.
The number of days across each date in dates
parameter to
look for the most recent forecasts.
Default to 0, which means to only look at the dates
parameter only.
a vector of strings of fips code or CBSA codes or location names,
such as "Hampshire County, MA", "Alabama", "United Kingdom".
A US county location names must include state abbreviation.
Default to NULL
which would include all locations with available forecasts.
Character vector specifying type of forecasts to load: "quantile"
and/or "point"
. Default to all valid forecast types.
character vector of targets to retrieve, for example
c('1 wk ahead cum death', '2 wk ahead cum death')
.
Default to NULL
which stands for all valid targets.
string specifying where forecasts will be loaded from: one of
"local_hub_repo"
, "zoltar"
and "local_zoltar"
. Default to "zoltar"
.
path to local clone of the forecast hub repository
path to local clone of zolpy repository.
Only needed when source
is "local_zoltar
.
path to local sqlite file,
either a relative path w.r.t. local_zoltpy_path
or an absolute path.
Only needed when source
is "local_zoltar
.
folder within the hub_repo_path that contains
forecast submission files. Default to "data-processed/"
, which is
appropriate for the covid19-forecast-hub repository.
character for date time to load forecasts submitted as of this time from Zoltar.
Ignored if source = "local_hub_repo"
.
It could use the format of one of the three examples:
"2021-01-01", "2020-01-01 01:01:01" and "2020-01-01 01:01:01 UTC"
.
If you would like to set a timezone, it has to be UTC now.
If not, helper function will append the default timezone to your input based on hub
parameter.
Default to NULL to load the latest version.
character vector, where the first element indicates the hub
from which to load forecasts. Possible options are "US"
, "ECDC"
and "FluSight"
.
logical to print out diagnostic messages. Default is TRUE
.
data.frame with columns model
, forecast_date
, location
, horizon
,
temporal_resolution
, target_variable
, target_end_date
, type
, quantile
, value
,
location_name
, population
, geo_type
, geo_value
, abbreviation
# Load forecasts from US forecast hub
# This call only loads the latest forecast submitted on "2021-07-26" in
# a 12-day window w.r.t "2021-7-30".
load_forecasts(
models = "COVIDhub-ensemble",
dates = "2021-07-30",
date_window_size = 11,
locations = "US",
types = c("point", "quantile"),
targets = paste(1:4, "wk ahead inc case"),
source = "zoltar",
verbose = FALSE,
as_of = NULL
)
#> get_token(): POST: https://zoltardata.com/api-token-auth/
#> get_resource(): GET: https://zoltardata.com/api/projects/
#> get_resource(): GET: https://zoltardata.com/api/project/44/models/
#> get_resource(): GET: https://zoltardata.com/api/project/44/timezeros/
#> # A tibble: 32 × 16
#> model forecast_date location horizon temporal_resolution target_variable
#> <chr> <date> <chr> <chr> <chr> <chr>
#> 1 COVIDhub-… 2021-07-26 US 1 wk inc case
#> 2 COVIDhub-… 2021-07-26 US 1 wk inc case
#> 3 COVIDhub-… 2021-07-26 US 1 wk inc case
#> 4 COVIDhub-… 2021-07-26 US 1 wk inc case
#> 5 COVIDhub-… 2021-07-26 US 1 wk inc case
#> 6 COVIDhub-… 2021-07-26 US 1 wk inc case
#> 7 COVIDhub-… 2021-07-26 US 1 wk inc case
#> 8 COVIDhub-… 2021-07-26 US 1 wk inc case
#> 9 COVIDhub-… 2021-07-26 US 2 wk inc case
#> 10 COVIDhub-… 2021-07-26 US 2 wk inc case
#> # ℹ 22 more rows
#> # ℹ 10 more variables: target_end_date <date>, type <chr>, quantile <dbl>,
#> # value <dbl>, location_name <chr>, population <dbl>, geo_type <chr>,
#> # geo_value <chr>, abbreviation <chr>, full_location_name <chr>
# Load forecasts from ECDC forecast hub
# This function call loads the latest forecasts in each 2-day window
# w.r.t "2021-03-08" and "2021-07-27".
load_forecasts(
models = "ILM-EKF",
hub = c("ECDC", "US"),
dates = c("2021-03-08", "2021-07-27"),
date_window_size = 1,
locations = "GB",
targets = paste(1:4, "wk ahead inc death"),
source = "zoltar"
)
#> get_token(): POST: https://zoltardata.com/api-token-auth/
#> get_resource(): GET: https://zoltardata.com/api/projects/
#> get_resource(): GET: https://zoltardata.com/api/project/238/models/
#> get_resource(): GET: https://zoltardata.com/api/project/238/timezeros/
#> # A tibble: 192 × 12
#> model forecast_date location horizon temporal_resolution target_variable
#> <chr> <date> <chr> <chr> <chr> <chr>
#> 1 ILM-EKF 2021-03-08 GB 1 wk inc death
#> 2 ILM-EKF 2021-03-08 GB 1 wk inc death
#> 3 ILM-EKF 2021-03-08 GB 1 wk inc death
#> 4 ILM-EKF 2021-03-08 GB 1 wk inc death
#> 5 ILM-EKF 2021-03-08 GB 1 wk inc death
#> 6 ILM-EKF 2021-03-08 GB 1 wk inc death
#> 7 ILM-EKF 2021-03-08 GB 1 wk inc death
#> 8 ILM-EKF 2021-03-08 GB 1 wk inc death
#> 9 ILM-EKF 2021-03-08 GB 1 wk inc death
#> 10 ILM-EKF 2021-03-08 GB 1 wk inc death
#> # ℹ 182 more rows
#> # ℹ 6 more variables: target_end_date <date>, type <chr>, quantile <dbl>,
#> # value <dbl>, location_name <chr>, population <int>