IMSL_AUTOCORRELATION

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

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

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:

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

The autocovariance function σ(k) is estimated by:

where K = lagmax. Note that:

σ(0)

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

Note that:

ρ(0) = 1

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:

where:

ρ(k)

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

ρ(k)

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:

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

IDL prints:

Mean = 46.9760

Variance = 1382.91

Lag      ACV          AC         SEAC

0      1382.91      1.00000

1      1115.03     0.806293   0.0347834

20     592.004     0.428087   0.0962420

30     95.2974    0.0689109    0.156783

40    -235.952    -0.170620    0.205767

50    -370.011    -0.267560    0.230956

60    -294.255    -0.212780    0.228995

70    -60.4423   -0.0437067    0.208622

80     227.633     0.164604    0.178476

90     458.381     0.331462    0.145727

100    567.841     0.410613    0.134406

110    546.122     0.394908    0.150676

120    398.937     0.288477    0.174348

130    197.757     0.143001    0.190619

140    26.8911    0.0194453    0.195490

150   -77.2807   -0.0558828    0.195893

160   -143.733    -0.103935    0.196285

170    202.048    -0.146104    0.196021

180   -245.372    -0.177432    0.198716

190   -230.816    -0.166906    0.205359

200   -142.879    -0.103318    0.209387

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 (optional)

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 (optional)

If present and nonzero, then double precision is used.

SE_OPTION (optional)

Method of computation for standard errors of the auto-correlations. The keywords SE_OPTION and SEAC must be used together.

SEAC (optional)

Named variable into which an array of length Lagmax containing the standard errors of the auto-correlations of the time series X is stored. The keywords SE_OPTION and SEAC must be used together.

XMEAN_IN (optional)

The estimate of the mean of the time series X.

XMEAN_OUT (optional)

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

Version History

6.4

Introduced