multiCrosscorrelation

../../_images/OpenMp_27.png

Computes the multichannel cross-correlation function of two mutually stationary multichannel time series.

Synopsis

multiCrosscorrelation (x, y, lagmax)

Required Arguments

float x[[]] (Input)
Array of length nObservationsX by nChannelX containing the first time series.
float y[[]] (Input)
Array of length nObservationsY by nChannelY containing the second time series.
int lagmax (Input)
Maximum lag of cross-covariances and cross-correlations to be computed. lagmax must be greater than or equal to one and less than the minimum of nObservationsX and nObservationsY.

Return Value

An array of length nChannelX× nChannelY × (2 × lagmax + 1) containing the cross-correlations between the channels of x and y. The m-th element of this array contains the cross-correlation between channel i of the x series and channel j of the y series at lag (k-lagmax) where

i = 1, …, nChannelX

j = 1, …, nChannelY

k = 0, 1, …, 2*lagmax, and

m = (nChannelX * nChannelY*k +(i*nChannelX+ j))

To release this space, use free. If no solution can be computed, None is return.

Optional Arguments

printLevel, int (Input)

Printing option.

printLevel Action
0 No printing is performed.
1 Prints the means and variances.
2 Prints the means, variances, and cross-covariances.
3 Prints the means, variances, cross-covariances, and cross-correlations.

Default = 0.

inputMeans, float xMeanIn, float yMeanIn (Input)
If specified, xMeanIn is an array of length nChannelX containing the user input of the estimate of the means of the channels of x and yMeanIn is an array of length nChannelY containing the user input of the estimate of the means of the channels of y.
outputMeans, xMeanOut, yMeanOut (Output)
If specified, xMeanOut is an array of length nChannelX containing the means of the channels of x and yMeanOut is an array of length nChannelY containing the means of the channels of y.
variances, xVariance, yVariance (Output)
If specified, xVariance is an array of length nChannelX containing the variances of the channels of x and yVariance is an array of length nChannelY containing the variances of the channels of y.
crossCovariances (Output)

An array of length nChannelX × nChannelY × (2×lagmax + 1) containing the cross-covariances between the channels of x and y. The mth element of this array contains the cross-covariance between channel i of the x series and channel j of the y series at lag (klagmax) where

i = 1, …, nChannelX

j = 1, …, nChannelY

k = 0, 1, …, 2*lagmax, and

m = (nChannelX * nChannelY*k +(i*nChannelX+ j)).

Description

Function multiCrosscorrelation estimates the multichannel cross-correlation function of two mutually stationary multichannel time series. Define the multichannel time series X by

X=(X1,X2,...,Xp)

where

Xj=(X1j,X2j,...,Xnj)T,j=1,2,...,p

with n = nObservationsX and p = nChannelX. Similarly, define the multichannel time series Y by

Y=(Y1,Y2,...,Yq)

where

Yj=(Y1j,Y2j,...,Ymj)T,j=1,2,...,q

with m = nObservationsY and q = nChannelY. The columns of X and Y correspond to individual channels of multichannel time series and may be examined from a univariate perspective. The rows of X and Y correspond to observations of p-variate and q-variate time series, respectively, and may be examined from a multivariate perspective. Note that an alternative characterization of a multivariate time series X considers the columns to be observations of the multivariate time series while the rows contain univariate time series. For example, see Priestley (1981, page 692) and Fuller (1976, page 14).

Let ˆμX be the row vector containing the means of the channels of X. In particular,

ˆμX=(ˆμX1,ˆμX2,,ˆμXp)

where for j=1,2,,p

