NAG CL Interface
g13bcc (multi_​xcorr)

Settings help

CL Name Style:


1 Purpose

g13bcc calculates cross-correlations between two time series.

2 Specification

#include <nag.h>
void  g13bcc (const double x[], const double y[], Integer nxy, Integer nl, double *s, double *r0, double r[], double *stat, NagError *fail)
The function may be called by the names: g13bcc, nag_tsa_multi_xcorr or nag_tsa_cross_corr.

3 Description

Given two series x1,x2,,xn and y1,y2,,yn the function calculates the cross-correlations between xt and lagged values of yt:
rxy(l)=t=1 n-l(xt-x¯)(yt+l-y¯) nsxsy ,  l=0,1,,L  
where
x¯=t= 1nxtn  
sx2=t=1n (xt-x¯) 2n  
and similarly for y.
The ratio of standard deviations sy/sx is also returned, and a portmanteau statistic is calculated:
stat=nl=1Lrxy (l) 2.  
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.

4 References

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

5 Arguments

1: x[nxy] const double Input
On entry: the n values of the x series.
2: y[nxy] const double Input
On entry: the n values of the y series.
3: nxy Integer Input
On entry: n, the length of the time series.
Constraint: nxy2.
4: nl Integer Input
On entry: L, the maximum lag for calculating cross-correlations.
Constraint: 1nl<nxy.
5: s double * Output
On exit: the ratio of the standard deviation of the y series to the standard deviation of the x series, sy/sx.
6: r0 double * Output
On exit: the cross-correlation between the x and y series at lag zero.
7: r[nl] double Output
On exit: r[l-1] contains the cross-correlations between the x and y series at lags L, rxy(l), for l=1,2,,L.
8: stat double * Output
On exit: the statistic for testing for absence of cross-correlation.
9: fail NagError * Input/Output
The NAG error argument (see Section 7 in the Introduction to the NAG Library CL Interface).

6 Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 3.1.2 in the Introduction to the NAG Library CL Interface for further information.
NE_BAD_PARAM
On entry, argument value had an illegal value.
NE_INT
On entry, nl=value.
Constraint: nl1.
On entry, nxy=value.
Constraint: nxy>1.
NE_INT_2
On entry, nl=value and nxy=value.
Constraint: 1nl<nxy.
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
See Section 7.5 in the Introduction to the NAG Library CL Interface for further information.
NE_NO_LICENCE
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library CL Interface for further information.
NE_ZERO_VARIANCE
One or both of the x and y series have zero variance.

7 Accuracy

All computations are believed to be stable.

8 Parallelism and Performance

g13bcc is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
g13bcc makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
Please consult the X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this function. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

9 Further Comments

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

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

10.1 Program Text

Program Text (g13bcce.c)

10.2 Program Data

Program Data (g13bcce.d)

10.3 Program Results

Program Results (g13bcce.r)