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 values of the series.
- y
- Type: array<System..::..Double>[]()[][]An array of size [nxy]On entry: the values of the series.
- nxy
- Type: System..::..Int32On entry: , the length of the time series.Constraint: .
- nl
- Type: System..::..Int32On entry: , the maximum lag for calculating cross-correlations.Constraint: .
- s
- Type: System..::..Double%On exit: the ratio of the standard deviation of the series to the standard deviation of the series, .
- r0
- Type: System..::..Double%On exit: the cross-correlation between the and series at lag zero.
- r
- Type: array<System..::..Double>[]()[][]An array of size [nl]On exit: contains the cross-correlations between the and series at lags , , for .
- stat
- Type: System..::..Double%On exit: the statistic for testing for absence of cross-correlation.
- ifail
- Type: System..::..Int32%On exit: unless the method detects an error or a warning has been flagged (see [Error Indicators and Warnings]).
Description
Given two series and the method calculates the cross-correlations between and lagged values of :
where
and similarly for .
The ratio of standard deviations is also returned, and a portmanteau statistic is calculated:
Provided is large, much less than , and both 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 -distribution with 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:
On entry, , or , or .
- One or both of the and series have zero variance and hence cross-correlations cannot be calculated.
Accuracy
All computations are believed to be stable.
Parallelism and Performance
None.
Further Comments
If , or then the autocorrelations are calculated directly and the time taken by g13bc is approximately proportional to , otherwise the autocorrelations are calculated by utilizing fast Fourier transforms (FFTs) and the time taken is approximately proportional to . If FFTs are used then g13bc internally allocates approximately real elements.
Example
This example reads two time series of length . It calculates and prints the cross-correlations up to lag for the first series leading the second series and then for the second series leading the first series.
Example program (C#): g13bce.cs