Internal function that add reference dates and relative horizons to a dataframe of forecasts. This function requires that the forecasts data frame contains only forecasts one temporal_resolution, i.e., only at the daily resolution or the weekly resolution.

align_forecasts_one_temporal_resolution(
  forecasts,
  reference_dates,
  reference_weekday,
  reference_windows,
  drop_nonpos_relative_horizons
)

Arguments

forecasts

dataframe in format returned by load_forecasts

reference_dates

a vector of reference dates for forecasts, grouping forecasts that were made during the same week. May be a character vector in the format "YYYY-MM-DD" or a vector of Dates. For example, if a forecast of daily hospitalizations is issued with a forecast date that is Saturday, 2021-09-04, and we want to align analyses around a Monday, the reference date would be Monday, 2021-09-06. This can be accomplished more easily by providing the reference_weekday argument below.

reference_weekday

capitalized weekday, e.g. "Monday". The day of week to use for reference dates, if the reference_dates argument is missing or NULL

reference_windows

an integer vector of offset values indicating the set of forecast dates should be assigned to a particular reference date, in units of number of days. If the reference_weekday is "Monday", the function defaults to -6:0, so that all forecasts with a forecast_date in the week leading up to a particular Monday will be assigned a reference date of that Monday. By default, if the reference_weekday is "Saturday", the function defaults to -4:2. This is appropriate for forecasts of weekly targets, in which case we might like to assign a forecast issued on a Monday to have a reference date of the previous Saturday.

drop_nonpos_relative_horizons

boolean indicating whether forecasts that have a non-positive horizon relative to the reference date should be dropped. Defaults to TRUE

Value

forecast dataframe augmented by columns reference_date and relative_horizon