public class VectorAutoregression extends Object implements Serializable, Cloneable
This class contains methods for modeling multivariate time series of the form Yt=(y1t,y2t,…,yKt)⊤ where each yit,i=1,…,K,t=…,−2,−1,0,1,2,… is a real-valued time series indexed by t. Define the K dimensional mean process μt=E[Yt]=(E[y1t],…,E[yKt])⊤ and the cross-covariance matrix Σt,h=Cov(Yt,Yt+h) where for each (t,h), Σt,h is a K * K real-valued matrix whose (i,j)t,h element is the covariance between yit,yj(t+h): Cov(yit,yj(t+h))=E[(yit−μit)(yj(t+h)−μj(t+h))].
The vector autoregressive model, or VAR, has a number of equivalent forms. A general form is A(L)(Yt−μt)=ut+DXt where A(L)=A0+A1L+A2L2+…+ApLp is a p-th degree matrix polynomial in the lag or backshift operator, L. Note that p is the specified autoregressive lag and ut is the error process. The error process is assumed to be a K dimensional white noise series, with E[ut]=0 and nonsingular covariance matrix, Σu, which is constant over time. The coefficient matrices Aj,j=0,…,p are K * K matrices containing the coefficients of the model. The matrix Xt represents a matrix of deterministic terms such as trend or seasonal variables, and D represents the associated coefficient matrix of Xt.
Constructor and Description |
---|
VectorAutoregression(TimeSeries ts)
Constructor for the class.
|
Modifier and Type | Method and Description |
---|---|
double[] |
getARConstants()
Returns the current settings of the constants used in the autoregression
model.
|
int[] |
getARModel()
Returns the autoregressive model configuration.
|
double[][] |
getEstimates()
Returns the parameter estimates (coefficients) of the vector
autoregression model.
|
double[][] |
getForecasts()
Returns the h-step ahead forecast at times
t=nT, nT+1, ..., T, where
h=1,2, ...,
maxStepsAhead . |
boolean |
isA0Flag()
Returns the state of
A0Flag . |
void |
setA0Flag(boolean A0Flag)
Sets the flag to include the leading autoregressive coefficient matrix in
the model.
|
void |
setARConstants(double[] arConstants)
Sets the constants for the autoregressive model.
|
void |
setARLag(int arLag)
Sets the autoregressive lag parameter.
|
void |
setARModel(int[] arModel)
Sets the form of the autoregressive terms of the model.
|
void |
setCenter(boolean center)
Sets the flag to center the data.
|
void |
setMaxLag(int maxLag)
Sets the maximum lag.
|
void |
setScale(boolean scale)
Sets the flag to scale the data.
|
void |
setTrend(boolean trend)
Sets the flag to fit a trend parameter in the model.
|
public VectorAutoregression(TimeSeries ts)
ts
- a TimeSeries
object.public void setA0Flag(boolean A0Flag)
When true
, a nontrivial, lower-triangular leading
autoregressive coefficient matrix, A0, will be
estimated in the model. When false
, A0
is the constant identity matrix, which is also the default case.
A0Flag
- boolean
indicating whether to fit the leading
coefficient matrix.
Default: A0Flag
=false
.
public boolean isA0Flag()
A0Flag
.boolean
which specifies whether or not the leading
coefficient matrix is nontrivial.public void setARLag(int arLag)
maxLag
.arLag
- an int
specifying the desired lag for the
autoregressive terms.
Default: arLag
=1.public double[] getARConstants()
double
array containing the constants used in the
autoregression model. If the value is null
, the default
values are active.public void setARConstants(double[] arConstants)
VectorAutoregression.setARModel(int[])
.arConstants
- a double
array specifying the
autoregressive model constants
The input array arConstants
must be of length
(A0Flag
+arLag
)*K*K,
such that for indices 1=0,...,(A0Flag
+ arLag
),
i=0,...,K-1, and
j=0,...,K-1, arConstants[
l*K*K +i*K +
j]
specifies a constant value for parameter
aij,l.
arConstants[
i]
=0.public int[] getARModel()
int
array specifying the autoregressive
configuration. If null
, then all parameters are active in
the current model.public void setARModel(int[] arModel)
Without loss of generality, assume that the series mean is 0 and that there are no deterministic terms. Then we can write the vector autoregression model of lag p as A0Yt+A1Yt−1+⋯+ApYt−p=ut.Each of the matrices Aj represents K * K unknown coefficients. In practice, many of the (p+ 1) * K * K coefficients are restricted to be 0 or otherwise constant. The leading coefficient matrix A0 must be lower-triangular and is very often equal to the identity matrix (this is the default behavior). Fully expanded the model looks like K equations in K(p+1) unknowns. Yt,k=K∑j=1akj,0Yt,j+p∑l=1K∑j=1akj,lYt−l,k Consider each coefficient matrix as the vector vec(Al)=(a11,l,a21,l,…,aK1,l,a12,l,a22,l,…,aK2,l,⋯,a1K,l,a2K,l,…,aKK,l)T for l=0,…,p. vec(Al) is just the columns of Al appended to each other. To specify a configuration different from the default, append the vectorized coefficient matrices as vec(A1,A2,…,Ap) or vec(A0,A1,…,Ap) when including a nontrivial leading coefficient matrix. Set the value at index l*K*K + j*K + i to 1 or -1 to fit aij,l or −aij,l in the model. Set the value to 0 to exclude aij,l as a parameter. Note that for the leading coefficient matrix,l= 0, the value at j*K + i is ignored unless i is at least j, i.e., only the lower triangle of A0 can be nontrivial.
arModel
- an int
array specifying the autoregressive
model parameters.
For indices
l=0,...,(A0Flag
+arLag
),
i=0,...,K-1, and j=0,...,K-1,
arModel[
l*K*K +i*K + j]
= {-1,1}
indicates that the coefficient ±aij,l
is a parameter (to be estimated) in the model.
Default: A0 is the identity matrix and
arModel[
i]
=1 for all i.
public void setCenter(boolean center)
center
=true
, column means are subtracted from
the data.center
- a boolean
indicating whether or not column
means should be subtracted from the data.
Default: center
=false
.
public void setMaxLag(int maxLag)
maxLag
- an int
specifying the maximum lag to consider
in the first (pure VAR) stage regression.public void setScale(boolean scale)
If scale
=true
, the data values are
mean-centered and then divided by the standard deviation.
scale
- a boolean
Default: scale
=false
.
public void setTrend(boolean trend)
true
to include a deterministic trend in the model.trend
- a boolean
specifying whether or not to include
a deterministic trend.
Default: trend
=false
.
public double[][] getEstimates()
double
array containing the estimated parameters
(coefficients).public double[][] getForecasts()
maxStepsAhead
.
The h-step ahead forecast ˆYt+h=E[Yt+h|Ys,0≤s≤t] uses the conditional expectation of Yt+h given the historical information known at time t. The estimated VAR model approximates the conditional expectation and the forecasts are generated from the estimated VAR model via the following recursion: ˆYt+h=p∑j=1ˆAjˆYt+h−j+δ where Y=(Y1,...,YK)T is the vector time series and δ=(I−ˆA1−ˆA2−⋯−ˆAp)μ.
double
matrix T-nT by
maxStepsAhead
* K containing the forecasts.
Note that the forecast ^Ykt+h is stored in location [t-nT][(h-1)*K + k] of the returned forecast matrix.
Copyright © 2020 Rogue Wave Software. All rights reserved.