Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

Chapter Contents
Chapter Introduction
NAG Toolbox

NAG Toolbox: nag_tsa_multi_corrmat_cross (g13dm)

Purpose

nag_tsa_multi_corrmat_cross (g13dm) calculates the sample cross-correlation (or cross-covariance) matrices of a multivariate time series.

Syntax

[wmean, r0, r, ifail] = g13dm(matrix, k, m, w, 'n', n)
[wmean, r0, r, ifail] = nag_tsa_multi_corrmat_cross(matrix, k, m, w, 'n', n)

Description

Let Wt = (w1t,w2t,,wkt)T ${W}_{t}={\left({w}_{1t},{w}_{2t},\dots ,{w}_{kt}\right)}^{\mathrm{T}}$, for t = 1,2,,n$t=1,2,\dots ,n$, denote n$n$ observations of a vector of k$k$ time series. The sample cross-covariance matrix at lag l$l$ is defined to be the k$k$ by k$k$ matrix (l)$\stackrel{^}{C}\left(l\right)$, whose (i,j$i,j$)th element is given by
 n Ĉij(l) = 1/n ∑ (wi(t − l) − wi)(wjt − wj),  l = 0,1,2, … ,m, ​i = 1,2, … ,k​ and ​j = 1,2, … ,k, t = l + 1
$C^ij(l)=1n∑t=l+1n(wi(t-l)-w-i)(wjt-w-j), l=0,1,2,…,m, ​i=1,2,…,k​ and ​j=1,2,…,k,$
where wi${\stackrel{-}{w}}_{i}$ and wj${\stackrel{-}{w}}_{j}$ denote the sample means for the i$i$th and j$j$th series respectively. The sample cross-correlation matrix at lag l$l$ is defined to be the k$k$ by k$k$ matrix (l)$\stackrel{^}{R}\left(l\right)$, whose (i,j)$\left(i,j\right)$th element is given by
 R̂ij (l) = ( Ĉij (l) )/( sqrt( Ĉii (0) Ĉjj (0) ) ) ,   l = 0,1,2, … ,m , ​ i = 1,2, … ,k ​ and ​ j = 1,2, … ,k . $R^ ij (l) = C^ ij (l) C^ ii (0) C^ jj (0) , l=0,1,2,…,m , ​ i=1,2,…,k ​ and ​ j=1,2,…,k .$
The number of lags, m$m$, is usually taken to be at most n / 4$n/4$.
If Wt${W}_{t}$ follows a vector moving average model of order q$q$, then it can be shown that the theoretical cross-correlation matrices (R(l))$\left(R\left(l\right)\right)$ are zero beyond lag q$q$. In order to help spot a possible cut-off point, the elements of (l)$\stackrel{^}{R}\left(l\right)$ are usually compared to their approximate standard error of 1/sqrt(n)$\sqrt{n}$. For further details see, for example, Wei (1990).
The function 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.

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

Parameters

Compulsory Input Parameters

1:     matrix – string (length ≥ 1)
Indicates whether the cross-covariance or cross-correlation matrices are to be computed.
matrix = 'V'${\mathbf{matrix}}=\text{'V'}$
The cross-covariance matrices are computed.
matrix = 'R'${\mathbf{matrix}}=\text{'R'}$
The cross-correlation matrices are computed.
Constraint: matrix = 'V'${\mathbf{matrix}}=\text{'V'}$ or 'R'$\text{'R'}$.
2:     k – int64int32nag_int scalar
k$k$, the dimension of the multivariate time series.
Constraint: k1${\mathbf{k}}\ge 1$.
3:     m – int64int32nag_int scalar
m$m$, the number of cross-correlation (or cross-covariance) matrices to be computed. If in doubt set m = 10${\mathbf{m}}=10$. However it should be noted that m is usually taken to be at most n / 4${\mathbf{n}}/4$.
Constraint: 1m < n$1\le {\mathbf{m}}<{\mathbf{n}}$.
4:     w(kmax,n) – double array
kmax, the first dimension of the array, must satisfy the constraint kmaxk$\mathit{kmax}\ge {\mathbf{k}}$.
w(i,t)${\mathbf{w}}\left(\mathit{i},\mathit{t}\right)$ must contain the observation wit${w}_{\mathit{i}\mathit{t}}$, for i = 1,2,,k$\mathit{i}=1,2,\dots ,k$ and t = 1,2,,n$\mathit{t}=1,2,\dots ,n$.

