Advanced Forecasting Methods

This document provides a comprehensive overview of advanced forecasting methods as covered in Chapter 12 of Hyndman’s Forecasting: Principles and Practice (fpp3). It includes theoretical explanations, mathematical formulations, and R code examples.

12.1 Complex Seasonality

So far, we have mostly considered relatively simple seasonal patterns such as quarterly and monthly data. However, higher frequency time series often exhibit more complicated seasonal patterns. For example, daily data may have a weekly pattern as well as an annual pattern. Hourly data usually has three types of seasonality: a daily pattern, a weekly pattern, and an annual pattern. Even weekly data can be challenging to forecast as there are not a whole number of weeks in a year, so the annual pattern has a seasonal period of 365.25.

Example: Bank Calls Data

library(fpp3)
## Registered S3 method overwritten by 'tsibble':
##   method               from 
##   as_tibble.grouped_df dplyr
## ── Attaching packages ──────────────────────────────────────────── fpp3 1.0.0 ──
## ✔ tibble      3.2.1     ✔ tsibble     1.1.5
## ✔ dplyr       1.1.4     ✔ tsibbledata 0.4.1
## ✔ tidyr       1.3.1     ✔ feasts      0.3.2
## ✔ lubridate   1.9.3     ✔ fable       0.3.4
## ✔ ggplot2     3.5.1     ✔ fabletools  0.4.2
## ── Conflicts ───────────────────────────────────────────────── fpp3_conflicts ──
## ✖ lubridate::date()    masks base::date()
## ✖ dplyr::filter()      masks stats::filter()
## ✖ tsibble::intersect() masks base::intersect()
## ✖ tsibble::interval()  masks lubridate::interval()
## ✖ dplyr::lag()         masks stats::lag()
## ✖ tsibble::setdiff()   masks base::setdiff()
## ✖ tsibble::union()     masks base::union()
# Load bank call data
bank_calls |>
  fill_gaps() |>
  autoplot(Calls) +
  labs(y = "Calls", title = "Five-minute call volume to bank")

12.2 Prophet Model

The Prophet model, introduced by Facebook, is available via the fable.prophet package and is particularly effective for time series with strong seasonality and several seasons of historical data.

Example: Quarterly Cement Production

library(fable.prophet)
## Loading required package: Rcpp
cement <- aus_production |>
  filter(year(Quarter) >= 1988)
train <- cement |>
  filter(year(Quarter) <= 2007)
fit <- train |>
  model(
    arima = ARIMA(Cement),
    ets = ETS(Cement),
    prophet = prophet(Cement ~ season(period = 4, order = 2, type = "multiplicative"))
  )

fc <- fit |> forecast(h = "2 years 6 months")
fc |> autoplot(cement)

12.3 Vector Autoregressions (VAR)

A VAR model treats all variables symmetrically, allowing feedback relationships between them.

Example: VAR Model for US Consumption

fit <- us_change |>
  model(
    aicc = VAR(vars(Consumption, Income)),
    bic = VAR(vars(Consumption, Income), ic = "bic")
  )
fit |>
  select(aicc) |>
  forecast() |>
  autoplot(us_change |> filter(year(Quarter) > 2010))

12.4 Neural Network Models

Neural networks are forecasting methods based on simple mathematical models of the brain, allowing for complex nonlinear relationships.

Example: Sunspots

sunspots <- sunspot.year |> as_tsibble()
fit <- sunspots |>
  model(NNETAR(sqrt(value)))
fit |>
  forecast(h = 30) |>
  autoplot(sunspots) +
  labs(x = "Year", y = "Counts", title = "Yearly sunspots")

12.5 Bootstrapping and Bagging

Bootstrapping generates new time series that are similar to the observed series, which can be averaged to improve forecast accuracy.

Example: Cement Production

cement <- aus_production |>
  filter(year(Quarter) >= 1988) |>
  select(Quarter, Cement)
cement_stl <- cement |>
  model(stl = STL(Cement))
cement_stl |>
  generate(new_data = cement, times = 10, bootstrap_block_size = 8) |>
  autoplot(.sim) +
  autolayer(cement, Cement) +
  labs(title = "Cement production: Bootstrapped series", y="Tonnes ('000)")

Conclusion

This R Markdown document covered advanced forecasting methods from Chapter 12, with theory, R code, and practical examples.