ARIMA and Seasonal ARIMA Models
This tutorial delves a bit deeper into statistical models. Study it to better understand the ARIMA and seasonal ARIMA models. Consider closely the discussion of how to apply the ACF and PACF to estimate the order parameters for a given model. In practical circumstances, this is an important question as it is often the case that such parameters would initially be unknown.
Identifying and Estimating ARIMA Models; Using ARIMA Models to Forecast Future Values
Forecasting with ARIMA Models
Section 3.4 in the textbook gives a theoretical look at forecasting with ARIMA models. That presentation is a bit tough, but in practice, it's easy to understand how forecasts are created.
In an ARIMA model, we express as a function of past value(s) of x and/or past errors (as well as a present time error). When we forecast a value past the end of the series, we might need values from the observed series on the right side of the equation, or we might, in theory, need values that aren't yet observed.
Example 3-4
Consider the AR(2) model . In this model, is a linear function of the values of x at the previous two times. Suppose that we have observed n data values and wish to use the observed data and estimated AR(2) model to forecast the value of and , the values of the series at the next two times past the end of the series. The equations for these two values are
To use the first of these equations, we simply use the observed values of and and replace by its expected value of 0 (the assumed mean for the errors).
The second equation for forecasting the value at time n + 2 presents a problem. It requires the unobserved value of (one time past the end of the series). The solution is to use the forecasted value of (the result of the first equation).
In general, the forecasting procedure, assuming a sample size of n, is as follows:
Notation
Our authors use the notation to represent a forecast m times past the end of the observed series. The "superscript" is to be read as "given data up to time n". Other authors use the notation to denote a forecast m times past time n.
To understand the formula for the standard error of the forecast error, we first need to define the concept of psi-weights.
Psi-weight representation of an ARIMA model
Any ARIMA model can be converted to an infinite order MA model:
\begin{align} x_t - \mu & = w_t + \Psi_1w_{t-1} + \Psi_2w_{t-2} + \dots + \Psi_kw_{t-k} + \dots \\ & = \sum_{j=0}^{\infty}\Psi_jw_{t-j} \text{ where} \Psi_0 \equiv 1 \end{align}
An important constraint so that the model doesn't "explode" as we go back in time is
The process of finding the "psi-weight" representation can involve a few algebraic tricks. Fortunately, R has a routine, ARMAtoMA, that will do it for us. To illustrate how psi-weights may be determined algebraically, we'll consider a simple example.
Example 3-5
Suppose that an AR(1) model is
For an AR(1) model, the mean so in this case, . We'll define and rewrite the model as . (You can do the algebra to check that things match between the two expressions of the model.)
To find the psi-weight expression, we'll continually substitute for the z on the right side in order to make the expression become one that only involves w values.
Substitute the right side of the second expression for _{ }in the first expression.
This gives
Substituting this into the equation gives
If you keep going, you'll soon see that the pattern leads to
Thus the psi-weights for this model are given by for .
In R, the command ARMAtoMA(ar = .6, ma=0, 12) gives the first 12 psi-weights. This will give the psi-weights _{ }to in scientific notation.
For the AR(1) with AR coefficient = 0.6, they are:
[1] 0.600000000 0.360000000 0.216000000 0.129600000 0.077760000 0.046656000
[7] 0.027993600 0.016796160 0.010077696 0.006046618 0.003627971 0.002176782
Remember that . R doesn't give this value. Its listing starts with , which equals 0.6 in this case.
MA Models: The psi-weights are easy for an MA model because the model is already written in terms of errors. The psi-weights = 0 for lags past the order of the MA model and equal the coefficient values for lags of the errors that are in the model. Remember that we always have .
Standard error of the forecast error for a forecast using an ARIMA model
Without proof, we'll state a result:
The variance of the difference between the forecasted value at time n + m and the (unobserved) value at time n + m is
Thus the estimated standard deviation of the forecast error at time n + m is
The summation of squared psi-weights begins with , and the summation goes to m – 1, one less than the number of times ahead for which we're forecasting.
When forecasting m = 1 time past the end of the series, the standard error of the forecast error is
When forecasting the value m = 2 times past the end of the series, the standard error of the forecast error is
Notice that the variance will not be too big when m = 1. But, as you predict out farther in the future, the variance will increase. When m is very large, we will get the total variance. In other words, if you are trying to predict very far out, we will get the variance of the entire time series, as if you haven't even looked at what was going on previously.
With the assumption of normally distributed errors, a 95% prediction interval for , the future value of the series at time n + m, is
Example 3-6
Suppose that an AR(1) model is estimated to be . This is the same model used earlier in this handout, so the psi-weights we got there apply.
Suppose that we have n = 100 observations, and . We wish to forecast the values at times 101 and 102 and create prediction intervals for both forecasts.
First, we forecast time 101.
The standard error of the forecast error at time 101 is
The 95% prediction interval for the value at time 101 is 88 ± 2(1.96), which is 84.08 to 91.96. We are, therefore, 95% confident that the observation at time 101 will be between 84.08 and 91.96. If we repeated this exact process many times, then 95% of the computed prediction intervals would contain the true value of x at time 101.
The forecast for time 102 is
We used the forecasted value for time 101 in the AR(1) equation.
The relevant standard error is
A 95% prediction interval for the value at time 102 is 92.8 ± (1.96)(2.332).
To forecast using an ARIMA model in R, we recommend our textbook author's script called sarima.for. (It is part of the astsa library recommended previously).
Example 3-7
In the homework for Lesson 2, problem 5 asked you to suggest a model for a time series of stride lengths measured every 30 seconds for a runner on a treadmill.
From R, the estimated coefficients for an AR(2) model and the estimated variance are as follows for a similar data set with n = 90 observations:
Coefficients:
ar1 | ar2 | xmean | |
---|---|---|---|
1.1480 | -0.3359 | 48.7476 | |
s.e. | 0.1009 | 0.1087 | 1.8855 |
sigma^2 estimated as 11.47
The command
sarima.for(stridelength, 6, 2, 0, 0) # 6 forecasts with an AR(2) model for stridelength
will give forecasts and standard errors of prediction errors for the next six times past the end of the series. Here's the output (slightly edited to fit here):
\$pred
Time Series:
Start = 91
End = 96
[1] 69.78674 64.75441 60.05661 56.35385 53.68102 51.85633
\$se
Time Series:
Start = 91
End = 96
[1] 3.386615 5.155988 6.135493 6.629810 6.861170 6.962654
The forecasts are given in the first batch of values under \$pred, and the standard errors of the forecast errors are given in the last line in the batch of results under \$se.
The procedure also gave this graph, which shows the series followed by the forecasts as a red line and the upper and lower prediction limits as blue dashed lines:
Psi-Weights for the Estimated AR(2) for the Stride Length Data
If we wanted to verify the standard error calculations for the six forecasts past the end of the series, we would need to know the psi-weights. To get them, we need to supply the estimated AR coefficients for the AR(2) model to the ARMAtoMA command.
The R command in this case is ARMAtoMA(ar = list(1.148, -0.3359), ma = 0, 5)
This will give the psi-weights to in scientific notation. The answer provided by R is:
[1] 1.148000e+00 9.820040e-01 7.417274e-01 5.216479e-01 3.497056e-01
The output for estimating the AR(2) included this estimate of the error variance:
sigma^2 estimated as 11.47
As an example, the standard error of the forecast error for 3 times past the end of the series is
which, except for the round-off error, matches the value of 6.135493 given as the third standard error in the sarima.for output above.
Where will the Forecasts End Up?
For a stationary series and model, the forecasts of future values will eventually converge to the mean and then stay there. Note below what happened with the stride length forecasts when we asked for 30 forecasts past the end of the series. [Command was sarima.for (stridelength, 30, 2, 0, 0)]. The forecast got to 48.74753 and then stayed there.
\$pred
Time Series:
Start = 91
End = 120
[1] 69.78674 64.75441 60.05661 56.35385 53.68102 51.85633 50.65935 49.89811
[9] 49.42626 49.14026 48.97043 48.87153 48.81503 48.78339 48.76604 48.75676
[17] 48.75192 48.74949 48.74833 48.74780 48.74760 48.74753 48.74753 48.74755
[25] 48.74757 48.74759 48.74760 48.74761 48.74762 48.74762
The graph showing the series and the six prediction intervals is the following