Optional Input Parameters

1:     n – int64int32nag_int scalar
Default: The second dimension of the array w.
n$n$, the number of observations in the series.
Constraint: n2${\mathbf{n}}\ge 2$.

kmax

Output Parameters

1:     wmean(k) – double array
The means, wi${\stackrel{-}{w}}_{\mathit{i}}$, for i = 1,2,,k$\mathit{i}=1,2,\dots ,k$.
2:     r0(kmax,k) – double array
kmaxk$\mathit{kmax}\ge {\mathbf{k}}$.
If ij$i\ne j$, then r0(i,j)${\mathbf{r0}}\left(i,j\right)$ contains an estimate of the (i,j)$\left(i,j\right)$th element of the cross-correlation (or cross-covariance) matrix at lag zero, ij(0)${\stackrel{^}{R}}_{ij}\left(0\right)$; if i = j$i=j$, then if matrix = 'V'${\mathbf{matrix}}=\text{'V'}$, r0(i,i)${\mathbf{r0}}\left(i,i\right)$ contains the variance of the i$i$th series, ii(0)${\stackrel{^}{C}}_{ii}\left(0\right)$, and if matrix = 'R'${\mathbf{matrix}}=\text{'R'}$, r0(i,i)${\mathbf{r0}}\left(i,i\right)$ contains the standard deviation of the i$i$th series, sqrt(ii(0))$\sqrt{{\stackrel{^}{C}}_{ii}\left(0\right)}$.
If ${\mathbf{ifail}}={\mathbf{2}}$ and matrix = 'R'${\mathbf{matrix}}=\text{'R'}$, then on exit all the elements in r0 whose computation involves the zero variance are set to zero.
3:     r(kmax,kmax,m) – double array
kmaxk$\mathit{kmax}\ge {\mathbf{k}}$.
r(i,j,l)${\mathbf{r}}\left(\mathit{i},\mathit{j},\mathit{l}\right)$ contains an estimate of the (i,j$\mathit{i},\mathit{j}$)th element of the cross-correlation (or cross-covariance) at lag l$\mathit{l}$, ij(l)${\stackrel{^}{R}}_{\mathit{i}\mathit{j}}\left(\mathit{l}\right)$, for l = 1,2,,m$\mathit{l}=1,2,\dots ,m$, i = 1,2,,k$\mathit{i}=1,2,\dots ,k$ and j = 1,2,,k$\mathit{j}=1,2,\dots ,k$.
If ${\mathbf{ifail}}={\mathbf{2}}$ and matrix = 'R'${\mathbf{matrix}}=\text{'R'}$, then on exit all the elements in r whose computation involves the zero variance are set to zero.
4:     ifail – int64int32nag_int scalar
${\mathrm{ifail}}={\mathbf{0}}$ unless the function detects an error (see [Error Indicators and Warnings]).

Error Indicators and Warnings

Errors or warnings detected by the function:

Cases prefixed with W are classified as warnings and do not generate an error of type NAG:error_n. See nag_issue_warnings.

ifail = 1${\mathbf{ifail}}=1$
 On entry, matrix ≠ 'V'${\mathbf{matrix}}\ne \text{'V'}$ or 'R'$\text{'R'}$, or k < 1${\mathbf{k}}<1$, or n < 2${\mathbf{n}}<2$, or m < 1${\mathbf{m}}<1$, or m ≥ n${\mathbf{m}}\ge {\mathbf{n}}$, or kmax < k$\mathit{kmax}<{\mathbf{k}}$.
W ifail = 2${\mathbf{ifail}}=2$
On entry, at least one of the k$k$ series is such that all its elements are practically equal giving zero (or near zero) variance. In this case if matrix = 'R'${\mathbf{matrix}}=\text{'R'}$ all the correlations in r0 and r involving this variance are set to zero.

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.

The time taken is roughly proportional to mnk2$mn{k}^{2}$.

Example

