g13ab 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.

Syntax

C#
public static void g13ab(
	double[] x,
	int nx,
	int nk,
	out double xm,
	out double xv,
	double[] r,
	out double stat,
	out int ifail
)
Visual Basic
Public Shared Sub g13ab ( _
	x As Double(), _
	nx As Integer, _
	nk As Integer, _
	<OutAttribute> ByRef xm As Double, _
	<OutAttribute> ByRef xv As Double, _
	r As Double(), _
	<OutAttribute> ByRef stat As Double, _
	<OutAttribute> ByRef ifail As Integer _
)
Visual C++
public:
static void g13ab(
	array<double>^ x, 
	int nx, 
	int nk, 
	[OutAttribute] double% xm, 
	[OutAttribute] double% xv, 
	array<double>^ r, 
	[OutAttribute] double% stat, 
	[OutAttribute] int% ifail
)
F#
static member g13ab : 
        x : float[] * 
        nx : int * 
        nk : int * 
        xm : float byref * 
        xv : float byref * 
        r : float[] * 
        stat : float byref * 
        ifail : int byref -> unit 

Parameters

x
Type: array<System..::..Double>[]()[][]
An array of size [nx]
On entry: the time series, xi, for i=1,2,,n.
nx
Type: System..::..Int32
On entry: n, the number of values in the time series.
Constraint: nx>1.
nk
Type: System..::..Int32
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.
xm
Type: System..::..Double%
On exit: the sample mean of the input time series.
xv
Type: System..::..Double%
On exit: the sample variance of the input time series.
r
Type: array<System..::..Double>[]()[][]
An array of size [nk]
On exit: the sample autocorrelation coefficient relating to lag k, for k=1,2,,K.
stat
Type: System..::..Double%
On exit: the statistic used to test the hypothesis that the true autocorrelation function of the time series is identically zero.
ifail
Type: System..::..Int32%
On exit: ifail=0 unless the method detects an error or a warning has been flagged (see [Error Indicators and Warnings]).

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=1nxi-x-2n-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=1n-kxi-x-xi+k-x-i=1nxi-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; g01ec 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.

References

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

Error Indicators and Warnings

Errors or warnings detected by the method:
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.
ifail=-9000
An error occured, see message report.
ifail=-8000
Negative dimension for array value
ifail=-6000
Invalid Parameters value

Accuracy

The computations are believed to be stable.

Parallelism and Performance

None.

Further Comments

If n<100, or K<10logn then the autocorrelations are calculated directly and the time taken by g13ab 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 g13ab internally allocates approximately 4n real elements.
If the input series for g13ab was generated by differencing using g13aa, ensure that only the differenced values are input to g13ab, and not the reconstituting information.

Example

In the example below, a set of 50 values of sunspot counts is used as input. The first 10 autocorrelations are computed.

Example program (C#): g13abe.cs

Example program data: g13abe.d

Example program results: g13abe.r

See Also