1.11 Examples of Analysis of Time SeriesWe illustrate the procedures and Mathematica functions outlined in earlier sections by considering a few examples of time series analysis. The reader should keep in mind that in each of the following examples the interpretation of the data and the model fitted are by no means unique; often there can be several equally valid interpretations consistent with the data. No package can be a substitute for experience and good judgment. Example 11.1 The file csp.dat contains the common stock prices from 1871 to 1970. We read in the data using ReadList. We load the package first. As we have emphasized earlier, the first thing to do in analyzing a time series is to look at its time plot. Here is a plot of the data. | Out[3]= |  |
We see that the series rises sharply with time, clearly signaling the nonstationary nature of the series, and indicating the need to transform the data to make it stationary. Here is the time plot of the series after the logarithmic transformation. This plots the transformed data. | Out[4]= |  |
The variability in the series has been reduced. However, a rising trend still persists. We difference the series to obtain a constant mean series. data contains the differenced series. This is the plot of data. | Out[6]= |  |
Now that the mean appears steady, we assume the series has a constant mean (the reader is encouraged to devise tests to check this) and evaluate it. | Out[7]= |  |
We subtract this sample mean from the series to make it a zero-mean series. The data are transformed to a zero-mean series. The length of the data is n. | Out[9]= |  |
Now we can fit data to a stationary time series model. In order to select an appropriate model, we first look at its correlation and partial correlation functions. This gives the sample correlation function. To plot the correlation function, we redefine the function plotcorr here. This is the correlation plot. | Out[12]= |  |
Here the sample partial correlation function is plotted. | Out[13]= |  |
We see that both the correlation and partial correlation functions decay quickly to small values. This indicates that the series can be fitted to models of relatively low order. We use the Hannan-Rissanen procedure to select models and get preliminary estimates. These are five models selected by the Hannan-Rissanen procedure. | Out[14]= |  |
These selected models with their estimated parameters are used as input to the function that performs the conditional maximum likelihood estimate. The five models are further estimated using the conditional maximum likelihood method. | Out[15]= |  |
We obtain the AIC values for the five models, AR(1), MA(1), AR(2), MA(2), and ARMA(2, 1), specified above. This gives the AIC values. | Out[16]= |  |
We see that the lowest AIC values correspond to MA(1) and MA(2) models. We choose these two models for further exploration using the maximum likelihood method. This gives the maximum likelihood estimate of the MA(1) model. | Out[17]= |  |
This is the AIC value of the MA(1) model. | Out[18]= |  |
This gives the maximum likelihood estimate of the MA(2) model. | Out[19]= |  |
This is the AIC value of the MA(2) model. | Out[20]= |  |
Again MA(1) is superior according to the AIC criterion. Note that in this particular example, the estimated parameters using the maximum likelihood method are very close to those obtained using the conditional maximum likelihood method. We now tentatively choose MA(1) as our model and proceed to check its adequacy.
From ( 5.6) the variance of the sample correlation for an MA(1) model for lags k>1 can be calculated. This calculates the variance of the sample correlation. | Out[21]= |  |
| Out[22]= |  |
The sample correlation function shown above is within this bound with the exception of  . So the behavior of the sample correlation function obtained from the data is consistent with the MA(1) model. Next we calculate the residuals and see if they form a white noise process. The residuals are calculated first. The residual correlation function is displayed along with the bounds. | Out[24]= |  |
We see that the correlation function of the residuals resembles that of a white noise. The portmanteau test also confirms the adequacy of the MA(1) model. This gives the portmanteau statistic Qh with h=20. | Out[25]= |  |
The model passes the test. | Out[26]= |  |
So we finally arrive at the model (1-B)lnXt=0.029+Zt+0.31Zt-1 where the noise {Zt} has a variance 0.024.
We can get the standard error of  by calculating the asymptotic variance of the estimator. Here is the asymptotic variance of  . | Out[27]= |  |
This is the standard error of  . | Out[28]= |  |
The disadvantage of choosing an MA(1) model is that it cannot account for the relatively large value of the sample correlation at lag 5. To account for the large  a higher-order model is needed. For example, the AR(5) model obtained from the maximum likelihood estimate (with 3 fixed to be 0) ARModel[{0.223396, -0.209017, 0, -0.147311, -0.171337}, 0.0219622] produces a correlation function that better resembles the sample correlation function. It also has a slightly lower AIC value than the MA(1) model. Example 11.2 The file unemp.dat contains the U.S. monthly unemployment figures in thousands from 1948 to 1981 for men of ages between 16 and 19. Here is a plot of the data. | Out[30]= |  |
We plot the sample correlation function. | Out[31]= |  |
The clear periodic structure in the time plot of the data is reflected in the correlation plot. The pronounced peaks at lags that are multiples of 12 indicate that the series has a seasonal period s=12. We also observe that the correlation function decreases rather slowly to zero both for  ( k=1, 2, ... ) and for  ( k is not a multiple of 12). This suggests that the series may be nonstationary and both seasonal and regular differencing may be required. We first transform the series by differencing. This is the plot of the sample correlation function of the transformed series. | Out[33]= |  |
This is the plot of the sample partial correlation function of the transformed series. | Out[34]= |  |
The single prominent dip in the correlation function at lag 12 shows that the seasonal component probably only persists in the MA part and Q=1. This is also consistent with the behavior of the partial correlation function that has dips at lags that are multiples of the seasonal period 12. The correlation plot also suggests that the orders of the regular AR and MA parts are small since  is prominent only at k=1. Based on these observations, we consider the models with P=0, Q=1 and p≤1, q≤1 and the reader is encouraged to try higher-order models. We will estimate the parameters of these models using the conditional maximum likelihood method. Specifically, we consider the following three models. This defines the three models. The initial values -0.3 and -0.5 for the parameters are guessed from looking at the sample correlation and partial correlation functions. For an AR(1) or MA(1) model, (1) is proportional to 1 or 1. So we pick our initial value for 1 or 1 to be  . For the partial correlation function of an MA(1) model we have k+1, k+1/ k, k - 1 (see Example 2.11). From our sample partial correlation function, we see that  , so we choose the initial value of 1 to be -0.5. Before estimating the parameters we first make sure that the mean value of the series is zero. This gives the sample mean of the data. | Out[36]= |  |
The mean is subtracted from the data. n is the length of the data. | Out[38]= |  |
This gives the conditional maximum likelihood estimate of the three models. | Out[39]= |  |
These are the AIC values of the models. | Out[40]= |  |
We drop the first model because it has a higher AIC value. We use the exact maximum likelihood method to get better estimates for the parameters of the second and third models. This gives the maximum likelihood estimate of the second model. | Out[41]= |  |
This is the AIC value of the model. | Out[42]= |  |
Here is the maximum likelihood estimate of the third model. | Out[43]= |  |
We obtain the AIC value of this model. | Out[44]= |  |
So the second model, SARIMA( 0, 1, 1)( 0, 1, 1) 12, is marginally superior and we choose it to be our model. We check to see if the model is invertible. | Out[45]= |  |
To test the adequacy of the model we first calculate the residuals. This plots the sample correlation function of the residuals. | Out[47]= |  |
We see that the residual correlation is within the rough bound  . Even though the asymptotic standard deviations of residual correlations can be smaller than  for small lags, our residual correlations for small lags are much smaller than the rough bound 0.1. This gives the portmanteau statistic Q40. | Out[48]= |  |
The model passes the portmanteau test. | Out[49]= |  |
So we conclude that our model is (1-B)(1-B12)Xt=0.2835+(1-0.326B)(1-0.663B12)Zt where the white noise {Zt} has variance 2306.8.
To estimate the standard errors of the estimated parameters we invert the estimated information matrix. This gives the inverse of the information matrix. | Out[50]= |  |
The standard errors are calculated from the diagonal elements. | Out[51]= |  |
The standard errors are about 0.05 for  and 0.04 for  .
To forecast the future values we first get the predictors for the differenced, zero-mean series data. This gives the predicted values for data. We have used the option Exact -> False since n is large and hence it makes little difference in the predicted values. To get the predicted values for the original series we use the function IntegratedPredictor. This gives the predicted values for the original series. | Out[53]= |  |
The mean square errors of the prediction are obtained by using the original series and the full model. In this case the full model is obtained by replacing the differencing orders {0, 0 } in mamodel (see Out[44]) by {1, 1 }. These are the mean square errors of the prediction. | Out[54]= |  |
Here we display the next 15 values of the series predicted from the estimated SARIMA model along with the last 40 observed data points. | Out[55]= |  |
We can also define a function, say, plotdata, to plot the data and the predicted values together. plotdata takes the data and the predicted values and plots them together. Example 11.3 In this example, we model the celebrated data recorded for the number of lynx trapped annually in northwest Canada from 1821 to 1934. The series has been analyzed by various authors and researchers and a survey of the work can be found in Campbell and Walker (1977). The lynx data are contained in the file lynx.dat and we first read in the data and plot them. We plot the number of lynx trapped against time. Note that the time scale is such that t=1 corresponds to the year 1821. See Example 4.2. | Out[58]= |  |
We can see that the series oscillates with an approximate period of 10. In order to make the variance more uniform, we first take the logarithm (base 10) of the data and subtract out the mean. n is the length of the data. | Out[59]= |  |
We obtain the sample mean. | Out[60]= |  |
The series is transformed to a zero-mean one. This is the plot of the transformed data. | Out[62]= |  |
Compared with the original plot the time plot now looks more symmetric. We proceed to calculate and plot the correlation and partial correlation functions. This is the plot of the sample correlation function. | Out[63]= |  |
This is the plot of the sample partial correlation function. | Out[64]= |  |
We notice that, like the time series itself, the correlation function oscillates with an approximate cycle of period 10. Also the slowly decaying behavior of the correlation signals that the series may be nonstationary or the AR polynomial (x) has zeros very close to the unit circle. As a preliminary estimate we use the Hannan-Rissanen method to select possible models. Since the period here is close to 10 we will use the long AR order and the maximum AR and MA orders greater than 10. Hannan-Rissanen method is used to select models. These are the AIC values of the models. | Out[66]= |  |
There are two models that have much lower AIC values than the rest. We pick out the models with AIC value less than -3.15. They are models 12 and 30. | Out[67]= |  |
This gives the two models. | Out[68]= |  |
They correspond to ARMA( 11, 1) and ARMA( 11, 2). | Out[69]= |  |
We further estimate the model parameters using the conditional maximum likelihood method. Note that the above models are used as the input to the function ConditionalMLEstimate. This gives the conditional maximum likelihood estimate. | Out[70]= |  |
| Out[71]= |  |
We can also try to estimate some nearby models to see if they give a lower AIC value. For example, we can try AR(12), ARMA( 10, 1), etc. It turns out that AR(12) has a lower AIC value. The reader can show that AR(13) and ARMA( 10, 1) yield higher AIC values than AR(12). This gives the estimate of AR(12) model. | Out[72]= |  |
| Out[73]= |  |
The correlation and the partial correlation function of the AR(12) model resemble those obtained from data1 (see earlier plots). This is the plot of the correlation function of the AR(12) model. | Out[74]= |  |
This is the plot of the partial correlation function of the AR(12) model. | Out[75]= |  |
To test the adequacy of the model we first calculate the residuals and their correlation function. The residuals are calculated first. This is the plot of the sample correlation function of the residuals. | Out[77]= |  |
The correlation function of the residuals is well within the bound of  . This is the portmanteau statistic for h=25. | Out[78]= |  |
So the AR(12) model passes the test. | Out[79]= |  |
To get the standard errors of the estimated parameters we first get their asymptotic covariance matrix. This can be done either by inverting the information matrix or using the function AsymptoticCovariance. Here we use the latter method. The asymptotic covariance matrix is calculated. This gives the standard errors. | Out[81]= |  |
We put the estimated parameters together with their standard errors using TableForm. | Out[82]//TableForm= |  |
So we can safely regard 5, 6, 7, 8, and 10 to be zero. However we will use the model ar12 to forecast the future values. This yields the forecast and mean square forecast errors for the number of lynx trappings for the next 15 years. | Out[83]= |  |
We plot the logarithm of the lynx data along with the next 15 predicted values. | Out[84]= |  |
Example 11.4 The file salesad.dat contains the Lydia E. Pinkham annual sales ( {xt1}) and advertising expenditure ( {xt2}) data. They have the following time plots. n is the length of the data. | Out[86]= |  |
Here is the time plot of series 1. | Out[87]= |  |
Here is the time plot of series 2. | Out[88]= |  |
Since we do not see a convincing systematic trend, we transform the series to zero-mean by simply subtracting the sample mean of the series. | Out[89]= |  |
We use the Hannan-Rissanen procedure to select preliminary models. This allows us to see the orders of each selected model. | Out[92]= |  |
This gives their AIC values. | Out[93]= |  |
Since the second (AR(3)) and third (ARMA( 2, 1)) models have the smallest AIC values, we choose them to be our preliminary models. The conditional maximum likelihood method gives the following parameter estimates. This gives the conditional maximum likelihood estimate. | Out[94]= |  |
In fact, it is unnecessary to further estimate the parameters of AR(3) model as we have done above, since the Hannan-Rissanen method and the conditional maximum likelihood method give identical parameter estimates for an AR( p) model. The reader should convince himself/herself of this. This gives the AIC values. | Out[95]= |  |
Since AR(2, 1) model has a lower AIC value, we choose it as our model and plot the residual correlation functions and cross-correlation function. This gives the residuals. This calculates the correlation function of the residuals. Here is the plot of the residual correlation function for series 1. | Out[98]= |  |
Here is the plot of the residual correlation function for series 2. | Out[99]= |  |
This is the plot of the residual cross-correlation function. | Out[100]= |  |
The residual correlation functions resemble those of white noise (since  ). The model also passes the portmanteau test. | Out[101]= |  |
The model passes the test. | Out[102]= |  |
This calculates the inverse of the information matrix. Here are the standard errors of estimated parameters. | Out[104]= |  |
These are the standard errors of {( 1)11, ( 1)12, ( 1)21, ... , ( 1)22}. We can display the estimated parameters and their standard errors together using TableForm. The parameters are displayed along with their standard errors. | Out[105]//TableForm= |  |
Again we can set several elements of the parameter matrices to zero. We find the forecast values for the next 15 time steps. This gives the predicted values. The mean is added to the prediction. This plots series 1 and the next 15 predicted values. | Out[108]= |  |
This plots series 2 and the next 15 predicted values. | Out[109]= |  |
|