ˆμXj={μXjμXj known (xMeanIn)1nnt=1XtjμXj unknown (xMeanOut)

Let ˆμY be similarly defined for the means of the channels of Y. The cross-covariance of lag k between channel i of X and channel j of Y is estimated by

ˆσXiYj(k)={1Nt(XtiˆμXi)(Yt+k,jˆμYj)k=0,1,,K1Nt(XtiˆμXi)(Yt+k,jˆμYj)k=1.2,,K

where i=1,,p, j=1,,q, and K = lagmax. The summation on t extends over all possible cross-products with N equal to the number of cross-products in the sum

Let

ˆσX(0)=xVariance

be the row vector consisting of the estimated variances of the channels of X. In particular,

ˆσX(0)=(ˆσX1(0),ˆσX2(0),,ˆσXp(0))

where

ˆσXj(0)=1nnt=1(XtjˆμXj)2...j=1,2,,p

Let

ˆσY(0)=yVariance

be similarly defined. The cross-correlation of lag k between channel i of X and channel j of Y is estimated by

ˆρXiYj(k)=ˆσXiYj(k)[ˆσXi(0)ˆσYj(0)]1/2...k=0,±1,,±K

Example

Consider the Wolfer Sunspot Data (Y) (Box and Jenkins 1976, page 530) along with data on northern light activity (X1) and earthquake activity (X2) (Robinson 1967, page 204) to be a three-channel time series. Function multiCrosscorrelation is used to compute the cross-covariances and cross-correlations between X1 and Y and between X2 and Y with lags from −10 through 10.

from __future__ import print_function
from numpy import *
from pyimsl.stat.dataSets import dataSets
from pyimsl.stat.multiCrosscorrelation import multiCrosscorrelation
from pyimsl.stat.writeMatrix import writeMatrix

x = empty((100, 2))
y = empty(100)
nchanx = 2
nchany = 1
lagmax = 10
xyvar = {}
xymeans = {}
ccv = []

data = dataSets(8, xColDim=4)
for i in range(0, 100):
    y[i] = data[i, 1]
    x[i, 0] = data[i, 2]
    x[i, 1] = data[i, 3]

result = multiCrosscorrelation(x, y, lagmax,
                               variances=xyvar,
                               outputMeans=xymeans,
                               crossCovariances=ccv)

writeMatrix("Channel means of x", xymeans['xMeanOut'])
writeMatrix("Channel variances of x", xyvar['xVariance'])
writeMatrix("Channel means of y", xymeans['yMeanOut'])
writeMatrix("Channel variances of y", xyvar['yVariance'])
print("\nMultichannel cross-covariance between x and y")
for i in range(0, 2 * lagmax + 1):
    print("Lag K = %d" % (i - lagmax))
    for j in range(0, nchanx):
        print("    %i   %8.1f" % (j, ccv[nchanx * nchany * i + j]))
print("\nMultichannel cross-correlation between x and y")
for i in range(0, 2 * lagmax + 1):
    print("Lag K = %d" % (i - lagmax))
    for j in range(0, nchanx):
        print("    %i   %8.4f" % (j, result[nchanx * nchany * i + j]))

Output

Multichannel cross-covariance between x and y
Lag K = -10
    0      -20.5
    1       70.7
Lag K = -9
    0       65.0
    1       38.1
Lag K = -8
    0      216.6
    1      135.6
Lag K = -7
    0      246.8
    1      100.4
Lag K = -6
    0      142.1
    1       45.0
Lag K = -5
    0       50.7
    1      -11.8
Lag K = -4
    0       72.7
    1       32.7
Lag K = -3
    0      217.9
    1      -40.1
Lag K = -2
    0      355.8
    1     -152.6
Lag K = -1
    0      579.7
    1     -213.0
Lag K = 0
    0      821.6
    1     -104.8
Lag K = 1
    0      810.1
    1       55.2
Lag K = 2
    0      628.4
    1       84.8
Lag K = 3
    0      438.3
    1       76.0
Lag K = 4
    0      238.8
    1      200.4
Lag K = 5
    0      143.6
    1      283.0
Lag K = 6
    0      253.0
    1      234.4
Lag K = 7
    0      479.5
    1      223.0
Lag K = 8
    0      724.9
    1      124.5
Lag K = 9
    0      925.0
    1      -79.5
Lag K = 10
    0      922.8
    1     -279.3

Multichannel cross-correlation between x and y
Lag K = -10
    0    -0.0107
    1     0.0427
Lag K = -9
    0     0.0340
    1     0.0230
Lag K = -8
    0     0.1133
    1     0.0819
Lag K = -7
    0     0.1290
    1     0.0607
Lag K = -6
    0     0.0743
    1     0.0272
Lag K = -5
    0     0.0265
    1    -0.0071
Lag K = -4
    0     0.0380
    1     0.0198
Lag K = -3
    0     0.1139
    1    -0.0242
Lag K = -2
    0     0.1860
    1    -0.0923
Lag K = -1
    0     0.3031
    1    -0.1287
Lag K = 0
    0     0.4296
    1    -0.0633
Lag K = 1
    0     0.4236
    1     0.0333
Lag K = 2
    0     0.3285
    1     0.0512
Lag K = 3
    0     0.2291
    1     0.0459
Lag K = 4
    0     0.1248
    1     0.1211
Lag K = 5
    0     0.0751
    1     0.1710
Lag K = 6
    0     0.1323
    1     0.1417
Lag K = 7
    0     0.2507
    1     0.1348
Lag K = 8
    0     0.3790
    1     0.0752
Lag K = 9
    0     0.4836
    1    -0.0481
Lag K = 10
    0     0.4825
    1    -0.1688
 
   Channel means of x
          1            2
      63.43        97.97
 
 Channel variances of x
          1            2
       2644         1978
 
Channel means of y
          46.94
 
Channel variances of y
             1384