NAG Library Routine Document
G13ABF computes the sample autocorrelation function of a time series. It also computes the sample mean, the sample variance and a statistic which may be used to test the hypothesis that the true autocorrelation function is zero.
||NX, NK, IFAIL
||X(NX), XM, XV, R(NK), STAT
The data consists of observations , for from a time series.
The quantities calculated are
||The sample mean
||The sample variance (for )
||The sample autocorrelation coefficients of lags , where is a user-specified maximum lag, and , .
The coefficient of lag
is defined as
See page 496 of Box and Jenkins (1976)
for further details.
||A test statistic defined as
which can be used to test the hypothesis that the true autocorrelation function is identically zero.
is large and
is much smaller than
distribution under the hypothesis of a zero autocorrelation function. Values of STAT
in the upper tail of the distribution provide evidence against the hypothesis; G01ECF
can be used to compute the tail probability.
Section 8.2.2 of Box and Jenkins (1976)
provides further details of the use of STAT
Box G E P and Jenkins G M (1976) Time Series Analysis: Forecasting and Control (Revised Edition) Holden–Day
- 1: X(NX) – REAL (KIND=nag_wp) arrayInput
On entry: the time series,
, for .
- 2: NX – INTEGERInput
On entry: , the number of values in the time series.
- 3: NK – INTEGERInput
On entry: , the number of lags for which the autocorrelations are required. The lags range from to and do not include zero.
- 4: XM – REAL (KIND=nag_wp)Output
On exit: the sample mean of the input time series.
- 5: XV – REAL (KIND=nag_wp)Output
On exit: the sample variance of the input time series.
- 6: R(NK) – REAL (KIND=nag_wp) arrayOutput
On exit: the sample autocorrelation coefficient relating to lag
, for .
- 7: STAT – REAL (KIND=nag_wp)Output
On exit: the statistic used to test the hypothesis that the true autocorrelation function of the time series is identically zero.
- 8: IFAIL – INTEGERInput/Output
must be set to
. If you are unfamiliar with this parameter you should refer to Section 3.3
in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value
is recommended. If the output of error messages is undesirable, then the value
is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is
. When the value is used it is essential to test the value of IFAIL on exit.
unless the routine detects an error or a warning has been flagged (see Section 6
6 Error Indicators and Warnings
If on entry
, explanatory error messages are output on the current error message unit (as defined by X04AAF
Errors or warnings detected by the routine:
On entry, all values of X
are practically identical, giving zero variance. In this case R
are undefined on exit.
The computations are believed to be stable.
If , or then the autocorrelations are calculated directly and the time taken by G13ABF is approximately proportional to , otherwise the autocorrelations are calculated by utilizing fast fourier transforms (FFTs) and the time taken is approximately proportional to . If FFTs are used then G13ABF internally allocates approximately real elements.
If the input series for G13ABF was generated by differencing using G13AAF
, ensure that only the differenced values are input to G13ABF, and not the reconstituting information.
In the example below, a set of values of sunspot counts is used as input. The first autocorrelations are computed.
9.1 Program Text
Program Text (g13abfe.f90)
9.2 Program Data
Program Data (g13abfe.d)
9.3 Program Results
Program Results (g13abfe.r)