Harmonic regression for multiple seasonality
Harmonic regressions are also useful when time series have multiple seasonal patterns. For example, taylor
contains half-hourly electricity demand in England and Wales over a few months in the year 2000. The seasonal periods are 48 (daily seasonality) and 7 x 48 = 336 (weekly seasonality). There is not enough data to consider annual seasonality.
auto.arima()
would take a long time to fit a long time series such as this one, so instead you will fit a standard regression model with Fourier terms using the tslm()
function. This is very similar to lm()
but is designed to handle time series. With multiple seasonality, you need to specify the order \(K\) for each of the seasonal periods.
# The formula argument is a symbolic description
# of the model to be fitted
> args(tslm)
function (formula, ...)
tslm()
is a newly introduced function, so you should be able to follow the pre-written code for the most part. The taylor
data are loaded into your workspace.
This is a part of the course
“Forecasting in R”
Exercise instructions
- Fit a harmonic regression called
fit
totaylor
using order 10 for each type of seasonality. - Forecast 20 working days ahead as
fc
. Remember that the data are half-hourly in order to set the correct value forh
. - Create a time plot of the forecasts.
- Check the residuals of your fitted model. As you can see,
auto.arima()
would have done a better job.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Fit a harmonic regression using order 10 for each type of seasonality
fit <- tslm(taylor ~ fourier(___, K = c(10, 10)))
# Forecast 20 working days ahead
fc <- forecast(___, newdata = data.frame(fourier(___, K = ___, h = ___)))
# Plot the forecasts
___
# Check the residuals of fit
___