autocorr - Plot or return computed sample autocorrelation function

Syntax

autocorr(Series,nLags,M,nSTDs)
[ACF,Lags,Bounds] = autocorr(Series,nLags,M,nSTDs)

Description

Input Arguments

Series

Column vector of observations of a univariate time series for which autocorr computes or plots the sample autocorrelation function (ACF). The last row of Series contains the most recent observation of the time series.

nLags

Positive scalar integer indicating the number of lags of the ACF to compute. If nLags = [] or is unspecified, the default is to compute the ACF at lags 0, 1, 2, ..., T, where T = min([20,length(Series)-1]).

M

Nonnegative integer scalar indicating the number of lags beyond which the theoretical ACF is effectively 0. autocorr assumes the underlying Series is an MA(M) process, and uses Bartlett's approximation to compute the large-lag standard error for lags greater than M. If M = [] or is unspecified, the default is 0, and autocorr assumes that Series is Gaussian white noise. If Series is a Gaussian white noise process of length N, the standard error is approximately . M must be less than nLags.

nSTDs

Positive scalar indicating the number of standard deviations of the sample ACF estimation error to compute. autocorr assumes the theoretical ACF of Series is 0 beyond lag M. When M = 0 and Series is a Gaussian white noise process of length N, specifying nSTDs results in confidence bounds at . If nSTDs = [] or is unspecified, the default is 2 (that is, approximate 95 percent confidence interval).

Output Arguments

ACF

Sample autocorrelation function of Series. ACF is a vector of length nLags+1 corresponding to lags 0, 1, 2, ..., nLags. The first element of ACF is unity, that is, ACF(1) = 1 = lag 0 correlation.

Lags

Vector of lags corresponding to ACF(0,1,2,...,nLags). Since an ACF is symmetric about 0 lag, autocorr ignores negative lags.

Bounds

Two-element vector indicating the approximate upper and lower confidence bounds, assuming that Series is an MA(M) process. Values of ACF beyond lag M that are effectively 0 lie within these bounds. autocorr computes Bounds only for lags greater than M.

Examples

Example 1

Create an MA(2) time series from a column vector of 1000 Gaussian deviates. Then, assess whether the ACF is effectively zero for lags greater than 2:

randn('state', 0)             % Start from a known state.
x = randn(1000, 1);           % 1000 Gaussian deviates ~ N(0, 1).
y = filter([1 -1 1], 1, x);   % Create an MA(2) process.

% Compute the ACF with 95 percent confidence.
[ACF, Lags, Bounds] = autocorr(y, [], 2);  
[Lags, ACF]
ans =
         0    1.0000
    1.0000   -0.6487
    2.0000    0.3001
    3.0000    0.0229
    4.0000    0.0196
    5.0000   -0.0489
    6.0000    0.0452
    7.0000    0.0012
    8.0000   -0.0214
    9.0000    0.0235
   10.0000    0.0340
   11.0000   -0.0392
   12.0000    0.0188
   13.0000    0.0504
   14.0000   -0.0600
   15.0000    0.0251
   16.0000    0.0441
   17.0000   -0.0732
   18.0000    0.0755
   19.0000   -0.0571
   20.0000    0.0485

Bounds

Bounds =
    0.0899
   -0.0899

autocorr(y, [], 2)    % Use the same example, but plot the ACF
                      % sequence with confidence bounds.

Example 2

Although various estimates of the sample autocorrelation function exist, the form adopted here follows that of Box, Jenkins, and Reinsel, specifically:

(13-1)

(13-2)

The autocorr function computes the sample ACF by removing the sample mean of the input Series, then normalizing the sequence such that the ACF at lag zero is unity. In certain applications, it is useful to rescale the resulting normalized ACF by the sample variance. In this case, the correct scale factor to use is var(Series,1).

The following commands simulate 1000 standard Gaussian random numbers, then compares the first 10 lags of the sample ACF with and without normalization:

randn('state', 0);
y = randn(1000, 1);
[ACF, Lags] = autocorr(y, 10);
[Lags  ACF  ACF*var(y,1)]
ans =
         0    1.0000    0.8893
    1.0000    0.0111    0.0099
    2.0000   -0.0230   -0.0205
    3.0000    0.0194    0.0173
    4.0000    0.0068    0.0061
    5.0000   -0.0371   -0.0330
    6.0000    0.0241    0.0215
    7.0000    0.0101    0.0090
    8.0000   -0.0011   -0.0010
    9.0000    0.0577    0.0513
   10.0000    0.0526    0.0467 

Example 3

See Example: Analysis and Estimation Using the Default Model.

See Also

crosscorr, parcorr

filter (MATLAB® function)

References

Box, G.E.P., G.M. Jenkins, and G.C. Reinsel, Time Series Analysis: Forecasting and Control, Third edition, Prentice Hall, 1994.

Hamilton, J.D., Time Series Analysis, Princeton University Press, 1994.

  


 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS