hide long namesshow long names
hide short namesshow short names
Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
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 Wt = (w1t,w2t,,wkt)T , for t = 1,2,,nt=1,2,,n, denote nn observations of a vector of kk time series. The sample cross-covariance matrix at lag ll is defined to be the kk by kk matrix (l)C^(l), whose (i,ji,j)th element is given by
n
ij(l) = 1/n(wi(tl)wi)(wjtwj),  l = 0,1,2,,m, ​i = 1,2,,k​ and ​j = 1,2,,k,
t = l + 1
C^ij(l)=1nt=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 wiw-i and wjw-j denote the sample means for the iith and jjth series respectively. The sample cross-correlation matrix at lag ll is defined to be the kk by kk matrix (l)R^(l), whose (i,j)(i,j)th element is given by
ij (l) = ( ij (l) )/( sqrt( ii (0) 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, mm, is usually taken to be at most n / 4n/4.
If WtWt follows a vector moving average model of order qq, then it can be shown that the theoretical cross-correlation matrices (R(l))(R(l)) are zero beyond lag qq. In order to help spot a possible cut-off point, the elements of (l)R^(l) are usually compared to their approximate standard error of 1/sqrt(n)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'matrix='V'
The cross-covariance matrices are computed.
matrix = 'R'matrix='R'
The cross-correlation matrices are computed.
Constraint: matrix = 'V'matrix='V' or 'R''R'.
2:     k – int64int32nag_int scalar
kk, the dimension of the multivariate time series.
Constraint: k1k1.
3:     m – int64int32nag_int scalar
mm, the number of cross-correlation (or cross-covariance) matrices to be computed. If in doubt set m = 10m=10. However it should be noted that m is usually taken to be at most n / 4n/4.
Constraint: 1m < n1m<n.
4:     w(kmax,n) – double array
kmax, the first dimension of the array, must satisfy the constraint kmaxkkmaxk.
w(i,t)wit must contain the observation witwit, for i = 1,2,,ki=1,2,,k and t = 1,2,,nt=1,2,,n.

Optional Input Parameters

1:     n – int64int32nag_int scalar
Default: The second dimension of the array w.
nn, the number of observations in the series.
Constraint: n2n2.

Input Parameters Omitted from the MATLAB Interface

kmax

Output Parameters

1:     wmean(k) – double array
The means, wiw-i, for i = 1,2,,ki=1,2,,k.
2:     r0(kmax,k) – double array
kmaxkkmaxk.
If ijij, then r0(i,j)r0ij contains an estimate of the (i,j)(i,j)th element of the cross-correlation (or cross-covariance) matrix at lag zero, ij(0)R^ij(0); if i = ji=j, then if matrix = 'V'matrix='V', r0(i,i)r0ii contains the variance of the iith series, ii(0)C^ii(0), and if matrix = 'R'matrix='R', r0(i,i)r0ii contains the standard deviation of the iith series, sqrt(ii(0))C^ii(0).
If ifail = 2ifail=2 and matrix = 'R'matrix='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
kmaxkkmaxk.
r(i,j,l)r(i,j,l) contains an estimate of the (i,ji,j)th element of the cross-correlation (or cross-covariance) at lag ll, ij(l)R^ij(l), for l = 1,2,,ml=1,2,,m, i = 1,2,,ki=1,2,,k and j = 1,2,,kj=1,2,,k.
If ifail = 2ifail=2 and matrix = 'R'matrix='R', then on exit all the elements in r whose computation involves the zero variance are set to zero.
4:     ifail – int64int32nag_int scalar
ifail = 0ifail=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 = 1ifail=1
On entry,matrix'V'matrix'V' or 'R''R',
ork < 1k<1,
orn < 2n<2,
orm < 1m<1,
ormnmn,
orkmax < kkmax<k.
W ifail = 2ifail=2
On entry, at least one of the kk series is such that all its elements are practically equal giving zero (or near zero) variance. In this case if matrix = 'R'matrix='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.

Further Comments

The time taken is roughly proportional to mnk2mnk2.

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



PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2013