public class CrossCorrelation extends Object implements Serializable, Cloneable
CrossCorrelation
estimates the cross-correlation function of
two jointly stationary time series given a sample of n =
x.length
observations {Xt}
and {Yt} for t = 1,2, ..., n.
Let ˆμx=xmean be the estimate of the mean μX of the time series {Xt} where ˆμX={μXforμXknown1nn∑t=1XtforμXunknown
The autocovariance function of {Xt},
σX(k), is estimated by
ˆσX(k)=1nn−k∑t=1(Xt−ˆμX)(Xt+k−ˆμX),\hspace{20pt}k=0,1,\dots,K
where K = maximum_lag
. Note that
ˆσX(0) is
equivalent to the sample variance of x
returned by method
getVarianceX
. The autocorrelation function
ρX(k) is estimated by
ˆρX(k)=ˆσX(k)ˆσX(0),\hspace{20pt}k=0,1,…,K
Note that ˆρx(0)≡1 by definition. Let ˆμY=ymean,ˆσY(k),andˆρY(k) be similarly defined.
The cross-covariance function σXY(k) is estimated by ˆσXY(k)={1nn−k∑t=1(Xt−ˆμX)(Yt+k−ˆμY)k=0,1,…,K1nn∑t=1−k(Xt−ˆμX)(Yt+k−ˆμY)k=−1,−2,…,−K The cross-correlation function ρXY(k) is estimated by ˆρXY(k)=ˆσXY(k)[ˆσX(0)ˆσY(0)]12k=0,±1,…,±K
The standard errors of the sample cross-correlations may be optionally
computed according to the getStandardErrors method argument
stderrMethod
. One method is based on a general
asymptotic expression for the variance of the sample cross-correlation
coefficient of two jointly stationary time series with independent,
identically distributed normal errors given by Bartlet (1978, page 352).
The theoretical formula is var{ˆρXY(k)}=1n−k∞∑i=−∞[ρX(i)+ρXY(i−k)ρXY(i+k)−2ρXY(k){ρX(i)ρXY(i+k)+ρXY(−i)ρY(i+k)}+ρ2XY(k){ρX(i)+12ρ2X(i)+12ρ2Y(i)}]
For computational purposes, the autocorrelations
ρX(k) and ρY(k)
and the cross-correlations ρXY(k)
are replaced by their corresponding estimates for
|k|≤K,
and the limits of summation are equal to zero for all k such that
|k|>K.
A second method evaluates Bartlett's formula under the additional assumption that the two series have no cross-correlation. The theoretical formula is var{ˆρXY(k)}=1n−k∞∑i=−∞ρX(i)ρY(i)k≥0 For additional special cases of Bartlett's formula, see Box and Jenkins (1976, page 377).
An important property of the cross-covariance coefficient is σXY(k)=σYX(−k) for k≥0. This result is used in the computation of the standard error of the sample cross-correlation for lag k<0. In general, the cross-covariance function is not symmetric about zero so both positive and negative lags are of interest.
Modifier and Type | Class and Description |
---|---|
static class |
CrossCorrelation.NonPosVariancesException
The problem is ill-conditioned.
|
Modifier and Type | Field and Description |
---|---|
static int |
BARTLETTS_FORMULA
Indicates standard error computation using Bartlett's formula.
|
static int |
BARTLETTS_FORMULA_NOCC
Indicates standard error computation using Bartlett's formula
with the assumption of no cross-correlation.
|
Constructor and Description |
---|
CrossCorrelation(double[] x,
double[] y,
int maximum_lag)
Constructor to compute the sample cross-correlation
function of two stationary time series.
|
Modifier and Type | Method and Description |
---|---|
double[] |
getAutoCorrelationX()
Returns the autocorrelations of the time series
x . |
double[] |
getAutoCorrelationY()
Returns the autocorrelations of the time series
y . |
double[] |
getAutoCovarianceX()
Returns the autocovariances of the time series
x . |
double[] |
getAutoCovarianceY()
Returns the autocovariances of the time series
y . |
double[] |
getCrossCorrelation()
Returns the cross-correlations between the time series
x
and y . |
double[] |
getCrossCovariance()
Returns the cross-covariances between the time series
x
and y . |
double |
getMeanX()
Returns the mean of the time series
x . |
double |
getMeanY()
Returns the mean of the time series
y . |
double[] |
getStandardErrors(int stderrMethod)
Returns the standard errors of the cross-correlations between the
time series
x and y . |
double |
getVarianceX()
Returns the variance of time series
x . |
double |
getVarianceY()
Returns the variance of time series
y . |
void |
setMeanX(double mean)
Estimate of the mean of time series
x . |
void |
setMeanY(double mean)
Estimate of the mean of time series
y . |
public static final int BARTLETTS_FORMULA
public static final int BARTLETTS_FORMULA_NOCC
public CrossCorrelation(double[] x, double[] y, int maximum_lag)
x
- A one-dimensional double
array containing the first stationary
time series.y
- A one-dimensional double
array containing the second stationary
time series.maximum_lag
- An int
containing
the maximum lag of the cross-covariance and
cross-correlations to be computed.
maximum_lag
must be greater
than or equal to 1 and less than the minimum
of the number of observations of x
and y
.public void setMeanX(double mean)
x
.mean
- A double
containing the
estimate mean of the time series x
.public double getMeanX()
x
.double
containing the mean
of the time series x
.public void setMeanY(double mean)
y
.mean
- A double
containing the
estimate mean of the time series y
.public double getMeanY()
y
.double
containing the mean
of the time series y
.public double getVarianceX() throws CrossCorrelation.NonPosVariancesException
x
.double
containing the variance
of the time series x
.CrossCorrelation.NonPosVariancesException
public double getVarianceY() throws CrossCorrelation.NonPosVariancesException
y
.double
containing the variance
of the time series y
.CrossCorrelation.NonPosVariancesException
public double[] getCrossCorrelation() throws CrossCorrelation.NonPosVariancesException
x
and y
.double
array of length 2 * maximum_lag
+1
containing the cross-correlations between the time series x
and y
. The cross-correlation between x
and
y
at lag k, where k = -maximum_lag
,..., 0, 1,...,maximum_lag
, corresponds to output array indices
0, 1,..., (2*maximum_lag)
.CrossCorrelation.NonPosVariancesException
public double[] getCrossCovariance()
x
and y
.double
array of length 2 * maximum_lag
+1
containing the cross-covariances between the time series x
and y
. The cross-covariance between x
and
y
at lag k, where k = -maximum_lag
,..., 0, 1,...,maximum_lag
, corresponds to output array indices
0, 1,..., (2*maximum_lag)
.public double[] getAutoCorrelationX() throws CrossCorrelation.NonPosVariancesException
x
.double
array of length maximum_lag
+1
containing the autocorrelations of the time series x
.
The 0-th element of this array is 1. The k-th element of this array
contains the autocorrelation of lag k where
k = 1, ..., maximum_lag
.CrossCorrelation.NonPosVariancesException
public double[] getAutoCorrelationY() throws CrossCorrelation.NonPosVariancesException
y
.double
array of length maximum_lag
+1
containing the autocorrelations of the time series y
.
The 0-th element of this array is 1. The k-th element of this array
contains the autocorrelation of lag k where
k = 1, ..., maximum_lag
.CrossCorrelation.NonPosVariancesException
public double[] getAutoCovarianceX() throws CrossCorrelation.NonPosVariancesException
x
.double
array of length maximum_lag
+1
containing the variances and autocovariances of the time series x
.
The 0-th element of the array contains the variance of the time series
x
. The k-th element contains the autocovariance of lag k
where k = 1, ..., maximum_lag
.CrossCorrelation.NonPosVariancesException
public double[] getAutoCovarianceY() throws CrossCorrelation.NonPosVariancesException
y
.double
array of length maximum_lag
+1
containing the variances and autocovariances of the time series y
.
The 0-th element of the array contains the variance of the time series
x
. The k-th element contains the autocovariance of lag k
where k = 1, ..., maximum_lag
.CrossCorrelation.NonPosVariancesException
public double[] getStandardErrors(int stderrMethod) throws CrossCorrelation.NonPosVariancesException
x
and y
. Method of computation for
standard errors of the cross-correlation is determined by the
stderrMethod
parameter. If stderrMethod
is set to BARTLETTS_FORMULA, Bartlett's formula is used to compute the
standard errors of cross-correlations. If
stderrMethod
is set to BARTLETTS_FORMULA_NOCC, Bartlett's
formula is used to compute the standard errors of
cross-correlations, with the assumption of no cross-correlation.stderrMethod
- An int
specifying the
method to compute the standard errors of
cross-correlations between the time series x
and y
.double
array of length 2 * maximum_lag
+ 1
containing the standard errors of the cross-correlations between the
time series x
and y
. The standard error of
cross-correlations between x
and y
at lag
k, where k = -maximum_lag
,..., 0, 1,...,
maximum_lag
, corresponds to output array indices
0, 1,..., (2*maximum_lag)
.CrossCorrelation.NonPosVariancesException
Copyright © 2020 Rogue Wave Software. All rights reserved.