nag_tsa_auto_corr (g13abc) (PDF version)
g13 Chapter Contents
g13 Chapter Introduction
NAG Library Manual

NAG Library Function Document

nag_tsa_auto_corr (g13abc)

+ Contents

    1  Purpose
    7  Accuracy

1  Purpose

nag_tsa_auto_corr (g13abc) 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

#include <nag.h>
#include <nagg13.h>
void  nag_tsa_auto_corr (const double x[], Integer nx, Integer nk, double *mean, double *var, double r[], double *stat, NagError *fail)

3  Description

The data consist of n  observations x i , for i=1,2,,n, from a time series.
The quantities calculated are:
(a) The sample mean
x - = i=1 n x i n
(b) The sample variance (for n2 )
s 2 = i=1 n x i - 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 .
(d) The coefficient of lag k  is defined as
r k = i=1 n-k x i - x - x i+k - x - i=1 n x i - x - 2
(e) See page 496 et seq. of Box and Jenkins (1976) for further details.
(f) A test statistic defined as
stat = n k=1 K r k 2 ,
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 χ K 2  distribution under the hypothesis of a zero autocorrelation function. Values of stat in the upper tail of the distribution provide evidence against the hypothesis.
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  Arguments

1:     x[nx]const doubleInput
On entry: the time series, x i , for i=1,2,,n.
2:     nxIntegerInput
On entry: the number of values, n , in the time series.
Constraint: nx>1 .
3:     nkIntegerInput
On entry: the number of lags, K , for which the autocorrelations are required. The lags range from 1 to K  and do not include zero.
Constraint: 0 < nk < nx .
4:     meandouble *Output
On exit: the sample mean of the input time series.
5:     vardouble *Output
On exit: the sample variance of the input time series.
6:     r[nk]doubleOutput
On exit: the sample autocorrelation coefficient relating to lag k , for k=1,2,,K.
7:     statdouble *Output
On exit: the statistic used to test the hypothesis that the true autocorrelation function of the time series is identically zero.
8:     failNagError *Input/Output
The NAG error argument (see Section 3.6 in the Essential Introduction).

6  Error Indicators and Warnings

NE_2_INT_ARG_LE
On entry, nx=value  while nk=value . These arguments must satisfy nx>nk .
NE_INT_ARG_LE
On entry, nk=value.
Constraint: nk>0.
On entry, nx=value.
Constraint: nx>1.
NE_TIME_SERIES_IDEN
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  Parallelism and Performance

Not applicable.

9  Further Comments

The time taken by nag_tsa_auto_corr (g13abc) is approximately proportional to nx×nk .

10  Example

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

10.1  Program Text

Program Text (g13abce.c)

10.2  Program Data

Program Data (g13abce.d)

10.3  Program Results

Program Results (g13abce.r)


nag_tsa_auto_corr (g13abc) (PDF version)
g13 Chapter Contents
g13 Chapter Introduction
NAG Library Manual

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