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_xcorr (g13bc)

Purpose

nag_tsa_multi_xcorr (g13bc) calculates cross-correlations between two time series.

Syntax

[s, r0, r, stat, ifail] = g13bc(x, y, nl, 'nxy', nxy)
[s, r0, r, stat, ifail] = nag_tsa_multi_xcorr(x, y, nl, 'nxy', nxy)

Description

Given two series x1,x2,,xnx1,x2,,xn and y1,y2,,yny1,y2,,yn the function calculates the cross-correlations between xtxt and lagged values of ytyt:
rxy(l) = (t = 1nl(xtx)(yt + ly))/(nsxsy),  l = 0,1,,L
rxy(l)=t=1 n-l(xt-x-)(yt+l-y-) nsxsy ,  l=0,1,,L
where
x = (t = 1nxt)/n
x-=t= 1nxtn
sx2 = (t = 1n(xtx)2)/n
sx2=t=1n (xt-x-) 2n
and similarly for yy.
The ratio of standard deviations sy / sxsy/sx is also returned, and a portmanteau statistic is calculated:
L
stat = nrxy(l)2.
l = 1
stat=nl=1Lrxy (l) 2.
Provided nn is large, LL much less than nn, and both xt,ytxt,yt are samples of series whose true autocorrelation functions are zero, then, under the null hypothesis that the true cross-correlations between the series are zero, stat has a χ2χ2-distribution with LL degrees of freedom. Values of stat in the upper tail of this distribution provide evidence against the null hypothesis.

References

Box G E P and Jenkins G M (1976) Time Series Analysis: Forecasting and Control (Revised Edition) Holden–Day

Parameters

Compulsory Input Parameters

1:     x(nxy) – double array
nxy, the dimension of the array, must satisfy the constraint nxy2nxy2.
The nn values of the xx series.
2:     y(nxy) – double array
nxy, the dimension of the array, must satisfy the constraint nxy2nxy2.
The nn values of the yy series.
3:     nl – int64int32nag_int scalar
LL, the maximum lag for calculating cross-correlations.
Constraint: 1nl < nxy1nl<nxy.

Optional Input Parameters

1:     nxy – int64int32nag_int scalar
Default: The dimension of the arrays x, y. (An error is raised if these dimensions are not equal.)
nn, the length of the time series.
Constraint: nxy2nxy2.

Input Parameters Omitted from the MATLAB Interface

None.

Output Parameters

1:     s – double scalar
The ratio of the standard deviation of the yy series to the standard deviation of the xx series, sy / sxsy/sx.
2:     r0 – double scalar
The cross-correlation between the xx and yy series at lag zero.
3:     r(nl) – double array
r(l)rl contains the cross-correlations between the xx and yy series at lags LL, rxy(l)rxy(l), for l = 1,2,,Ll=1,2,,L.
4:     stat – double scalar
The statistic for testing for absence of cross-correlation.
5:     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:
  ifail = 1ifail=1
On entry,nxy1nxy1,
ornl < 1nl<1,
ornlnxynlnxy.
  ifail = 2ifail=2
One or both of the xx and yy series have zero variance and hence cross-correlations cannot be calculated.

Accuracy

All computations are believed to be stable.

Further Comments

If n < 100n<100, or L < 10log(n)L<10log(n) then the autocorrelations are calculated directly and the time taken by nag_tsa_multi_xcorr (g13bc) is approximately proportional to nLnL, otherwise the autocorrelations are calculated by utilizing fast Fourier transforms (FFTs) and the time taken is approximately proportional to nlog(n)nlog(n). If FFTs are used then nag_tsa_multi_xcorr (g13bc) internally allocates approximately 6n6n real elements.

Example

function nag_tsa_multi_xcorr_example
x = [0.02;
     0.05;
     0.08;
     0.03;
     -0.05;
     0.11;
     -0.01;
     -0.08;
     -0.08;
     -0.11;
     -0.18;
     -0.19;
     -0.09;
     0.03;
     0.1;
     0.15;
     -0.14;
     0.07;
     0.09;
     0.16];
y = [3.18;
     3.21;
     3.26;
     3.25;
     3.08;
     3.01;
     3.06;
     3.17;
     3.12;
     3.04;
     3.26;
     3.45;
     3.33;
     3.7;
     3.31;
     3.81;
     3.33;
     2.96;
     3.28;
     3.1];
nl = int64(15);
[s, r0, r, stat, ifail] = nag_tsa_multi_xcorr(x, y, nl)
 

s =

    2.0053


r0 =

    0.0568


r =

    0.0438
   -0.3762
   -0.4864
   -0.6294
   -0.3871
   -0.1690
   -0.0678
    0.0962
    0.0788
    0.2910
    0.0950
    0.0547
    0.1855
    0.0243
    0.0034


stat =

   22.1269


ifail =

                    0


function g13bc_example
x = [0.02;
     0.05;
     0.08;
     0.03;
     -0.05;
     0.11;
     -0.01;
     -0.08;
     -0.08;
     -0.11;
     -0.18;
     -0.19;
     -0.09;
     0.03;
     0.1;
     0.15;
     -0.14;
     0.07;
     0.09;
     0.16];
y = [3.18;
     3.21;
     3.26;
     3.25;
     3.08;
     3.01;
     3.06;
     3.17;
     3.12;
     3.04;
     3.26;
     3.45;
     3.33;
     3.7;
     3.31;
     3.81;
     3.33;
     2.96;
     3.28;
     3.1];
nl = int64(15);
[s, r0, r, stat, ifail] = g13bc(x, y, nl)
 

s =

    2.0053


r0 =

    0.0568


r =

    0.0438
   -0.3762
   -0.4864
   -0.6294
   -0.3871
   -0.1690
   -0.0678
    0.0962
    0.0788
    0.2910
    0.0950
    0.0547
    0.1855
    0.0243
    0.0034


stat =

   22.1269


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