G13ABF (PDF version)
G13 Chapter Contents
G13 Chapter Introduction
NAG Library Manual

NAG Library Routine Document

G13ABF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

+ Contents

    1  Purpose
    7  Accuracy

1  Purpose

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.

2  Specification

SUBROUTINE G13ABF ( X, NX, NK, XM, XV, R, STAT, IFAIL)
INTEGER  NX, NK, IFAIL
REAL (KIND=nag_wp)  X(NX), XM, XV, R(NK), STAT

3  Description

The data consists of n observations xi, for i=1,2,,n from a time series.
The quantities calculated are
(a) The sample mean
x-=i=1nxin.
(b) The sample variance (for n2)
s2=i=1n xi-x- 2 n-1 .
(c) The sample autocorrelation coefficients of lags k=1,2,,K, where K is a user-specified maximum lag, and K<n, n>1.
The coefficient of lag k is defined as
rk=i=1 n-kxi-x-xi+k-x- i=1n xi-x- 2 .
See page 496 of Box and Jenkins (1976) for further details.
(d) A test statistic defined as
STAT=nk= 1Krk2,
which can be used to test the hypothesis that the true autocorrelation function is identically zero.
If n is large and K is much smaller than n, STAT has a χK2 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.

4  References

Box G E P and Jenkins G M (1976) Time Series Analysis: Forecasting and Control (Revised Edition) Holden–Day

5  Parameters

1:     X(NX) – REAL (KIND=nag_wp) arrayInput
On entry: the time series, xi, for i=1,2,,n.
2:     NX – INTEGERInput
On entry: n, the number of values in the time series.
Constraint: NX>1.
3:     NK – INTEGERInput
On entry: K, the number of lags for which the autocorrelations are required. The lags range from 1 to K and do not include zero.
Constraint: 0<NK<NX.
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 k, for k=1,2,,K.
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
On entry: IFAIL must be set to 0, -1​ or ​1. 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 -1​ or ​1 is recommended. If the output of error messages is undesirable, then the value 1 is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is 0. When the value -1​ or ​1 is used it is essential to test the value of IFAIL on exit.
On exit: IFAIL=0 unless the routine detects an error or a warning has been flagged (see Section 6).

6  Error Indicators and Warnings

If on entry IFAIL=0 or -1, explanatory error messages are output on the current error message unit (as defined by X04AAF).
Errors or warnings detected by the routine:
IFAIL=1
On entry,NXNK,
orNX1,
orNK0.
IFAIL=2
On entry, all values of X are practically identical, giving zero variance. In this case R and STAT are undefined on exit.

7  Accuracy

The computations are believed to be stable.

8  Further Comments

If n<100, or K<10logn then the autocorrelations are calculated directly and the time taken by G13ABF is approximately proportional to nK, otherwise the autocorrelations are calculated by utilizing fast fourier transforms (FFTs) and the time taken is approximately proportional to nlogn. If FFTs are used then G13ABF internally allocates approximately 4n 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.

9  Example

In the example below, a set of 50 values of sunspot counts is used as input. The first 10 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)


G13ABF (PDF version)
G13 Chapter Contents
G13 Chapter Introduction
NAG Library Manual

© The Numerical Algorithms Group Ltd, Oxford, UK. 2012