EC 485: Time Series Analysis in A Nut Shell
EC 485: Time Series Analysis in A Nut Shell
Forecasting:
1) Use the best model to construct forecasts
2) Graph your forecasts against actual values
3) Calculate the Mean Squared Error for the forecasts
Data Preparation: #3
1) Plot data and examine. Do a visual inspection to determine if your series is non-
stationary.
2) Examine Autocorrelation Function (ACF) for stationarity. The ACF for a non-
stationary series will show large autocorrelations that diminish only very slowly at
large lags. (At this stage you can ignore the partial autocorrelations and you can
always ignore what SAS calls the inverse autocorrelations.
3) If not stationary, take first differences. SAS will do this automatically in the
IDENTIFY VAR=y(1) statement where the variable to be “identified” is y and the 1
refers to first-differencing.
5) Examine the ACF after these transformations to determine if the series is now
stationary
#4
In this presentation, a variable measuring the capacity utilization
for the U.S. economy is modeled. The data are monthly from
1967:1 – 2004:03.
Name of Variable = cu
Period(s) of Differencing 1
Mean of Working Series -0.03295
Standard Deviation 0.584287
Number of Observations 440 This ACF was produced in SAS
Observation(s) eliminated by differencing 1
using the code:
Autocorrelations
Lag Covariance Correlation -1 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 1
0 0.341391 1.00000 | |********************|
PROC ARIMA;
1 0.126532 0.37064 | . |******* | IDENTIFY VAR=cu(1);
2 0.093756 0.27463 | . |***** |
3 0.079004 0.23142 | . |***** |
RUN;
4 0.062319 0.18254 | . |**** |
5 0.021558 0.06315 | . |*. |
6 0.020578 0.06028 | . |*. |
where the (1) tells SAS to use
7 0.018008 0.05275 | . |*. | first differences.
8 0.029300 0.08583 | . |** |
9 0.040026 0.11724 | . |** |
10 0.020880 0.06116 | . |*. |
11 0.010021 0.02935 | . |*. |
12 -0.0071559 -.02096 | . | . |
13 -0.026090 -.07642 | **| . |
14 -0.031699 -.09285 | **| . |
15 -0.032960 -.09654 | **| . |
16 -0.023544 -.06897 | . *| . |
17 -0.021426 -.06276 | . *| . |
18 -0.0084132 -.02464 | . | . |
Lag Correlation -1 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 1
1 0.37064 | . |******* |
2 0.15912 | . |*** |
3 0.10330 | . |** |
4 0.04939 | . |*. |
5 -0.07279 | .*| . |
6 0.00433 | . | . |
7 0.01435 | . | . |
8 0.06815 | . |*. |
9 0.08346 | . |** |
10 -0.02903 | .*| . |
11 -0.03996 | .*| . |
12 -0.07539 | **| . |
13 -0.08379 | **| . |
14 -0.03419 | .*| . |
15 -0.02101 | . | . |
16 0.01950 | . | . |
17 -0.00768 | . | . |
18 0.01681 | . | . |
Model Identification and Estimation: (con’t) #12
The “q” measures the order of the moving average component. To get an
idea of what orders to consider, we examine the autocorrelation function. If
the time-series is a moving average of order 1, called a MA(1), we should
see only one significant autocorrelation coefficient at lag 1. This is because
a MA(1) process has a memory of only one period. If the time-series is a
MA(2), we should see only two significant autocorrelation coefficients, at
lag 1 and 2, because a MA(2) process has a memory of only two periods.
Generally, for a time-series that is a MA(q), the autocorrelation function
will have significant correlations up to lag q, and will quickly drop to near
zero values after lag q.
For the capacity utilization time-series, we see that the ACF function decays,
but only for the first 4 lags. Then it appears to drop off to zero abruptly.
Therefore, a MA(4) might be considered.
Our initial guess is ARIMA(2,1,4) where the 1 tells us that the data have been
first-differenced to render it stationary.
2) Estimate the Models: #13
To estimate the model in SAS is fairly straight forward. Go back to the PROC
ARIMA and add the ESTIMATE command. Here we will estimate four models:
ARIMA(1,1,0), ARIMA(1,1,1), ARIMA(2,1,0), and ARIMA(2,1,4). Although
we believe the last of these will be the best, it is instructive to estimate a simple
AR(1) on our differenced series, this is the ARIMA(1,1,0) a model with an
AR(1) and a MA(1) on the differenced series; this is the ARIMA(1,1,1), and a
model with only an AR(2) term. This is the ARIMA(2,1,0)
This tells SAS that d=1 for all models
PROC ARIMA;
IDENTIFY VAR=cu(1); This estimates an ARIMA(1,1,0)
ESTIMATE p = 1:
ESTIMATE p = 1 q=1;
This estimates ARIMA(1,1,1)
ESTIMATE p = 2;
ESTIMATE p = 2 q = 4; This estimates an ARIMA(2,1,0)
RUN;
This estimates an ARIMA(2,1,4)
#14
3) Examine the parameter estimates, the SBC statistic and test of white noise
for the residuals.
On the next few slides you will see the results of estimating the 4 models
discussed in the previous section. We are looking at the statistical
significance of the parameter estimates. We also want to compare
measures of overall fit. We will use the SBC statistic. It is based on the
sum of squared residuals from estimating the model and it balances the
reduction in degrees of freedom against the reduction in sum of squared
residuals from adding more variables (lags of the time-series). The lower
the sum of squared residuals, the better the model. SAS calculates the
SBC as:
Where k = p+q+1, the number of
parameters estimated, and T is sample
SBC 2 ln( L) K ln( T ) size. L is the likelihood measure, and essentially
depends on the sum of squared residuals. The model
with the lowest SBC measure is considered “best”.
SBC can be positive or negative.
NOTE: SAS’s formula differs slightly from the one in
the textbook.
This is the ARIMA(1,1,0) model: yt =β0 + β1 yt-1 + εt #15
Conditional Least Squares Estimation
Standard Approx
Parameter Estimate Error t Value Pr > |t| Lag
MU -0.03528 0.04115 -0.86 0.3918 0
AR1,1 0.37113 0.04440 8.36 <.0001 1
Things to notice: the parameter estimates of the AR(1) term β1 and of the
MA(1) term λ1 are statistically significant. Also, the autocorrelation check
of the residuals tells us that the residuals from this ARIMA(1,1,1) are white-
noise, since the Chi-Square statistics up to a lag of 18 have p-values greater
than 10%, meaning we cannot reject the null hypothesis that the
autocorrelations up to lag 18 are jointly zero (p-value = 0.4021). Also the
SBC statistic is smaller. So we might be done …
#17
This is the ARIMA(2,1,0) model: yt = β0 + β1 yt-1 + β2 yt-2 + εt
Conditional Least Squares Estimation
Standard Approx
Parameter Estimate Error t Value Pr > |t| Lag
MU -0.03783 0.04829 -0.78 0.4338 0
AR1,1 0.31208 0.04726 6.60 <.0001 1
AR1,2 0.15929 0.04726 3.37 0.0008 2
To Chi- Pr >
Lag Square DF ChiSq ---------------Autocorrelations---------------
Two of the parameter estimates are not statistically significant telling us the model
is not “parsimonious”, and the SBC statistic is larger than the SBC for the
ARIMA(1,1,1) model. Ignore the first Chi-Square statistic since it has 0 d.o.f. due
to estimating a model with 7 parameters. The Chi-Square statistic at 12 and 18 lags
is statistically insignificant indicating white noise.
Forecasts: #19
proc arima;
identify var=cu(1);
estimate p=1; (any model goes here)
forecast lead=6 id=date interval=month out=fore1;
We calculate the Mean Squared Error for the 6 out-of-sample forecasts. Graphs
appear on the next four slides. We find that the fourth model produces forecasts with
the smallest MSE. SAS automatically adjusts the data from first differences back into
levels.
Use the actual values for CU and the forecasted values below to generate a mean
squared prediction error for each model estimated. The formula is MSE = (1/6)*(fcu
– cu)2 where fcu is a forecast and cu is actual.
Obs date cu cu2 fcu1 sd1 fcu2 sd2 fcu3 sd3 fcu4 sd4
441 SEP03 74.9 74.9 74.4778 0.54385 74.5294 0.53486 74.5596 0.53754 74.6211 0.53359
442 OCT03 . 75.0 75.0263 0.54385 75.0215 0.53486 75.0048 0.53754 75.1540 0.53359
443 NOV03 . 75.7 75.0509 0.92295 75.1034 0.87485 75.0813 0.88678 75.3396 0.87138
444 DEC03 . 75.8 75.0379 1.23500 75.1555 1.19316 75.1018 1.22371 75.3883 1.18650
445 JAN04 . 76.2 75.0109 1.49834 75.1851 1.49534 75.1004 1.52680 75.3511 1.50072
446 FEB04 . 76.7 74.9787 1.72697 75.1976 1.78205 75.0833 1.80183 75.2766 1.81196
447 MAR04 . 76.5 74.9445 1.93039 75.1972 2.05370 75.0577 2.05184 75.2110 2.08938
#20
#21
Granger Causality (Predictability) Test
lcpi = lag(cpi);
inf = 12*100*log(cpi)-log(lcpi);
dinf = inf-lag(inf);
ldinf = lag(dinf);
l2dinf = lag2(dinf);
l3dinf = lag3(dinf);
l4dinf = lag4(dinf);
ldcu = lag(dcu);
l2dcu = lag2(dcu);
l3dcu = lag3(dcu);
l4dcu = lag4(dcu);
run;
proc autoreg data=one;
model dcu = ldcu l2dcu l3dcu l4dcu ldinf l2dinf l3dinf l4dinf ;
test ldinf=0,l2dinf=0,l3dinf=0,l4dinf=0;
run;
#22
The AUTOREG Procedure
Dependent Variable dcu
Ordinary Least Squares Estimates
Test 1
Mean
Source DF Square F Value Pr > F
Numerator 4 1.295144 4.81 0.0008
Denominator 432 0.269423