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)

 Contents

    1  Purpose
    2  Syntax
    7  Accuracy
    9  Example

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,,wktT , for t=1,2,,n, denote n observations of a vector of k time series. The sample cross-covariance matrix at lag l is defined to be the k by k matrix C^l, whose (i,j)th element is given by
C^ijl=1nt=l+1nwit-l-w-iwjt-w-j,  l=0,1,2,,m, ​i=1,2,,k​ and ​j=1,2,,k,  
where w-i and w-j denote the sample means for the ith and jth series respectively. The sample cross-correlation matrix at lag l is defined to be the k by k matrix R^l, whose i,jth element is given by
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, is usually taken to be at most n/4.
If Wt follows a vector moving average model of order q, then it can be shown that the theoretical cross-correlation matrices Rl are zero beyond lag q. In order to help spot a possible cut-off point, the elements of R^l are usually compared to their approximate standard error of 1/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'
The cross-covariance matrices are computed.
matrix='R'
The cross-correlation matrices are computed.
Constraint: matrix='V' or 'R'.
2:     k int64int32nag_int scalar
k, the dimension of the multivariate time series.
Constraint: k1.
3:     m int64int32nag_int scalar
m, the number of cross-correlation (or cross-covariance) matrices to be computed. If in doubt set m=10. However it should be noted that m is usually taken to be at most n/4.
Constraint: 1m<n.
4:     wkmaxn – double array
kmax, the first dimension of the array, must satisfy the constraint kmaxk.
wit must contain the observation wit, for i=1,2,,k and t=1,2,,n.

Optional Input Parameters

1:     n int64int32nag_int scalar
Default: the second dimension of the array w.
n, the number of observations in the series.
Constraint: n2.

Output Parameters

1:     wmeank – double array
The means, w-i, for i=1,2,,k.
2:     r0kmaxk – double array
kmax=k.
If ij, then r0ij contains an estimate of the i,jth element of the cross-correlation (or cross-covariance) matrix at lag zero, R^ij0; if i=j, then if matrix='V', r0ii contains the variance of the ith series, C^ii0, and if matrix='R', r0ii contains the standard deviation of the ith series, C^ii0.
If ifail=2 and matrix='R', then on exit all the elements in r0 whose computation involves the zero variance are set to zero.
3:     rkmaxkmaxm – double array
kmax=k.
rijl contains an estimate of the (i,j)th element of the cross-correlation (or cross-covariance) at lag l, R^ijl, for l=1,2,,m, i=1,2,,k and j=1,2,,k.
If ifail=2 and 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=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
On entry,matrix'V' or 'R',
ork<1,
orn<2,
orm<1,
ormn,
orkmax<k.
W  ifail=2
On entry, at least one of the k series is such that all its elements are practically equal giving zero (or near zero) variance. In this case if matrix='R' all the correlations in r0 and r involving this variance are set to zero.
   ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
   ifail=-399
Your licence key may have expired or may not have been installed correctly.
   ifail=-999
Dynamic memory allocation failed.

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 mnk2.

Example

This program computes the sample cross-correlation matrices of two time series of length 48, up to lag 10. 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 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.
function g13dm_example


fprintf('g13dm example results\n\n');

w = [-1.49, -1.62, 5.20, 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.40, 2.26, 3.34, 5.09, 5.00, ...
      4.78,  4.11, 3.45, 1.65, 1.29, 4.09, 6.32, 7.50, 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.00, 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.40, 6.24, 7.93, 4.04, 3.73, 5.60, 5.35, 6.81, ...
      8.27,  7.68, 6.65, 6.08,10.25, 9.14,17.75,13.30, 9.63, 6.80, 4.08, ...
      5.06,  4.94, 6.65, 7.94,10.76,11.89, 5.85, 9.01, 7.50,10.02,10.38, ...
      8.15, 8.37, 10.73, 12.14];
[k,n] = size(w);
k     = int64(k);
matrix = 'R';
m = int64(10);
[wmean, r0, r, ifail] = g13dm( ...
			       matrix, k, m, w);

disp('The means');
disp(wmean');
disp('Cross-Correlation Matrices');
disp('Lag = 0');
disp(r0);
for l = 1:m
  fprintf('Lag = %d\n',l);
  disp(r(:,:,l));
end
sn1 = 1/sqrt(n);
fprintf('Standard error = 1/sqrt(n) = %7.4f\n\n',sn1);

disp('Tables Of Indicator Symbols');
fprintf('\nFor Lags 1 to %d\n',m);
lhs = {'              0.005  :'; '        +     0.01   :';
       '              0.05   :'; 
       '   Sig. Level        :- - - - - - - - - -  Lags';
       '              0.05   :';
       '        -     0.01   :'; '              0.005  :'};
c = sn1*[3.29, 2.58, 1.96, 0, -1.96, -2.58, -3.29];
for i = 1:k
  for j=1:k
    if i==j
      fprintf('\nAuto-correlation function for series %d\n', i);
    else
      fprintf('\nCross-correlation function for series %d and series %d\n', ...
	      i, j);
    end
    rhs = lhs;
    for t = 1:m
      for u = 1:3
	if r(i,j,t)>c(u)
	  rhs{u} = strcat(rhs{u},'*');
	end
      end
      for u = 5:7
	if r(i,j,t)<c(u)
	  rhs{u} = strcat(rhs{u},'*');
	end
      end
    end
    fprintf('\n');
    fprintf('%s\n',rhs{1:end});
  end
end  


g13dm example results

The means
    4.3702    7.8675

Cross-Correlation Matrices
Lag = 0
    2.8176    0.2493
    0.2493    2.8149

Lag = 1
    0.7359    0.1743
    0.2114    0.5546

Lag = 2
    0.4557    0.0764
    0.0693    0.2605

Lag = 3
    0.3792    0.0138
    0.0260   -0.0381

Lag = 4
    0.3224    0.1100
    0.0933   -0.2359

Lag = 5
    0.3411    0.2694
    0.0872   -0.2501

Lag = 6
    0.3631    0.3436
    0.1323   -0.2265

Lag = 7
    0.2800    0.4254
    0.2069   -0.1285

Lag = 8
    0.2480    0.5217
    0.1970   -0.0846

Lag = 9
    0.2398    0.2664
    0.2537    0.0745

Lag = 10
    0.1619   -0.0197
    0.2667    0.0047

Standard error = 1/sqrt(n) =  0.1443

Tables Of Indicator Symbols

For Lags 1 to 10

Auto-correlation function for series 1

              0.005  :*
        +     0.01   :***
              0.05   :******
   Sig. Level        :- - - - - - - - - -  Lags
              0.05   :
        -     0.01   :
              0.005  :

Cross-correlation function for series 1 and series 2

              0.005  :*
        +     0.01   :**
              0.05   :***
   Sig. Level        :- - - - - - - - - -  Lags
              0.05   :
        -     0.01   :
              0.005  :

Cross-correlation function for series 2 and series 1

              0.005  :
        +     0.01   :
              0.05   :
   Sig. Level        :- - - - - - - - - -  Lags
              0.05   :
        -     0.01   :
              0.005  :

Auto-correlation function for series 2

              0.005  :*
        +     0.01   :*
              0.05   :*
   Sig. Level        :- - - - - - - - - -  Lags
              0.05   :
        -     0.01   :
              0.005  :

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–2015