NAG CL Interface
g13abc (uni_​autocorr)

Settings help

CL Name Style:


1 Purpose

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>
void  g13abc (const double x[], Integer nx, Integer nk, double *mean, double *var, double r[], double *stat, NagError *fail)
The function may be called by the names: g13abc, nag_tsa_uni_autocorr or nag_tsa_auto_corr.

3 Description

The data consist of n observations x i , for i=1,2,,n, from a time series.
The quantities calculated are:
  1. (a)The sample mean
    x ¯ = i=1 n x i n  
  2. (b)The sample variance (for n2 )
    s 2 = i=1 n ( x i - x ¯) 2 (n-1)  
  3. (c)The sample autocorrelation coefficients of lags k = 1 , 2 , , K , where K is a user-specified maximum lag, and K<n , n>1 .
  4. (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  
  5. (e)See page 496 et seq. of Box and Jenkins (1976) for further details.
  6. (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 double Input
On entry: the time series, x i , for i=1,2,,n.
2: nx Integer Input
On entry: the number of values, n , in the time series.
Constraint: nx>1 .
3: nk Integer Input
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: mean double * Output
On exit: the sample mean of the input time series.
5: var double * Output
On exit: the sample variance of the input time series.
6: r[nk] double Output
On exit: the sample autocorrelation coefficient relating to lag k , for k=1,2,,K.
7: stat double * Output
On exit: the statistic used to test the hypothesis that the true autocorrelation function of the time series is identically zero.
8: fail NagError * Input/Output
The NAG error argument (see Section 7 in the Introduction to the NAG Library CL Interface).

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

g13abc is not threaded in any implementation.

9 Further Comments

The time taken by 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)