NAG Library Function Document
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.
||nag_tsa_auto_corr (const double x,
The data consist 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 et seq. 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.
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
x[nx] – const doubleInput
On entry: the time series, , for .
nx – IntegerInput
On entry: the number of values, , in the time series.
nk – IntegerInput
On entry: the number of lags, , for which the autocorrelations are required. The lags range from 1 to and do not include zero.
mean – double *Output
On exit: the sample mean of the input time series.
var – double *Output
On exit: the sample variance of the input time series.
r[nk] – doubleOutput
On exit: the sample autocorrelation coefficient relating to lag , for .
stat – double *Output
On exit: the statistic used to test the hypothesis that the true autocorrelation function of the time series is identically zero.
fail – NagError *Input/Output
The NAG error argument (see Section 3.6
in the Essential Introduction).
6 Error Indicators and Warnings
On entry, while . These arguments must satisfy .
On entry, .
On entry, .
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.
The time taken by nag_tsa_auto_corr (g13abc) is approximately proportional to .
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 (g13abce.c)
9.2 Program Data
Program Data (g13abce.d)
9.3 Program Results
Program Results (g13abce.r)