In this chapter, we briefly discuss four more advanced forecasting methods that build on the models discussed in earlier chapters.
11.1 Complex seasonality
So far, we have 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 it typically has an annual pattern with seasonal period of 365.25/7 \approx 52.179 on average.
Such multiple seasonal patterns are becoming more common with high frequency data recording. Further examples where multiple seasonal patterns can occur include call volume in call centres, daily hospital admissions, requests for cash at ATMs, electricity and water usage, and access to computer web sites.
Most of the methods we have considered so far are unable to deal with these seasonal complexities. Even the ts class in R can only handle one type of seasonality, which is usually assumed to take integer values.
To deal with such series, we will use the msts class which handles multiple seasonality time series. This allows you to specify all of the frequencies that might be relevant. It is also flexible enough to handle non-integer frequencies.
Despite this flexibility, we don’t necessarily want to include all of these frequencies — just the ones that are likely to be present in the data. For example, if we have only 180 days of data, we may ignore the annual seasonality. If the data are measurements of a natural phenomenon (e.g., temperature), we can probably safely ignore any weekly seasonality.
The top panel of Figure 11.1 shows the number of retail banking call arrivals per 5-minute interval between 7:00am and 9:05pm each weekday over a 33 week period. The bottom panel shows the first three weeks of the same time series. There is a strong daily seasonal pattern with frequency 169 (there are 169 5-minute intervals per day), and a weak weekly seasonal pattern with frequency 169 \times 5 = 845. (Call volumes on Mondays tend to be higher than the rest of the week.) If a longer series of data were available, we may also have observed an annual seasonal pattern.
p1 <-autoplot(calls) +ylab("Call volume") +xlab("Weeks") +scale_x_continuous(breaks =seq(1, 33, by =2))p2 <-autoplot(window(calls, end =4)) +ylab("Call volume") +xlab("Weeks") +scale_x_continuous(minor_breaks =seq(1, 4, by =0.2))gridExtra::grid.arrange(p1, p2)
Figure 11.1: Five-minute call volume handled on weekdays between 7:00am and 9:05pm in a large North American commercial bank. Top panel shows data from 3 March 2003 for 164 days.
STL with multiple seasonal periods
The mstl() function is a variation on stl() designed to deal with multiple seasonality. It will return multiple seasonal components, as well as a trend and remainder component.
calls |>mstl() |>autoplot() +xlab("Week")
Figure 11.2: Multiple STL for the call volume data.
There are two seasonal patterns shown, one for the time of day (the third panel), and one for the time of week (the fourth panel). To properly interpret this graph, it is important to notice the vertical scales. In this case, the trend and the weekly seasonality have relatively narrow ranges compared to the other components, because there is little trend seen in the data, and the weekly seasonality is weak.
The decomposition can also be used in forecasting, with each of the seasonal components forecast using a seasonal naïve method, and the seasonally adjusted data forecasting using ETS (or some other user-specified method). The stlf() function will do this automatically.
calls |>stlf() |>autoplot() +xlab("Week")
Figure 11.3: Multiple STL for the call volume data.
Dynamic harmonic regression with multiple seasonal periods
With multiple seasonalities, we can use Fourier terms as we did in earlier chapters (see Sections 5.4 and 9.5). Because there are multiple seasonalities, we need to add Fourier terms for each seasonal period. In this case, the seasonal periods are 169 and 845, so the Fourier terms are of the form
\sin\left( \frac{2\pi kt}{169} \right), \quad \cos\left( \frac{2\pi kt}{169} \right),
\quad \sin\left( \frac{2\pi kt}{845} \right),
\quad \text{and} \quad \cos\left( \frac{2\pi kt}{845} \right),
for k = 1,2,\dots. The fourier() function can generate these for you.
We will fit a dynamic harmonic regression model with an ARMA error structure. The total number of Fourier terms for each seasonal period have been chosen to minimise the AICc. We will use a log transformation (lambda=0) to ensure the forecasts and prediction intervals remain positive.
fit <-auto.arima( calls,seasonal =FALSE,lambda =0,xreg =fourier(calls, K =c(10, 10)))fit |>forecast(xreg =fourier(calls, K =c(10, 10), h =2*169)) |>autoplot(include =5*169) +ylab("Call volume") +xlab("Weeks")
Figure 11.4: Forecasts from a dynamic harmonic regression applied to the call volume data.
This is a large model, containing 40 parameters: 4 ARMA coefficients, 20 Fourier coefficients for frequency 169, and 16 Fourier coefficients for frequency 845. We don’t use all the Fourier terms for frequency 845 because there is some overlap with the terms of frequency 169 (since 845 = 5 \times 169).
TBATS models
An alternative approach developed by De Livera et al. (2011) uses a combination of Fourier terms with an exponential smoothing state space model and a Box-Cox transformation, in a completely automated manner. As with any automated modelling framework, there may be cases where it gives poor results, but it can be a useful approach in some circumstances.
A TBATS model differs from dynamic harmonic regression in that the seasonality is allowed to change slowly over time in a TBATS model, while harmonic regression terms force the seasonal patterns to repeat periodically without changing. One drawback of TBATS models, however, is that they can be slow to estimate, especially with long time series. Hence, we will consider a subset of the calls data to save time.
calls |>subset(start =length(calls) -2000) |>tbats() -> fit2fc2 <-forecast(fit2, h =2*169)autoplot(fc2, include =5*169) +ylab("Call volume") +xlab("Weeks")
Figure 11.5: Forecasts from a TBATS model applied to the call volume data.
Here the prediction intervals appear to be much too wide – something that seems to happen quite often with TBATS models unfortunately.
Complex seasonality with covariates
TBATS models do not allow for covariates, although they can be included in dynamic harmonic regression models. One common application of such models is electricity demand modelling.
Figure 11.6 shows half-hourly electricity demand in Victoria, Australia, during 2014, along with temperatures for the same period for Melbourne (the largest city in Victoria).
Figure 11.6: Half-hourly electricity demand and corresponding temperatures in 2014, Victoria, Australia.
Plotting electricity demand against temperature (Figure 11.7) shows that there is a nonlinear relationship between the two, with demand increasing for low temperatures (due to heating) and increasing for high temperatures (due to cooling).
Figure 11.7: Half-hourly electricity demand for Victoria, plotted against temperatures for the same times in Melbourne, the largest city in Victoria.
We will fit a regression model with a piecewise linear function of temperature (containing a knot at 18 degrees), and harmonic regression terms to allow for the daily seasonal pattern.
Forecasting with such models is difficult because we require future values of the predictor variables. Future values of the Fourier terms are easy to compute, but future temperatures are, of course, unknown. If we are only interested in forecasting up to a week ahead, we could use temperature forecasts obtain from a meteorological model. Alternatively, we could use scenario forecasting (Section 4.5) and plug in possible temperature patterns. In the following example, we have used a repeat of the last two days of temperatures to generate future possible demand values.
temps <-subset( elecdemand[, "Temperature"],start =NROW(elecdemand) -2*48+1)fc <-forecast( fit,xreg =cbind(fourier(temps, c(10, 10, 0)),heating = temps,cooling =pmax(temps, 18) ))autoplot(fc, include =14*48)
Figure 11.8: Forecasts from a dynamic harmonic regression model applied to half-hourly electricity demand data.
Although the short-term forecasts look reasonable, this is a crude model for a complicated process. The residuals demonstrate that there is a lot of information that has not been captured with this model.
checkresiduals(fc)
Ljung-Box testdata: Residuals from Regression with ARIMA(5,1,4) errorsQ*=738430, df =3495, p-value <2e-16Model df:9. Total lags used:3504
Figure 11.9: Residual diagnostics for the dynamic harmonic regression model.
More sophisticated versions of this model which provide much better forecasts are described in Hyndman & Fan (2010) and Fan & Hyndman (2012).
11.2 Vector autoregressions
One limitation of the models that we have considered so far is that they impose a unidirectional relationship — the forecast variable is influenced by the predictor variables, but not vice versa. However, there are many cases where the reverse should also be allowed for — where all variables affect each other. In Section 9.2, the changes in personal consumption expenditure (C_t) were forecast based on the changes in personal disposable income (I_t). However, in this case a bi-directional relationship may be more suitable: an increase in I_t will lead to an increase in C_t and vice versa.
An example of such a situation occurred in Australia during the Global Financial Crisis of 2008–2009. The Australian government issued stimulus packages that included cash payments in December 2008, just in time for Christmas spending. As a result, retailers reported strong sales and the economy was stimulated. Consequently, incomes increased.
Such feedback relationships are allowed for in the vector autoregressive (VAR) framework. In this framework, all variables are treated symmetrically. They are all modelled as if they all influence each other equally. In more formal terminology, all variables are now treated as “endogenous”. To signify this, we now change the notation and write all variables as ys: y_{1,t} denotes the tth observation of variable y_1, y_{2,t} denotes the tth observation of variable y_2, and so on.
A VAR model is a generalisation of the univariate autoregressive model for forecasting a vector of time series.1 It comprises one equation per variable in the system. The right hand side of each equation includes a constant and lags of all of the variables in the system. To keep it simple, we will consider a two variable VAR with one lag. We write a 2-dimensional VAR(1) as
\begin{align}
y_{1,t} & = c_1 + \phi_{11,1}y_{1,t-1} + \phi_{12,1}y_{2,t-1} + e_{1,t} \\
y_{2,t} & = c_2 + \phi_{21,1}y_{1,t-1} + \phi_{22,1}y_{2,t-1} + e_{2,t},
\end{align}
\tag{11.1} where e_{1,t} and e_{2,t} are white noise processes that may be contemporaneously correlated. The coefficient \phi_{ii,\ell} captures the influence of the \ellth lag of variable y_i on itself, while the coefficient \phi_{ij,\ell} captures the influence of the \ellth lag of variable y_j on y_i.
If the series are stationary, we forecast them by fitting a VAR to the data directly (known as a “VAR in levels”). If the series are non-stationary, we take differences of the data in order to make them stationary, then fit a VAR model (known as a “VAR in differences”). In both cases, the models are estimated equation by equation using the principle of least squares. For each equation, the parameters are estimated by minimising the sum of squared e_{i,t} values.
The other possibility, which is beyond the scope of this book and therefore we do not explore here, is that the series may be non-stationary but cointegrated, which means that there exists a linear combination of them that is stationary. In this case, a VAR specification that includes an error correction mechanism (usually referred to as a vector error correction model) should be included, and alternative estimation methods to least squares estimation should be used.2
Forecasts are generated from a VAR in a recursive manner. The VAR generates forecasts for each variable included in the system. To illustrate the process, assume that we have fitted the 2-dimensional VAR(1) described in Equations 11.1, for all observations up to time T. Then the one-step-ahead forecasts are generated by
\begin{align*}
\hat y_{1,T+1|T} & = \hat{c}_1 + \hat\phi_{11,1}y_{1,T} + \hat\phi_{12,1}y_{2,T} \\
\hat y_{2,T+1|T} & = \hat{c}_2 + \hat\phi_{21,1}y_{1,T} + \hat\phi_{22,1}y_{2,T}.
\end{align*}
This is the same form as Equations 11.1, except that the errors have been set to zero and parameters have been replaced with their estimates. For h = 2, the forecasts are given by
\begin{align*}
\hat y_{1,T+2|T} & = \hat{c}_1 + \hat\phi_{11,1}\hat y_{1,T+1} + \hat\phi_{12,1}\hat y_{2,T+1} \\
\hat y_{2,T+2|T} & = \hat{c}_2 + \hat\phi_{21,1}\hat y_{1,T+1} + \hat\phi_{22,1}\hat y_{2,T+1}.
\end{align*}
Again, this is the same form as Equations 11.1, except that the errors have been set to zero, the parameters have been replaced with their estimates, and the unknown values of y_1 and y_2 have been replaced with their forecasts. The process can be iterated in this manner for all future time periods.
There are two decisions one has to make when using a VAR to forecast, namely how many variables (denoted by K) and how many lags (denoted by p) should be included in the system. The number of coefficients to be estimated in a VAR is equal to K + pK^2 (or 1 + pK per equation). For example, for a VAR with K = 5 variables and p = 3 lags, there are 16 coefficients per equation, giving a total of 80 coefficients to be estimated. The more coefficients that need to be estimated, the larger the estimation error entering the forecast.
In practice, it is usual to keep K small and include only variables that are correlated with each other, and therefore useful in forecasting each other. Information criteria are commonly used to select the number of lags to be included.
VAR models are implemented in the vars package in R. It contains a function VARselect() for selecting the number of lags p using four different information criteria: AIC, HQ, SC and FPE. We have met the AIC before, and SC is simply another name for the BIC (SC stands for Schwarz Criterion, after Gideon Schwarz who proposed it). HQ is the Hannan-Quinn criterion, and FPE is the “Final Prediction Error” criterion.3 Care should be taken when using the AIC as it tends to choose large numbers of lags. Instead, for VAR models, we prefer to use the BIC.
A criticism that VARs face is that they are atheoretical; that is, they are not built on some economic theory that imposes a theoretical structure on the equations. Every variable is assumed to influence every other variable in the system, which makes a direct interpretation of the estimated coefficients difficult. Despite this, VARs are useful in several contexts:
forecasting a collection of related variables where no explicit interpretation is required;
testing whether one variable is useful in forecasting another (the basis of Granger causality tests);
impulse response analysis, where the response of one variable to a sudden but temporary change in another variable is analysed;
forecast error variance decomposition, where the proportion of the forecast variance of each variable is attributed to the effects of the other variables.
Example: A VAR model for forecasting US consumption
library(vars)
VARselect(uschange[, 1:2], lag.max =8, type ="const")[["selection"]]
AIC(n) HQ(n) SC(n) FPE(n)
5 1 1 5
The R output shows the lag length selected by each of the information criteria available in the vars package. There is a large discrepancy between the VAR(5) selected by the AIC and the VAR(1) selected by the BIC. This is not unusual. As a result we first fit a VAR(1), as selected by the BIC.
var1 <-VAR(uschange[, 1:2], p =1, type ="const")serial.test(var1, lags.pt =10, type ="PT.asymptotic")var2 <-VAR(uschange[, 1:2], p =2, type ="const")serial.test(var2, lags.pt =10, type ="PT.asymptotic")
In similar fashion to the univariate ARIMA methodology, we test that the residuals are uncorrelated using a Portmanteau test4. Both a VAR(1) and a VAR(2) have some residual serial correlation, and therefore we fit a VAR(3).
var3 <-VAR(uschange[, 1:2], p =3, type ="const")serial.test(var3, lags.pt =10, type ="PT.asymptotic")
Portmanteau Test (asymptotic)
data: Residuals of VAR object var3
Chi-squared = 34, df = 28, p-value = 0.2
The residuals for this model pass the test for serial correlation. The forecasts generated by the VAR(3) are plotted in Figure 11.10.
forecast(var3) |>autoplot() +xlab("Year")
Figure 11.10: Forecasts for US consumption and income generated from a VAR(3).
11.3 Neural network models
Artificial neural networks are forecasting methods that are based on simple mathematical models of the brain. They allow complex nonlinear relationships between the response variable and its predictors.
Neural network architecture
A neural network can be thought of as a network of “neurons” which are organised in layers. The predictors (or inputs) form the bottom layer, and the forecasts (or outputs) form the top layer. There may also be intermediate layers containing “hidden neurons”.
The simplest networks contain no hidden layers and are equivalent to linear regressions. Figure 11.11 shows the neural network version of a linear regression with four predictors. The coefficients attached to these predictors are called “weights”. The forecasts are obtained by a linear combination of the inputs. The weights are selected in the neural network framework using a “learning algorithm” that minimises a “cost function” such as the MSE. Of course, in this simple example, we can use linear regression which is a much more efficient method of training the model.
Figure 11.11: A simple neural network equivalent to a linear regression.
Once we add an intermediate layer with hidden neurons, the neural network becomes non-linear. A simple example is shown in Figure 11.12.
Figure 11.12: A neural network with four inputs and one hidden layer with three hidden neurons.
This is known as a multilayer feed-forward network, where each layer of nodes receives inputs from the previous layers. The outputs of the nodes in one layer are inputs to the next layer. The inputs to each node are combined using a weighted linear combination. The result is then modified by a nonlinear function before being output. For example, the inputs into hidden neuron j in Figure 11.12 are combined linearly to give
z_j = b_j + \sum_{i=1}^4 w_{i,j} x_i.
In the hidden layer, this is then modified using a nonlinear function such as a sigmoid,
s(z) = \frac{1}{1 + e^{-z}},
to give the input for the next layer. This tends to reduce the effect of extreme input values, thus making the network somewhat robust to outliers.
The parameters b_1,b_2,b_3 and w_{1,1},\dots,w_{4,3} are “learned” from the data. The values of the weights are often restricted to prevent them from becoming too large. The parameter that restricts the weights is known as the “decay parameter”, and is often set to be equal to 0.1.
The weights take random values to begin with, and these are then updated using the observed data. Consequently, there is an element of randomness in the predictions produced by a neural network. Therefore, the network is usually trained several times using different random starting points, and the results are averaged.
The number of hidden layers, and the number of nodes in each hidden layer, must be specified in advance. Usually, these would be selected using cross-validation.
Neural network autoregression
With time series data, lagged values of the time series can be used as inputs to a neural network, just as we used lagged values in a linear autoregression model (Chapter 8). We call this a neural network autoregression or NNAR model.
In this book, we only consider feed-forward networks with one hidden layer, and we use the notation NNAR(p,k) to indicate there are p lagged inputs and k nodes in the hidden layer. For example, a NNAR(9,5) model is a neural network with the last nine observations (y_{t-1},y_{t-2},\dots,y_{t-9}) used as inputs for forecasting the output y_t, and with five neurons in the hidden layer.
With seasonal data, it is useful to also add the last observed values from the same season as inputs. For example, an NNAR(3,1,2)_{12} model has inputs y_{t-1}, y_{t-2}, y_{t-3} and y_{t-12}, and two neurons in the hidden layer. More generally, an NNAR(p,P,k)_m model has inputs (y_{t-1},y_{t-2},\dots,y_{t-p},y_{t-m},y_{t-2m},\dots, y_{t-Pm}) and k neurons in the hidden layer. A NNAR(p,P,0)_m model is similar to an ARIMA(p,0,0)(P,0,0)_m model but without the restrictions on the parameters that ensure stationarity, and without the cross-product lags (e.g., lag m + 1 when p = P = 1).
The nnetar() function fits an NNAR(p,P,k)_m model. If the values of p and P are not specified, they are selected automatically. For non-seasonal time series, the default is the optimal number of lags (according to the AIC) for a linear AR(p) model. For seasonal time series, the default values are P = 1 and p is chosen from the optimal linear model fitted to the seasonally adjusted data. If k is not specified, it is set to k = (p + P + 1)/2 (rounded to the nearest integer).
When it comes to forecasting, the network is applied iteratively. For forecasting one step ahead, we simply use the available historical inputs. For forecasting two steps ahead, we use the one-step forecast as an input, along with the historical data. This process proceeds until we have computed all the required forecasts.
Example: sunspots
The surface of the sun contains magnetic regions that appear as dark spots. These affect the propagation of radio waves, and so telecommunication companies like to predict sunspot activity in order to plan for any future difficulties. Sunspots follow a cycle of length between 9 and 14 years. In Figure 11.13, forecasts from an NNAR(10,6) are shown for the next 30 years. We have set a Box-Cox transformation with lambda=0 to ensure the forecasts stay positive.
fit <-nnetar(sunspotarea, lambda =0)autoplot(forecast(fit, h =30))
Figure 11.13: Forecasts from a neural network with ten lagged inputs and one hidden layer containing six neurons.
Here, the last 10 observations are used as predictors, and there are 6 neurons in the hidden layer. The cyclicity in the data has been modelled well. We can also see the asymmetry of the cycles has been captured by the model, where the increasing part of the cycle is steeper than the decreasing part of the cycle. This is one difference between a NNAR model and a linear AR model — while linear AR models can model cyclicity, the modelled cycles are always symmetric.
Prediction intervals
Unlike most of the methods considered in this book, neural networks are not based on a well-defined stochastic model, and so it is not straightforward to derive prediction intervals for the resultant forecasts. However, we can still compute prediction intervals using simulation where future sample paths are generated using bootstrapped residuals (as described in Section 3.5).
The neural network fitted to the sunspot data can be written as
y_t = f(\boldsymbol{y}_{t-1}) + \varepsilon_t
where \boldsymbol{y}_{t-1} = (y_{t-1},y_{t-2},\dots,y_{t-10})' is a vector containing lagged values of the series, and f is a neural network with 6 hidden nodes in a single layer. The error series \{\varepsilon_t\} is assumed to be homoscedastic (and possibly also normally distributed).
We can simulate future sample paths of this model iteratively, by randomly generating a value for \varepsilon_t, either from a normal distribution, or by resampling from the historical values. So if \varepsilon^*_{T+1} is a random draw from the distribution of errors at time T + 1, then
y^*_{T+1} = f(\boldsymbol{y}_{T}) + \varepsilon^*_{T+1}
is one possible draw from the forecast distribution for y_{T+1}. Setting \boldsymbol{y}_{T+1}^* = (y^*_{T+1}, y_{T}, \dots, y_{T-8})', we can then repeat the process to get
y^*_{T+2} = f(\boldsymbol{y}^*_{T+1}) + \varepsilon^*_{T+2}.
In this way, we can iteratively simulate a future sample path. By repeatedly simulating sample paths, we build up knowledge of the distribution for all future values based on the fitted neural network.
Here is a simulation of 9 possible future sample paths for the sunspot data. Each sample path covers the next 30 years after the observed data.
Figure 11.14: Future sample paths for the annual sunspot data.
If we do this a few hundred or thousand times, we can get a good picture of the forecast distributions. This is how the forecast() function produces prediction intervals for NNAR models:
fcast <-forecast(fit, PI =TRUE, h =30)autoplot(fcast)
Figure 11.15: Forecasts with prediction intervals for the annual sunspot data. Prediction intervals are computed using simulated future sample paths.
Because it is a little slow, PI=FALSE is the default, so prediction intervals are not computed unless requested. The npaths argument in forecast() controls how many simulations are done (default 1000). By default, the errors are drawn from a normal distribution. The bootstrap argument allows the errors to be “bootstrapped” (i.e., randomly drawn from the historical errors).
11.4 Bootstrapping and bagging
Bootstrapping time series
In the preceding section, and in Section 3.5, we bootstrap the residuals of a time series in order to simulate future values of a series using a model.
More generally, we can generate new time series that are similar to our observed series, using another type of bootstrap.
First, the time series is Box-Cox-transformed, and then decomposed into trend, seasonal and remainder components using STL. Then we obtain shuffled versions of the remainder component to get bootstrapped remainder series. Because there may be autocorrelation present in an STL remainder series, we cannot simply use the re-draw procedure that was described in Section 3.5. Instead, we use a “blocked bootstrap”, where contiguous sections of the time series are selected at random and joined together. These bootstrapped remainder series are added to the trend and seasonal components, and the Box-Cox transformation is reversed to give variations on the original time series.
Some examples are shown in Figure 11.16 for the monthly expenditure on retail debit cards in Iceland, from January 2000 to August 2013.
Figure 11.16: Ten bootstrapped versions of monthly expenditure on retail debit cards in Iceland.
This type of bootstrapping can be useful in two ways. First it helps us to get a better measure of forecast uncertainty, and second it provides a way of improving our point forecasts using “bagging”.
Prediction intervals from bootstrapped series
Almost all prediction intervals from time series models are too narrow. This is a well-known phenomenon and arises because they do not account for all sources of uncertainty. Hyndman et al. (2002) measured the size of the problem by computing the actual coverage percentage of the prediction intervals on test data, and found that for ETS models, nominal 95% intervals may only provide coverage between 71% and 87%. The difference is due to missing sources of uncertainty.
There are at least four sources of uncertainty in forecasting using time series models:
The random error term;
The parameter estimates;
The choice of model for the historical data;
The continuation of the historical data generating process into the future.
When we produce prediction intervals for time series models, we generally only take into account the first of these sources of uncertainty. Even if we ignore the model uncertainty and the uncertainty due to changing data generating processes (sources 3 and 4), and we just try to allow for parameter uncertainty as well as the random error term (sources 1 and 2), there are no algebraic solutions apart from some simple special cases.
We can use bootstrapped time series to go some way towards overcoming this problem. We demonstrate the idea using the debitcards data. First, we simulate many time series that are similar to the original data, using the block-bootstrap described above.
For each of these series, we fit an ETS model and simulate one sample path from that model. A different ETS model may be selected in each case, although it will most likely select the same model because the series are similar. However, the estimated parameters will be different. Therefore the simulated sample paths will allow for model uncertainty and parameter uncertainty, as well as the uncertainty associated with the random error term. This is a time-consuming process as there are a large number of time series to model.
h <-36Lfuture <-matrix(0, nrow = nsim, ncol = h)for (i inseq(nsim)) { future[i, ] <-simulate(ets(sim[[i]]), nsim = h)}
Finally, we take the means and quantiles of these simulated sample paths to form point forecasts and prediction intervals.
These prediction intervals will be larger than those obtained from an ETS model applied directly to the original data.
etsfc <-forecast(ets(debitcards), h = h, level =95)autoplot(debitcards) +ggtitle("Monthly retail debit card usage in Iceland") +xlab("Year") +ylab("million ISK") +autolayer(simfc, series ="Simulated") +autolayer(etsfc, series ="ETS")
Figure 11.17: Forecasts of Iceland debit card usage using an ETS model with regular prediction intervals along with prediction intervals computed using simulations that allow for model and parameter uncertainty.
Bagged ETS forecasts
Another use for these bootstrapped time series is to improve forecast accuracy. If we produce forecasts from each of the additional time series, and average the resulting forecasts, we get better forecasts than if we simply forecast the original time series directly. This is called “bagging” which stands for “bootstrap aggregating”.
We could simply average the simulated future sample paths computed earlier. However, if our interest is only in improving point forecast accuracy, and not in also obtaining improved prediction intervals, then it is quicker to average the point forecasts from each series. The speed improvement comes about because we do not need to produce so many simulated series.
We will use ets() to forecast each of these series. Figure 11.18 shows ten forecasts obtained in this way.
Figure 11.18: Forecasts of the ten bootstrapped series obtained using ETS models.
The average of these forecasts gives the bagged forecasts of the original data. The whole procedure can be handled with the baggedETS() function. By default, 100 bootstrapped series are used, and the length of the blocks used for obtaining bootstrapped residuals is set to 24 for monthly data. The resulting forecasts are shown in Figure 11.19.
etsfc <- debitcards |>ets() |>forecast(h =36)baggedfc <- debitcards |>baggedETS() |>forecast(h =36)autoplot(debitcards) +autolayer(baggedfc, series ="BaggedETS", PI =FALSE) +autolayer(etsfc, series ="ETS", PI =FALSE) +guides(colour =guide_legend(title ="Forecasts"))
Figure 11.19: Comparing bagged ETS forecasts (the average of 100 bootstrapped forecast) and ETS applied directly to the data.
In this case, it makes little difference. Bergmeir et al. (2016) show that, on average, bagging gives better forecasts than just applying ets() directly. Of course, it is slower because a lot more computation is required.
11.5 Exercises
Use the tbats() function to model your retail time series.
Check the residuals and produce forecasts.
Does this completely automated approach work for these data?
Have you saved any degrees of freedom by using Fourier terms rather than seasonal differencing?
Consider the weekly data on US finished motor gasoline products supplied (millions of barrels per day) (series gasoline):
Fit a TBATS model to these data.
Check the residuals and produce forecasts.
Could you model these data using any of the other methods we have considered in this book?
Experiment with using nnetar() on your retail data and other data we have considered in previous chapters.
11.6 Further reading
De Livera et al. (2011) introduced the TBATS model and discuss the problem of complex seasonality in general.
Pfaff (2008) provides a book-length overview of VAR modelling and other multivariate time series models.
Neural networks for individual time series have not tended to produce good forecasts. Crone et al. (2011) discuss this issue in the context of a forecasting competition.
Bootstrapping for time series is discussed in Lahiri (2003).
Bagging for time series forecasting is relatively new. Bergmeir et al. (2016) is one of the few papers which addresses this topic.
Athanasopoulos, G, Poskitt, DS, & Vahid, F. (2012). Two canonical VARMA forms: Scalar component models vis-à-vis the echelon form. Econometric Reviews, 31(1), 60–83.
Bergmeir, C, Hyndman, RJ, & Benítez, JM. (2016). Bagging exponential smoothing methods using STL decomposition and Box-Cox transformation. International Journal of Forecasting, 32(2), 303–312.
Crone, SF, Hibon, M, & Nikolopoulos, K. (2011). Advances in forecasting with neural networks? Empirical evidence from the NN3 competition on time series prediction. International Journal of Forecasting, 27(3), 635–660.
De Livera, AM, Hyndman, RJ, & Snyder, RD. (2011). Forecasting time series with complex seasonal patterns using exponential smoothing. J American Statistical Association, 106(496), 1513–1527.
Fan, S, & Hyndman, RJ. (2012). Short-term load forecasting based on a semi-parametric additive model. IEEE Transactions on Power Systems, 27(1), 134–141.
Hamilton, JD. (1994). Time series analysis. Princeton University Press, Princeton.
Hyndman, RJ, & Fan, S. (2010). Density forecasting for long-term peak electricity demand. IEEE Transactions on Power Systems, 25(2), 1142–1153.
Hyndman, RJ, Koehler, AB, Snyder, RD, & Grose, S. (2002). A state space framework for automatic forecasting using exponential smoothing methods. International Journal of Forecasting, 18(3), 439–454.
Lahiri, SN. (2003). Resampling methods for dependent data. Springer Science & Business Media.
Lütkepohl, H. (2005). New introduction to multiple time series analysis. Springer-Verlag.
Lütkepohl, H. (2007). General-to-specific or specific-to-general modelling? An opinion on current econometric terminology. Journal of Econometrics, 136(1), 234–319.
Pfaff, B. (2008). Analysis of integrated and cointegrated time series with R. Springer Science & Business Media.
A more flexible generalisation would be a Vector ARMA process. However, the relative simplicity of VARs has led to their dominance in forecasting. Interested readers may refer to Athanasopoulos et al. (2012).↩︎
Interested readers should refer to Hamilton (1994) and Lütkepohl (2007).↩︎
For a detailed comparison of these criteria, see Chapter 4.3 of Lütkepohl (2005).↩︎
The tests for serial correlation in the “vars” package are multivariate generalisations of the tests presented in Section 3.3.↩︎