multiCrosscorrelation¶
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
nObservationsXbynChannelXcontaining the first time series. - float
y[[]](Input) - Array of length
nObservationsYbynChannelYcontaining the second time series. - int
lagmax(Input) - Maximum lag of cross-covariances and cross-correlations to be computed.
lagmaxmust be greater than or equal to one and less than the minimum ofnObservationsXandnObservationsY.
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, …,
nChannelXj = 1, …,
nChannelYk = 0, 1, …, 2*
lagmax, andm = (
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.
printLevelAction 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, floatxMeanIn,floatyMeanIn(Input)- If specified,
xMeanInis an array of lengthnChannelXcontaining the user input of the estimate of the means of the channels ofxandyMeanInis an array of lengthnChannelYcontaining the user input of the estimate of the means of the channels ofy. outputMeans,xMeanOut,yMeanOut(Output)- If specified,
xMeanOutis an array of lengthnChannelXcontaining the means of the channels ofxandyMeanOutis an array of lengthnChannelYcontaining the means of the channels ofy. variances,xVariance,yVariance(Output)- If specified,
xVarianceis an array of lengthnChannelXcontaining the variances of the channels ofxandyVarianceis an array of lengthnChannelYcontaining the variances of the channels ofy. crossCovariances(Output)An array of length
nChannelX×nChannelY× (2×lagmax+ 1) containing the cross-covariances between the channels ofxandy. The mth element of this array contains the cross-covariance between channel i of thexseries and channel j of theyseries at lag (k−lagmax) wherei = 1, …,
nChannelXj = 1, …,
nChannelYk = 0, 1, …, 2*
lagmax, andm = (
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
where
with n = nObservationsX and p = nChannelX. Similarly, define the
multichannel time series Y by
where
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 \(\hat{\mu}_X\) be the row vector containing the means of the channels of X. In particular,
where for \(j=1,2,\ldots,p\)
Let \(\hat{\mu}_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
where \(i=1,\ldots,p\), \(j=1,\ldots,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
be the row vector consisting of the estimated variances of the channels of X. In particular,
where
Let
be similarly defined. The cross-correlation of lag k between channel i of X and channel j of Y is estimated by
Example¶
Consider the Wolfer Sunspot Data (Y) (Box and Jenkins 1976, page 530)
along with data on northern light activity (\(X_1\)) and earthquake
activity (\(X_2\)) (Robinson 1967, page 204) to be a three-channel time
series. Function multiCrosscorrelation is used to compute the
cross-covariances and cross-correlations between \(X_1\) and Y and
between \(X_2\) 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