The forecast function allows you to produce future predictions of a time series from fitted models. If the response variable has been transformed in the model formula, the transformation will be automatically back-transformed (and bias adjusted if bias_adjust is TRUE). More details about transformations in the fable framework can be found in vignette("transformations", package = "fable").

forecast(object, ...)

# S3 method for mdl_df
forecast(object, new_data = NULL, h = NULL,
  bias_adjust = TRUE, ...)

Arguments

object

The time series model used to produce the forecasts

...

Additional arguments for forecast model methods.

new_data

A tsibble containing future information used to forecast.

h

The forecast horison (can be used instead of new_data for regular time series with no exogenous regressors).

bias_adjust

Use adjusted back-transformed mean for transformations. Refer to vignette("transformations", package = "fable") for more details.

Details

The forecasts returned contain both point forecasts and their distribution. A specific forecast interval can be extracted from the distribution using the hilo() function, and multiple intervals can be obtained using report(). These intervals are stored in a single column using the hilo class, to extract the numerical upper and lower bounds you can use tidyr::unnest().

Examples

library(fable) library(tsibble) library(tsibbledata) library(dplyr) library(tidyr) # Forecasting with an ETS(M,Ad,A) model to Australian beer production beer_fc <- aus_production %>% model(ets = ETS(log(Beer) ~ error("M") + trend("Ad") + season("A"))) %>% forecast(h = "3 years") # Compute 80% and 95% forecast intervals beer_fc %>% hilo(level = c(80, 95))
#> # A tsibble: 12 x 5 [1Q] #> # Key: .model [1] #> .model Quarter Beer `80%` `95%` #> <chr> <qtr> <dbl> <hilo> <hilo> #> 1 ets 2010 Q3 407. [388.3086, 425.8337]80 [378.9423, 436.3591]95 #> 2 ets 2010 Q4 483. [459.8714, 506.5468]80 [448.2540, 519.6750]95 #> 3 ets 2011 Q1 419. [398.6325, 439.3894]80 [388.4926, 450.8578]95 #> 4 ets 2011 Q2 384. [365.3574, 403.7254]80 [355.8271, 414.5385]95 #> 5 ets 2011 Q3 405. [382.4128, 427.7091]80 [371.2483, 440.5715]95 #> 6 ets 2011 Q4 481. [452.3059, 509.7606]80 [438.2139, 526.1534]95 #> 7 ets 2012 Q1 417. [391.5386, 443.0498]80 [378.9369, 457.7836]95 #> 8 ets 2012 Q2 383. [358.4021, 407.8355]80 [346.3522, 422.0245]95 #> 9 ets 2012 Q3 403. [374.7091, 432.7834]80 [360.6877, 449.6076]95 #> 10 ets 2012 Q4 479. [442.8408, 516.4800]80 [425.1726, 537.9426]95 #> 11 ets 2013 Q1 416. [383.0362, 449.4648]80 [367.1605, 468.8992]95 #> 12 ets 2013 Q2 382. [350.3968, 414.1880]80 [335.2233, 432.9358]95
beer_fc %>% autoplot(aus_production)
# Forecasting with a seasonal naive and linear model to the monthly # "Food retailing" turnover for each Australian state/territory. library(dplyr) aus_retail %>% filter(Industry == "Food retailing") %>% model( snaive = SNAIVE(Turnover), ets = TSLM(log(Turnover) ~ trend() + season()), ) %>% forecast(h = "2 years 6 months") %>% autoplot(filter(aus_retail, Month >= yearmonth("2000 Jan")), level = 90)
# Forecast GDP with a dynamic regression model on log(GDP) using population and # an automatically chosen ARIMA error structure. Assume that population is fixed # in the future. aus_economy <- global_economy %>% filter(Country == "Australia") fit <- aus_economy %>% model(lm = ARIMA(log(GDP) ~ Population))
#> Warning: 1 error encountered for lm #> [1] The `urca` package must be installed to use this functionality. It can be installed with install.packages("urca")
future_aus <- new_data(aus_economy, n = 10) %>% mutate(Population = last(aus_economy$Population)) fit %>% forecast(new_data = future_aus) %>% autoplot(aus_economy)