NAG FL Interface
g13dmf (multi_corrmat_cross)
1
Purpose
g13dmf calculates the sample crosscorrelation (or crosscovariance) matrices of a multivariate time series.
2
Specification
Fortran Interface
Integer, Intent (In) 
:: 
k, n, m, kmax 
Integer, Intent (Inout) 
:: 
ifail 
Real (Kind=nag_wp), Intent (In) 
:: 
w(kmax,n) 
Real (Kind=nag_wp), Intent (Inout) 
:: 
r0(kmax,k), r(kmax,kmax,m) 
Real (Kind=nag_wp), Intent (Out) 
:: 
wmean(k) 
Character (1), Intent (In) 
:: 
matrix 

C Header Interface
#include <nag.h>
void 
g13dmf_ (const char *matrix, const Integer *k, const Integer *n, const Integer *m, const double w[], const Integer *kmax, double wmean[], double r0[], double r[], Integer *ifail, const Charlen length_matrix) 

C++ Header Interface
#include <nag.h> extern "C" {
void 
g13dmf_ (const char *matrix, const Integer &k, const Integer &n, const Integer &m, const double w[], const Integer &kmax, double wmean[], double r0[], double r[], Integer &ifail, const Charlen length_matrix) 
}

The routine may be called by the names g13dmf or nagf_tsa_multi_corrmat_cross.
3
Description
Let
${W}_{t}={\left({w}_{1t},{w}_{2t},\dots ,{w}_{kt}\right)}^{\mathrm{T}}$, for
$t=1,2,\dots ,n$, denote
$n$ observations of a vector of
$k$ time series. The sample crosscovariance matrix at lag
$l$ is defined to be the
$k$ by
$k$ matrix
$\hat{C}\left(l\right)$, whose (
$i,j$)th element is given by
where
${\overline{w}}_{i}$ and
${\overline{w}}_{j}$ denote the sample means for the
$i$th and
$j$th series respectively. The sample crosscorrelation matrix at lag
$l$ is defined to be the
$k$ by
$k$ matrix
$\hat{R}\left(l\right)$, whose
$\left(i,j\right)$th element is given by
The number of lags, $m$, is usually taken to be at most $n/4$.
If
${W}_{t}$ follows a vector moving average model of order
$q$, then it can be shown that the theoretical crosscorrelation matrices
$\left(R\left(l\right)\right)$ are zero beyond lag
$q$. In order to help spot a possible cutoff point, the elements of
$\hat{R}\left(l\right)$ are usually compared to their approximate standard error of 1/
$\sqrt{n}$. For further details see, for example,
Wei (1990).
The routine uses a single pass through the data to compute the means and the crosscovariance matrix at lag zero. The crosscovariance 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
Arguments

1:
$\mathbf{matrix}$ – Character(1)
Input

On entry: indicates whether the crosscovariance or crosscorrelation matrices are to be computed.
 ${\mathbf{matrix}}=\text{'V'}$
 The crosscovariance matrices are computed.
 ${\mathbf{matrix}}=\text{'R'}$
 The crosscorrelation matrices are computed.
Constraint:
${\mathbf{matrix}}=\text{'V'}$ or $\text{'R'}$.

2:
$\mathbf{k}$ – Integer
Input

On entry: $k$, the dimension of the multivariate time series.
Constraint:
${\mathbf{k}}\ge 1$.

3:
$\mathbf{n}$ – Integer
Input

On entry: $n$, the number of observations in the series.
Constraint:
${\mathbf{n}}\ge 2$.

4:
$\mathbf{m}$ – Integer
Input

On entry:
$m$, the number of crosscorrelation (or crosscovariance) matrices to be computed. If in doubt set
${\mathbf{m}}=10$. However it should be noted that
m is usually taken to be at most
${\mathbf{n}}/4$.
Constraint:
$1\le {\mathbf{m}}<{\mathbf{n}}$.

5:
$\mathbf{w}\left({\mathbf{kmax}},{\mathbf{n}}\right)$ – Real (Kind=nag_wp) array
Input

On entry: ${\mathbf{w}}\left(\mathit{i},\mathit{t}\right)$ must contain the observation ${w}_{\mathit{i}\mathit{t}}$, for $\mathit{i}=1,2,\dots ,k$ and $\mathit{t}=1,2,\dots ,n$.

6:
$\mathbf{kmax}$ – Integer
Input

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:
${\mathbf{kmax}}\ge {\mathbf{k}}$.

7:
$\mathbf{wmean}\left({\mathbf{k}}\right)$ – Real (Kind=nag_wp) array
Output

On exit: the means,
${\overline{w}}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,k$.

8:
$\mathbf{r0}\left({\mathbf{kmax}},{\mathbf{k}}\right)$ – Real (Kind=nag_wp) array
Output