function nag_tsa_multi_corrmat_cross_example
matrix = 'R';
k = int64(2);
m = int64(10);
w = [-1.49, -1.62, 5.2, 6.23, 6.21, 5.86, 4.09, 3.18, 2.62, 1.49, 1.17, ...
0.85, -0.35, 0.24, 2.44, 2.58, 2.04, 0.4, 2.26, 3.34, 5.09, 5, 4.78, ...
4.11, 3.45, 1.65, 1.29, 4.09, 6.32, 7.5, 3.89, 1.58, 5.21, 5.25, 4.93, ...
7.38, 5.87, 5.81, 9.68, 9.07, 7.29, 7.84, 7.55, 7.32, 7.97, 7.76, 7, 8.35;
7.34, 6.35, 6.96, 8.54, 6.62, 4.97, 4.55, 4.81, 4.75, ...
4.76, 10.88, 10.01, 11.62, 10.36, 6.4, 6.24, 7.93, 4.04, 3.73, 5.6, ...
5.35, 6.81, 8.27, 7.68, 6.65, 6.08, 10.25, 9.14, 17.75, 13.3, ...
9.63, 6.8, 4.08, 5.06, 4.94, 6.65, 7.94, 10.76, 11.89, ...
5.85, 9.01, 7.5, 10.02, 10.38, 8.15, 8.37, 10.73, 12.14];
[wmean, r0, r, ifail] = nag_tsa_multi_corrmat_cross(matrix, k, m, w)

wmean =

4.3702
7.8675

r0 =

2.8176    0.2493
0.2493    2.8149

r(:,:,1) =

0.7359    0.1743
0.2114    0.5546

r(:,:,2) =

0.4557    0.0764
0.0693    0.2605

r(:,:,3) =

0.3792    0.0138
0.0260   -0.0381

r(:,:,4) =

0.3224    0.1100
0.0933   -0.2359

r(:,:,5) =

0.3411    0.2694
0.0872   -0.2501

r(:,:,6) =

0.3631    0.3436
0.1323   -0.2265

r(:,:,7) =

0.2800    0.4254
0.2069   -0.1285

r(:,:,8) =

0.2480    0.5217
0.1970   -0.0846

r(:,:,9) =

0.2398    0.2664
0.2537    0.0745

r(:,:,10) =

0.1619   -0.0197
0.2667    0.0047

ifail =

0

function g13dm_example
matrix = 'R';
k = int64(2);
m = int64(10);
w = [-1.49, -1.62, 5.2, 6.23, 6.21, 5.86, 4.09, 3.18, 2.62, 1.49, 1.17, ...
0.85, -0.35, 0.24, 2.44, 2.58, 2.04, 0.4, 2.26, 3.34, 5.09, 5, 4.78, ...
4.11, 3.45, 1.65, 1.29, 4.09, 6.32, 7.5, 3.89, 1.58, 5.21, 5.25, 4.93, ...
7.38, 5.87, 5.81, 9.68, 9.07, 7.29, 7.84, 7.55, 7.32, 7.97, 7.76, 7, 8.35;
7.34, 6.35, 6.96, 8.54, 6.62, 4.97, 4.55, 4.81, 4.75, ...
4.76, 10.88, 10.01, 11.62, 10.36, 6.4, 6.24, 7.93, 4.04, 3.73, 5.6, ...
5.35, 6.81, 8.27, 7.68, 6.65, 6.08, 10.25, 9.14, 17.75, 13.3, ...
9.63, 6.8, 4.08, 5.06, 4.94, 6.65, 7.94, 10.76, 11.89, ...
5.85, 9.01, 7.5, 10.02, 10.38, 8.15, 8.37, 10.73, 12.14];
[wmean, r0, r, ifail] = g13dm(matrix, k, m, w)

wmean =

4.3702
7.8675

r0 =

2.8176    0.2493
0.2493    2.8149

r(:,:,1) =

0.7359    0.1743
0.2114    0.5546

r(:,:,2) =

0.4557    0.0764
0.0693    0.2605

r(:,:,3) =

0.3792    0.0138
0.0260   -0.0381

r(:,:,4) =

0.3224    0.1100
0.0933   -0.2359

r(:,:,5) =

0.3411    0.2694
0.0872   -0.2501

r(:,:,6) =

0.3631    0.3436
0.1323   -0.2265

r(:,:,7) =

0.2800    0.4254
0.2069   -0.1285

r(:,:,8) =

0.2480    0.5217
0.1970   -0.0846

r(:,:,9) =

0.2398    0.2664
0.2537    0.0745

r(:,:,10) =

0.1619   -0.0197
0.2667    0.0047

ifail =

0