NAG Library Routine Document
G13DMF
1 Purpose
G13DMF calculates the sample cross-correlation (or cross-covariance) matrices of a multivariate time series.
2 Specification
INTEGER |
K, N, M, KMAX, IFAIL |
REAL (KIND=nag_wp) |
W(KMAX,N), WMEAN(K), R0(KMAX,K), R(KMAX,KMAX,M) |
CHARACTER(1) |
MATRIX |
|
3 Description
Let
, for
, denote
observations of a vector of
time series. The sample cross-covariance matrix at lag
is defined to be the
by
matrix
, whose (
)th element is given by
where
and
denote the sample means for the
th and
th series respectively. The sample cross-correlation matrix at lag
is defined to be the
by
matrix
, whose
th element is given by
The number of lags, , is usually taken to be at most .
If
follows a vector moving average model of order
, then it can be shown that the theoretical cross-correlation matrices
are zero beyond lag
. In order to help spot a possible cut-off point, the elements of
are usually compared to their approximate standard error of 1/
. For further details see, for example,
Wei (1990).
The routine uses a single pass through the data to compute the means and the cross-covariance matrix at lag zero. The cross-covariance matrices at further lags are then computed on a second pass through the data.
4 References
Wei W W S (1990) Time Series Analysis: Univariate and Multivariate Methods Addison–Wesley
West D H D (1979) Updating mean and variance estimates: An improved method Comm. ACM 22 532–555
5 Parameters
- 1: – CHARACTER(1)Input
-
On entry: indicates whether the cross-covariance or cross-correlation matrices are to be computed.
- The cross-covariance matrices are computed.
- The cross-correlation matrices are computed.
Constraint:
or .
- 2: – INTEGERInput
-
On entry: , the dimension of the multivariate time series.
Constraint:
.
- 3: – INTEGERInput
-
On entry: , the number of observations in the series.
Constraint:
.
- 4: – INTEGERInput
-
On entry:
, the number of cross-correlation (or cross-covariance) matrices to be computed. If in doubt set
. However it should be noted that
M is usually taken to be at most
.
Constraint:
.
- 5: – REAL (KIND=nag_wp) arrayInput
-
On entry: must contain the observation , for and .
- 6: – INTEGERInput
-
On entry: the first dimension of the arrays
W,
R0 and
R and the second dimension of the array
R as declared in the (sub)program from which G13DMF is called.
Constraint:
.
- 7: – REAL (KIND=nag_wp) arrayOutput
-
On exit: the means,
, for .
- 8: – REAL (KIND=nag_wp) arrayOutput
-
On exit: if
, then
contains an estimate of the
th element of the cross-correlation (or cross-covariance) matrix at lag zero,
; if
, then if
,
contains the variance of the
th series,
, and if
,
contains the standard deviation of the
th series,
.
If
and
, then on exit all the elements in
R0 whose computation involves the zero variance are set to zero.
- 9: – REAL (KIND=nag_wp) arrayOutput
-
On exit:
contains an estimate of the (
)th element of the cross-correlation (or cross-covariance) at lag
,
, for
,
and
.
If
and
, then on exit all the elements in
R whose computation involves the zero variance are set to zero.
- 10: – INTEGERInput/Output
-
On entry:
IFAIL must be set to
,
. If you are unfamiliar with this parameter you should refer to
Section 3.3 in the Essential Introduction 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 parameter, 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, | or , |
or | , |
or | , |
or | , |
or | , |
or | . |
-
On entry, at least one of the
series is such that all its elements are practically equal giving zero (or near zero) variance. In this case if
all the correlations in
R0 and
R involving this variance are set to zero.
An unexpected error has been triggered by this routine. Please
contact
NAG.
See
Section 3.8 in the Essential Introduction for further information.
Your licence key may have expired or may not have been installed correctly.
See
Section 3.7 in the Essential Introduction for further information.
Dynamic memory allocation failed.
See
Section 3.6 in the Essential Introduction for further information.
7 Accuracy
For a discussion of the accuracy of the one-pass algorithm used to compute the sample cross-covariances at lag zero see
West (1979). For the other lags a two-pass algorithm is used to compute the cross-covariances; the accuracy of this algorithm is also discussed in
West (1979). The accuracy of the cross-correlations will depend on the accuracy of the computed cross-covariances.
8 Parallelism and Performance
G13DMF is not threaded by NAG in any implementation.
G13DMF 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.
The time taken is roughly proportional to .
10 Example
This program computes the sample cross-correlation matrices of two time series of length , up to lag . It also prints the cross-correlation matrices together with plots of symbols indicating which elements of the correlation matrices are significant. Three * represent significance at the % level, two * represent significance at the 1% level and a single * represents significance at the 5% level. The * are plotted above or below the line depending on whether the elements are significant in the positive or negative direction.
10.1 Program Text
Program Text (g13dmfe.f90)
10.2 Program Data
Program Data (g13dmfe.d)
10.3 Program Results
Program Results (g13dmfe.r)