IMSL_AUTOCORRELATION

Syntax | Return Value | Arguments | Keywords | Discussion | Example | Version History

The IMSL_AUTOCORRELATION function computes the sample autocorrelation function of a stationary time series.

Note
This routine requires an IDL Advanced Math and Stats license. For more information, contact your ITT Visual Information Solutions sales or technical support representative.

Syntax

Result = IMSL_AUTOCORRELATION(x, lagmax [, ACV=variable] [ /DOUBLE] [, SE_OPTION=value] [, SEAC=variable] [, XMEAN_IN=value] [, XMEAN_OUT=variable])

Return Value

One-dimensional array of length lagmax + 1 containing the auto-correlations of the time series x. The 0-th element of this array is 1. The k-th element of this array contains the autocorrelation of lag k where k = 1, ..., lagmax.

Arguments

lagmax

Scalar integer containing the maximum lag of autocovariance, auto-correlations, and standard errors of auto-correlations to be computed. lagmax must be greater than or equal to 1 and less than N_ELEMENTS(x).

x

One-dimensional array containing the time series. N_ELEMENTS(x) must be greater than or equal to 2.

Keywords

ACV

Named variable into which an array of length lagmax + 1 containing the variance and auto-covariances of the time series x is stored. The 0-th element of this array is the variance of the time series x. The k-th element contains the autocovariance of lag k where k = 1, ..., lagmax.

DOUBLE

If present and nonzero, double precision is used.

SE_OPTION

Method of computation for standard errors of the auto-correlations. Keywords Se_Option and Seac must be used together.

SEAC

Named variable into which an array of length lagmax containing the standard errors of the auto-correlations of the time series x is stored. Keywords Seac and Se_Option must be used together.

XMEAN_IN

The estimate of the mean of the time series x.

XMEAN_OUT

Named variable into which the estimate of the mean of the time series x is stored.

Discussion

The IMSL_AUTOCORRELATION function estimates the autocorrelation function of a stationary time series given a sample of n = N_ELEMENTS(x) observations {Xt} for t = 1, 2, ..., n.

Let:

IMSL_AUTOCORRELATION-076.jpg

be the estimate of the mean μ of the time series {Xt} where:

IMSL_AUTOCORRELATION-077.jpg

The autocovariance function σ(k) is estimated by:

IMSL_AUTOCORRELATION-078.jpg

where K = lagmax. Note that:

IMSL_AUTOCORRELATION-079.jpg

is an estimate of the sample variance. The autocorrelation function ρ(k) is estimated by:

IMSL_AUTOCORRELATION-080.jpg

Note that:

IMSL_AUTOCORRELATION-081.jpg

by definition.

The standard errors of the sample auto-correlations may be optionally computed according to the keyword Se_Option for the output keyword Seac. One method (Bartlett 1946) is based on a general asymptotic expression for the variance of the sample autocorrelation coefficient of a stationary time series with independent, identically distributed normal errors. The theoretical formula is:

IMSL_AUTOCORRELATION-082.jpg

where:

IMSL_AUTOCORRELATION-083.jpg

assumes μ is unknown. For computational purposes, the auto-correlations ρ(k) are replaced by their estimates:

IMSL_AUTOCORRELATION-084.jpg

for |k| ≤ K, and the limits of summation are bounded because of the assumption that ρ(k) = 0 for all k such that |k| > K.

A second method (Moran 1947) utilizes an exact formula for the variance of the sample autocorrelation coefficient of a random process with independent, identically distributed normal errors. The theoretical formula is:

IMSL_AUTOCORRELATION-085.jpg

where μ is assumed to be equal to zero. Note that this formula does not depend on the autocorrelation function.

Example

Consider the Wolfer Sunspot Data (Anderson 1971, page 660) consisting of the number of sunspots observed each year from 1749 through 1924. The data set for this example consists of the number of sunspots observed from 1770 through 1869. The IMSL_AUTOCORRELATION function computes the estimated auto-covariances, estimated auto-correlations, and estimated standard errors of the auto-correlations.

.RUN 
PRO print_results, xm, acv, result, seac 
   PRINT, 'Mean =', xm 
   PRINT, 'Variance =', acv(0) 
   PRINT, '      Lag       ACV          AC         SEAC' 
   PRINT, '       0', acv(0), result(0) 
   FOR j  =  1, 20 DO $ 
      PRINT, j, acv(j), result(j), seac(j - 1) 
END 
 
lagmax = 20 
data = IMSL_STATDATA(2) 
x = data(21:120,1) 
result = IMSL_AUTOCORRELATION(x, lagmax, ACV = acv, $ 
   SE_OPTION = 1, SEAC = seac, XMEAN_OUT = xm) 
print_results, xm, acv, result, seac 
 
Mean =      46.9760 
Variance =      1382.91 
   Lag       ACV          AC         SEAC 
   0      1382.91      1.00000 
   1      1115.03     0.806293    0.0347834 
   2      592.004     0.428087    0.0962420 
   3      95.2974    0.0689109     0.156783 
   4     -235.952    -0.170620     0.205767 
   5     -370.011    -0.267560     0.230956 
   6     -294.255    -0.212780     0.228995 
   7     -60.4423   -0.0437067     0.208622 
   8      227.633     0.164604     0.178476 
   9      458.381     0.331462     0.145727 
   10      567.841     0.410613     0.134406 
   11      546.122     0.394908     0.150676 
   12      398.937     0.288477     0.174348 
   13      197.757     0.143001     0.190619 
   14      26.8911    0.0194453     0.195490 
   15     -77.2807   -0.0558828     0.195893 
   16     -143.733    -0.103935     0.196285 
   17     -202.048    -0.146104     0.196021 
   18     -245.372    -0.177432     0.198716 
   19     -230.816    -0.166906     0.205359 
   20     -142.879    -0.103318     0.209387 

Version History

6.4

Introduced