NAG Library Routine Document
g13abf (uni_autocorr)
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
Fortran Interface
Integer, Intent (In) | :: | nx, nk | Integer, Intent (Inout) | :: | ifail | Real (Kind=nag_wp), Intent (In) | :: | x(nx) | Real (Kind=nag_wp), Intent (Out) | :: | xm, xv, r(nk), stat |
|
C Header Interface
#include <nagmk26.h>
void |
g13abf_ (const double x[], const Integer *nx, const Integer *nk, double *xm, double *xv, double r[], double *stat, Integer *ifail) |
|
3
Description
The data consists of observations , for from a time series.
The quantities calculated are
(a) |
The sample mean
|
(b) |
The sample variance (for )
|
(c) |
The sample autocorrelation coefficients of lags , where is a user-specified maximum lag, and , .
The coefficient of lag is defined as
See page 496 of Box and Jenkins (1976) for further details. |
(d) |
A test statistic defined as
which can be used to test the hypothesis that the true autocorrelation function is identically zero.
If is large and is much smaller than , stat has a 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
Arguments
- 1: – Real (Kind=nag_wp) arrayInput
-
On entry: the time series,
, for .
- 2: – IntegerInput
-
On entry: , the number of values in the time series.
Constraint:
.
- 3: – IntegerInput
-
On entry: , the number of lags for which the autocorrelations are required. The lags range from to and do not include zero.
Constraint:
.
- 4: – Real (Kind=nag_wp)Output
-
On exit: the sample mean of the input time series.
- 5: – Real (Kind=nag_wp)Output
-
On exit: the sample variance of the input time series.
- 6: – Real (Kind=nag_wp) arrayOutput
-
On exit: the sample autocorrelation coefficient relating to lag
, for .
- 7: – 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: – IntegerInput/Output
-
On entry:
ifail must be set to
,
. If you are unfamiliar with this argument you should refer to
Section 3.4 in How to Use the NAG Library and its Documentation for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value
is recommended. If the output of error messages is undesirable, then the value
is recommended. Otherwise, if you are not familiar with this argument, the recommended value is
.
When the value is used it is essential to test the value of ifail on exit.
On exit:
unless the routine detects an error or a warning has been flagged (see
Section 6).
6
Error Indicators and Warnings
If on entry
or
, explanatory error messages are output on the current error message unit (as defined by
x04aaf).
Errors or warnings detected by the routine:
-
On entry, .
Constraint: .
On entry, .
Constraint: .
On entry, and .
Constraint: .
-
On entry, all values of
x are practically identical. This gives zero variance and means that
r and
stat are undefined on exit.
An unexpected error has been triggered by this routine. Please
contact
NAG.
See
Section 3.9 in How to Use the NAG Library and its Documentation for further information.
Your licence key may have expired or may not have been installed correctly.
See
Section 3.8 in How to Use the NAG Library and its Documentation for further information.
Dynamic memory allocation failed.
See
Section 3.7 in How to Use the NAG Library and its Documentation for further information.
7
Accuracy
The computations are believed to be stable.
8
Parallelism and Performance
g13abf is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
g13abf makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
Please consult the
X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this routine. Please also consult the
Users' Note for your implementation for any additional implementation-specific information.
If , or then the autocorrelations are calculated directly and the time taken by g13abf is approximately proportional to , otherwise the autocorrelations are calculated by utilizing fast fourier transforms (FFTs) and the time taken is approximately proportional to . If FFTs are used then g13abf internally allocates approximately 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.
10
Example
In the example below, a set of values of sunspot counts is used as input. The first autocorrelations are computed.
10.1
Program Text
Program Text (g13abfe.f90)
10.2
Program Data
Program Data (g13abfe.d)
10.3
Program Results
Program Results (g13abfe.r)
This plot shows the autocorrelations for all possible lag values. Reference lines are given at .