g13bc calculates cross-correlations between two time series.

Syntax

C#
public static void g13bc(
	double[] x,
	double[] y,
	int nxy,
	int nl,
	out double s,
	out double r0,
	double[] r,
	out double stat,
	out int ifail
)
Visual Basic
Public Shared Sub g13bc ( _
	x As Double(), _
	y As Double(), _
	nxy As Integer, _
	nl As Integer, _
	<OutAttribute> ByRef s As Double, _
	<OutAttribute> ByRef r0 As Double, _
	r As Double(), _
	<OutAttribute> ByRef stat As Double, _
	<OutAttribute> ByRef ifail As Integer _
)
Visual C++
public:
static void g13bc(
	array<double>^ x, 
	array<double>^ y, 
	int nxy, 
	int nl, 
	[OutAttribute] double% s, 
	[OutAttribute] double% r0, 
	array<double>^ r, 
	[OutAttribute] double% stat, 
	[OutAttribute] int% ifail
)
F#
static member g13bc : 
        x : float[] * 
        y : float[] * 
        nxy : int * 
        nl : int * 
        s : float byref * 
        r0 : float byref * 
        r : float[] * 
        stat : float byref * 
        ifail : int byref -> unit 

Parameters

x
Type: array<System..::..Double>[]()[][]
An array of size [nxy]
On entry: the n values of the x series.
y
Type: array<System..::..Double>[]()[][]
An array of size [nxy]
On entry: the n values of the y series.
nxy
Type: System..::..Int32
On entry: n, the length of the time series.
Constraint: nxy2.
nl
Type: System..::..Int32
On entry: L, the maximum lag for calculating cross-correlations.
Constraint: 1nl<nxy.
s
Type: System..::..Double%
On exit: the ratio of the standard deviation of the y series to the standard deviation of the x series, sy/sx.
r0
Type: System..::..Double%
On exit: the cross-correlation between the x and y series at lag zero.
r
Type: array<System..::..Double>[]()[][]
An array of size [nl]
On exit: r[l-1] contains the cross-correlations between the x and y series at lags L, rxyl, for l=1,2,,L.
stat
Type: System..::..Double%
On exit: the statistic for testing for absence of cross-correlation.
ifail
Type: System..::..Int32%
On exit: ifail=0 unless the method detects an error or a warning has been flagged (see [Error Indicators and Warnings]).

Description

Given two series x1,x2,,xn and y1,y2,,yn the method calculates the cross-correlations between xt and lagged values of yt:
rxyl=t=1n-lxt-x-yt+l-y-nsxsy,  l=0,1,,L
where
x-=t=1nxtn
sx2=t=1nxt-x-2n
and similarly for y.
The ratio of standard deviations sy/sx is also returned, and a portmanteau statistic is calculated:
stat=nl=1Lrxyl2.
Provided n is large, L much less than n, and both xt,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-distribution with L 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

Error Indicators and Warnings

Errors or warnings detected by the method:
ifail=1
On entry,nxy1,
ornl<1,
ornlnxy.
ifail=2
One or both of the x and y series have zero variance and hence cross-correlations cannot be calculated.
ifail=-9000
An error occured, see message report.
ifail=-8000
Negative dimension for array value
ifail=-6000
Invalid Parameters value

Accuracy

All computations are believed to be stable.

Parallelism and Performance

None.

Further Comments

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

Example

This example reads two time series of length 20. It calculates and prints the cross-correlations up to lag 15 for the first series leading the second series and then for the second series leading the first series.

Example program (C#): g13bce.cs

Example program data: g13bce.d

Example program results: g13bce.r

See Also