On exit: if
$i\ne j$, then
${\mathbf{r0}}\left(i,j\right)$ contains an estimate of the
$\left(i,j\right)$th element of the crosscorrelation (or crosscovariance) matrix at lag zero,
${\hat{R}}_{ij}\left(0\right)$; if
$i=j$, then if
${\mathbf{matrix}}=\text{'V'}$,
${\mathbf{r0}}\left(i,i\right)$ contains the variance of the
$i$th series,
${\hat{C}}_{ii}\left(0\right)$, and if
${\mathbf{matrix}}=\text{'R'}$,
${\mathbf{r0}}\left(i,i\right)$ contains the standard deviation of the
$i$th series,
$\sqrt{{\hat{C}}_{ii}\left(0\right)}$.
If
${\mathbf{ifail}}={\mathbf{2}}$ and
${\mathbf{matrix}}=\text{'R'}$, then on exit all the elements in
r0 whose computation involves the zero variance are set to zero.

9:
$\mathbf{r}\left({\mathbf{kmax}},{\mathbf{kmax}},{\mathbf{m}}\right)$ – Real (Kind=nag_wp) array
Output

On exit:
${\mathbf{r}}\left(\mathit{i},\mathit{j},\mathit{l}\right)$ contains an estimate of the (
$\mathit{i},\mathit{j}$)th element of the crosscorrelation (or crosscovariance) at lag
$\mathit{l}$,
${\hat{R}}_{\mathit{i}\mathit{j}}\left(\mathit{l}\right)$, for
$\mathit{l}=1,2,\dots ,m$,
$\mathit{i}=1,2,\dots ,k$ and
$\mathit{j}=1,2,\dots ,k$.
If
${\mathbf{ifail}}={\mathbf{2}}$ and
${\mathbf{matrix}}=\text{'R'}$, then on exit all the elements in
r whose computation involves the zero variance are set to zero.

10:
$\mathbf{ifail}$ – Integer
Input/Output

On entry:
ifail must be set to
$0$,
$1\text{or}1$. If you are unfamiliar with this argument you should refer to
Section 4 in the Introduction to the NAG Library FL Interface for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value
$1\text{or}1$ is recommended. If the output of error messages is undesirable, then the value
$1$ is recommended. Otherwise, if you are not familiar with this argument, the recommended value is
$0$.
When the value $\mathbf{1}\text{or}\mathbf{1}$ is used it is essential to test the value of ifail on exit.
On exit:
${\mathbf{ifail}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see
Section 6).
6
Error Indicators and Warnings
If on entry
${\mathbf{ifail}}=0$ or
$1$, explanatory error messages are output on the current error message unit (as defined by
x04aaf).
Errors or warnings detected by the routine:
 ${\mathbf{ifail}}=1$

On entry, ${\mathbf{k}}=\u2329\mathit{\text{value}}\u232a$.
Constraint: ${\mathbf{k}}\ge 1$.
On entry, ${\mathbf{kmax}}=\u2329\mathit{\text{value}}\u232a$ and ${\mathbf{k}}=\u2329\mathit{\text{value}}\u232a$.
Constraint: ${\mathbf{kmax}}\ge {\mathbf{k}}$.
On entry, ${\mathbf{m}}=\u2329\mathit{\text{value}}\u232a$ and ${\mathbf{n}}=\u2329\mathit{\text{value}}\u232a$.
Constraint: ${\mathbf{m}}\ge 1$ and ${\mathbf{m}}<{\mathbf{n}}$.
On entry, ${\mathbf{matrix}}=\u2329\mathit{\text{value}}\u232a$.
Constraint: ${\mathbf{matrix}}=\text{'V'}$ or $\text{'R'}$.
On entry, ${\mathbf{n}}=\u2329\mathit{\text{value}}\u232a$.
Constraint: ${\mathbf{n}}\ge 2$.
 ${\mathbf{ifail}}=2$

On entry, at least one of the series is such that all its elements are practically identical giving zero (or near zero) variance. In this case if
${\mathbf{matrix}}=\text{'R'}$ all the correlations in
r0 and
r involving this variance are set to zero.
 ${\mathbf{ifail}}=99$
An unexpected error has been triggered by this routine. Please
contact
NAG.
See
Section 7 in the Introduction to the NAG Library FL Interface for further information.
 ${\mathbf{ifail}}=399$
Your licence key may have expired or may not have been installed correctly.
See
Section 8 in the Introduction to the NAG Library FL Interface for further information.
 ${\mathbf{ifail}}=999$
Dynamic memory allocation failed.
See
Section 9 in the Introduction to the NAG Library FL Interface for further information.
7
Accuracy
For a discussion of the accuracy of the onepass algorithm used to compute the sample crosscovariances at lag zero see
West (1979). For the other lags a twopass algorithm is used to compute the crosscovariances; the accuracy of this algorithm is also discussed in
West (1979). The accuracy of the crosscorrelations will depend on the accuracy of the computed crosscovariances.
8
Parallelism and Performance
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 implementationspecific information.
The time taken is roughly proportional to $mn{k}^{2}$.
10
Example
This program computes the sample crosscorrelation matrices of two time series of length $48$, up to lag $10$. It also prints the crosscorrelation matrices together with plots of symbols indicating which elements of the correlation matrices are significant. Three * represent significance at the $0.5$% 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
10.2
Program Data
10.3
Program Results