Skip to contents

Converts a "mf_model_forecast" object into a genuine "forecast" object from the forecast package, so that functions such as forecast::accuracy() can be used on bridgr output.

Usage

as.forecast(object, ...)

# S3 method for class 'mf_model_forecast'
as.forecast(object, ...)

Arguments

object

A "mf_model_forecast" object returned by forecast.mf_model().

...

Unused.

Value

An object of class "forecast", with mean, lower, upper, x, fitted and residuals stored as stats::ts() objects.

Details

Conversion requires a target frequency that stats::ts() can represent exactly, that is, a whole number of target periods per calendar year. Annual, semi-annual, quarterly, bi-monthly and monthly targets qualify; daily, weekly and sub-daily targets do not, and are rejected with an informative error rather than silently approximated.

See also

forecast.mf_model() for the native forecast object, which supports every target frequency.

Examples

gdp_growth <- tsbox::ts_pc(gdp)
#> [value]: 'values' 
#> [value]: 'values' 
gdp_growth <- tsbox::ts_na_omit(gdp_growth)
#> [value]: 'values' 
model <- mf_model(
  target = gdp_growth,
  indic = baro,
  indic_predict = "auto.arima",
  indic_aggregators = "mean",
  h = 1
)

converted <- as.forecast(forecast(model))
class(converted)
#> [1] "forecast"