Skip to contents

This function creates a forecast template for the given dataset where the output includes all unique locations from the input data and the specified forecast horizon.

Usage

create_forecast_template(train_data)

Arguments

train_data

Input data used to create the forecast template.

Value

Returns a data frame containing the forecast template. The output has the following columns: location, date, value, signal, day, and trn_tst. Each row of the output dataframe will contain a unique location from the input dataset, and dates ranging from forecast_horiz_start to forecast_horiz_end. The values in the value column are left as NA. The signal column is set to "hosp" indicating hospital data. The day column specifies the weekday for the corresponding date. The trn_tst column indicates whether the observation was part of the training or test dataset. For the forecast template, all rows will have "test". The final output contains only distinct observations with respect to columns date and location. Additionally, the dataset returned by this function contains an additional column named 'Region' joined from the original input data.

Examples

library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(lubridate)
#> 
#> Attaching package: 'lubridate'
#> The following objects are masked from 'package:base':
#> 
#>     date, intersect, setdiff, union
# create sample data
date_data <- seq(as.Date("2021-01-01"), as.Date("2021-01-31"), by = "day")
loc_data <- c('loc1', 'loc2')
val_data <- c(1, 2)
hosp_data <- rep('hosp', length(date_data))
day_data <- weekdays(date_data)
trn_tst_data <- 'train'
data <- data.frame(date = rep(date_data, length(loc_data)),
                   location = rep(loc_data, each = length(date_data)),
                   value = rep(val_data, each = length(date_data)),
                   signal = hosp_data,
                   day = rep(day_data, length(loc_data)),
                   trn_tst = trn_tst_data)

create_forecast_template(data, as.Date("2021-02-01"), as.Date("2021-02-10"))
#> Error in create_forecast_template(data, as.Date("2021-02-01"), as.Date("2021-02-10")): unused arguments (as.Date("2021-02-01"), as.Date("2021-02-10"))