convert_bytime: Convert a list of h_ahead format Forecast objects to a time...

View source: R/lmForc_transform.R

convert_bytimeR Documentation

Convert a list of h_ahead format Forecast objects to a time format Forecast object.

Description

Given a list of forecasts with different h_ahead values, converts the forecasts to time format based on the time object passed to the values argument. Converts Forecast objects that have have homogenous h_ahead values to Forecast objects with homogenous origin or future values.

Usage

convert_bytime(forcs, values, slot)

Arguments

forcs

List of Forecast objects.

values

Single time object or a vector of time objects.

slot

Character representing whether the list of Forecasts will be converted to homogenous origin or future values. Must be either "origin" or "future".

Value

Single Forecast object or list of Forecast objects in time format.

Examples


# The following forecasts are in h_ahead format. All forecasts come from the 
# same source (forc1) and have the same origin values. However, the forecasts
# are for different periods ahead.

forc1_1h <- Forecast(
  origin = as.Date(c("2010-02-17", "2010-05-14", "2010-07-22", "2010-12-22")),
  future = as.Date(c("2010-06-30", "2010-09-30", "2010-12-31", "2011-03-31")),
  forecast = c(4.27, 3.36, 4.78, 5.45),
  realized = c(4.96, 4.17, 4.26, 4.99),
  h_ahead = 1
)

forc1_2h <- Forecast(
  origin = as.Date(c("2010-02-17", "2010-05-14", "2010-07-22", "2010-12-22")),
  future = as.Date(c("2010-09-30", "2010-12-31", "2011-03-31", "2011-06-30")),
  forecast = c(3.77, 3.82, 4.53, 4.89),
  realized = c(4.17, 4.26, 4.99, 5.33),
  h_ahead = 2
)

forc1_3h <- Forecast(
  origin = as.Date(c("2010-02-17", "2010-05-14", "2010-07-22", "2010-12-22")),
  future = as.Date(c("2010-12-31", "2011-03-31", "2011-06-30", "2011-09-30")),
  forecast = c(3.52, 4.22, 5.03, 5.78),
  realized = c(4.26, 4.99, 5.33, 5.21),
  h_ahead = 3
)

forcs <- list(forc1_1h, forc1_2h, forc1_3h)

convert_bytime(forcs, value = as.Date("2010-05-14"), slot = "origin")

convert_bytime(
  forcs, 
  value = as.Date(c("2010-07-22", "2010-12-22")), 
  slot = "origin"
)


lmForc documentation built on Sept. 11, 2024, 8:14 p.m.