View source: R/as_covid_hub_forecasts.R
as_covid_hub_forecasts | R Documentation |
model_output_tbl
class (or similar) to
that of a data.frame
formatted according to standards of the COVID-19
Forecasting Hub which can be processed by functions from the covidHubUtils
package such as score_forecasts()
or plot_forecasts()
. The supplied
model_output_tbl
should have columns defining properties akin to
reference dates, locations, horizons, and targets.Reformat model outputs stored as a model_output_tbl
class (or similar) to
that of a data.frame
formatted according to standards of the COVID-19
Forecasting Hub which can be processed by functions from the covidHubUtils
package such as score_forecasts()
or plot_forecasts()
. The supplied
model_output_tbl
should have columns defining properties akin to
reference dates, locations, horizons, and targets.
as_covid_hub_forecasts(
model_outputs,
model_id_col = "model_id",
reference_date_col = "forecast_date",
location_col = "location",
horizon_col = "horizon",
target_col = "target",
output_type_col = "output_type",
output_type_id_col = "output_type_id",
value_col = "value",
temp_res_col = "temporal_resolution",
target_end_date_col = "target_end_date"
)
model_outputs |
an object of class |
model_id_col |
|
reference_date_col |
|
location_col |
|
horizon_col |
|
target_col |
|
output_type_col |
|
output_type_id_col |
|
value_col |
|
temp_res_col |
|
target_end_date_col |
|
a data.frame
of reformatted model outputs that may be fed into
any of the covidHubUtils
functions with 10 total columns: model,
forecast_date, location, horizon, temporal_resolution, target_variable,
target_end_date, type, quantile, value. Other columns are removed.
library(dplyr)
forecasts <- load_forecasts(
models = c("COVIDhub-ensemble", "UMass-MechBayes"),
dates = "2020-12-14",
date_window_size = 7,
locations = c("US"),
targets = paste(1:4, "wk ahead inc death"),
source = "zoltar"
)
altered_forecasts <- forecasts |> # Alter forecasts to not be CovidHub format
dplyr::rename(model_id=model, output_type=type, output_type_id=quantile) |>
dplyr::mutate(target_variable = "wk ahead inc death", horizon=as.numeric(horizon)) |>
dplyr::select(-temporal_resolution)
formatted_forecasts <- as_covid_hub_forecasts(
altered_forecasts,
target_col="target_variable",
temp_res_col=NULL
) |>
dplyr::mutate(horizon=as.character(horizon))
testthat::expect_equal(formatted_forecasts, dplyr::select(forecasts, model:value))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.