public class AutoCorrelation extends Object implements Serializable, Cloneable
AutoCorrelation
estimates the autocorrelation function
of a stationary time series given a sample of n observations
{Xt} for
t=1,2,…,n.
Let ˆμ=xmean be the estimate of the mean μ of the time series {Xt} where
ˆμ={μforμknown1nn∑t=1Xtforμunknown The autocovariance function σ(k) is estimated by ˆσ(k)=1nn−k∑t=1(Xt−ˆμ)(Xt+k−ˆμ), k=0,1,…,Kwhere K = maximum_lag
. Note that ˆσ(0) is an estimate of the sample variance. The
autocorrelation function ρ(k) is estimated by
ˆρ(k)=ˆσ(k)ˆσ(0), k=0,1,…,K
Note that ˆρ(0)≡1 by definition.
The standard errors of sample autocorrelations may be optionally
computed according to the getStandardErrors method argument
stderrMethod
. One method (Bartlett 1946) is based on a
general asymptotic expression for the variance of the sample
autocorrelation coefficient of a stationary time series with
independent, identically distributed normal errors. The theoretical
formula is
var{ˆρ(k)}=1n∞∑i=−∞[ρ2(i)+ρ(i−k)ρ(i+k)−4ρ(i)ρ(k)ρ(i−k)+2ρ2(i)ρ2(k)]
where ˆρ(k) assumes μ is unknown. For computational purposes, the autocorrelations ρ(k) are replaced by their estimates ˆρ(k) for |k|≤K, and the limits of summation are bounded because of the assumption that ρ(k)=0 for all k such that |k|>K.
A second method (Moran 1947) utilizes an exact formula for the variance of the sample autocorrelation coefficient of a random process with independent, identically distributed normal errors. The theoretical formula is
var{ˆρ(k)}=n−kn(n+2)
where μ is assumed to be equal to zero. Note that this formula does not depend on the autocorrelation function.
The method getPartialAutoCorrelations
estimates the
partial autocorrelations of the stationary time series given K =
maximum_lag
sample autocorrelations ˆρ(k) for k=0,1,...,K. Consider the AR(k)
process defined by Xt=ϕk1Xt−1+ϕk2Xt−2+⋯+ϕkkXt−k+At where ϕkj denotes the j-th
coefficient in the process. The set of estimates {ˆϕkk} for k = 1, ..., K is the sample partial
autocorrelation function. The autoregressive parameters
{ˆϕkj} for j = 1, ..., k
are approximated by Yule-Walker estimates for successive AR(k)
models where k = 1, ..., K. Based on the sample Yule-Walker
equations
ˆρ(j)=ˆϕk1ˆρ(j−1)+ˆϕk2ˆρ(j−2)+⋯+ˆϕkkˆρ(j−k), j=1,2,…,k
a recursive relationship for k=1, ..., K was developed by Durbin
(1960). The equations are given by
This procedure is sensitive to rounding error and should not be used if the parameters are near the nonstationarity boundary. A possible alternative would be to estimate {ϕkk} for successive AR(k) models using least or maximum likelihood. Based on the hypothesis that the true process is AR(p), Box and Jenkins (1976, page 65) note
var{ˆϕkk}≃1nk≥p+1See Box and Jenkins (1976, pages 82-84) for more information concerning the partial autocorrelation function.
Modifier and Type | Class and Description |
---|---|
static class |
AutoCorrelation.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 |
MORANS_FORMULA
Indicates standard error computation using Moran's formula.
|
Constructor and Description |
---|
AutoCorrelation(double[] x,
int maximum_lag)
Constructor to compute the sample autocorrelation function of a
stationary time series.
|
Modifier and Type | Method and Description |
---|---|
double[] |
getAutoCorrelations()
Returns the autocorrelations of the time series
x . |
double[] |
getAutoCovariances()
Returns the variance and autocovariances of the time series
x . |
double |
getMean()
Returns the mean of the time series
x . |
int |
getNumberOfThreads()
Returns the number of
java.lang.Thread instances used for
parallel processing. |
double[] |
getPartialAutoCorrelations()
Returns the sample partial autocorrelation function of the stationary
time series
x . |
double[] |
getStandardErrors(int stderrMethod)
Returns the standard errors of the autocorrelations of the time series
x . |
double |
getVariance()
Returns the variance of the time series
x . |
void |
setMean(double mean)
Estimate mean of the time series
x . |
void |
setNumberOfThreads(int numberOfThreads)
Sets the number of
java.lang.Thread instances to be used for
parallel processing. |
public static final int BARTLETTS_FORMULA
public static final int MORANS_FORMULA
public AutoCorrelation(double[] x, int maximum_lag)
x
- a one-dimensional double
array containing the
stationary time seriesmaximum_lag
- an int
containing the maximum lag of
autocovariance, autocorrelations, and standard
errors of autocorrelations to be computed.
maximum_lag
must be greater than or
equal to 1 and less than the number of observations
in x
public void setNumberOfThreads(int numberOfThreads)
java.lang.Thread
instances to be used for
parallel processing.numberOfThreads
- an int
specifying the number of
java.lang.Thread
instances to be used for parallel
processing.
Default: numberOfThreads
= 1.
public int getNumberOfThreads()
java.lang.Thread
instances used for
parallel processing.int
containing the number of
java.lang.Thread
instances used for parallel processing.public void setMean(double mean)
x
.mean
- a double
containing the estimate mean of
the time series x
.public double getMean()
x
.double
containing the meanpublic double[] getStandardErrors(int stderrMethod)
x
. Method of computation for standard errors of the
autocorrelation is chosen by the stderrMethod
parameter. If
stderrMethod
is set to BARTLETTS_FORMULA
,
Bartlett's formula is used to compute the standard errors of
autocorrelations. If stderrMethod
is set to
MORANS_FORMULA
, Moran's formula is used to compute the
standard errors of autocorrelations.stderrMethod
- an int
specifying the method to
compute the standard errors of autocorrelations
of the time series x
double
array of length maximum_lag
containing the standard errors of the autocorrelations of the
time series x
public double[] getAutoCorrelations()
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
.public double[] getAutoCovariances() throws AutoCorrelation.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
.AutoCorrelation.NonPosVariancesException
- is thrown if the problem is
ill-conditionedpublic double getVariance()
x
.double
containing the variance of the time series
x
public double[] getPartialAutoCorrelations()
x
.double
array of length maximum_lag
containing the partial autocorrelations of the time series
x
.Copyright © 2020 Rogue Wave Software. All rights reserved.