public class VectorAutoregression extends Object implements Serializable, Cloneable
This class contains methods for modeling multivariate time series of the form $$Y_t=(y_{1t}, y_{2t},\ldots,y_{Kt})^\top $$ where each $$y_{it}, i=1,\ldots,K, t =\ldots, -2, -1, 0, 1, 2,\ldots $$ is a real-valued time series indexed by t. Define the K dimensional mean process $$\mu_t=E[Y_t]=(E[y_{1t}],\ldots,E[y_{Kt}])^\top $$ and the cross-covariance matrix $$\Sigma_{t,h}=\text{Cov}(Y_t,Y_{t+h}) $$ where for each (t,h), \(\Sigma_{t,h}\) is a K * K real-valued matrix whose (i,j)t,h element is the covariance between \(y_{it},y_{j(t+h)}\): $$\text{Cov}(y_{it},y_{j(t+h)})= E[(y_{it}-\mu_{it})(y_{j(t+h)}-\mu_{j(t+h)})]. $$
The vector autoregressive model, or VAR, has a number of equivalent forms. A general form is $$ A(L)(Y_t - \mu_t)=u_t + DX_t $$ where $$ A(L)=A_0 + A_1L + A_2L^2 + \ldots + A_pL^p $$ 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[u_t]=0\) and nonsingular covariance matrix, \(\Sigma_u\), which is constant over time. The coefficient matrices \(A_j, j = 0,\ldots,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
\(a_{ij,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 $$ A_0Y_t + A_1Y_{t-1} + \cdots + A_pY_{t-p} = u_t. $$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. $$Y_{t,k} = \sum_{j=1}^{K}a_{kj,0}Y_{t,j} + \sum_{l=1}^{p}\sum_{j=1}^{K}a_{kj,l}Y_{t-l,k}$$ Consider each coefficient matrix as the vector $$ \text{vec}(A_{l}) = (a_{11,l}, a_{21,l},\ldots,a_{K1,l}, a_{12,l},a_{22,l},\ldots,a_{K2,l},\cdots, a_{1K,l},a_{2K,l},\ldots, a_{KK,l})^{T} $$ for \(l=0,\ldots,p\). $$ \text{vec}(A_{l})$$ is just the columns of $$ A_{l}$$ appended to each other. To specify a configuration different from the default, append the vectorized coefficient matrices as $$ \text{vec}(A_1, A_2,\ldots,A_p)$$ or $$ \text{vec}(A_0, A_1,\ldots,A_p)$$ when including a nontrivial leading coefficient matrix. Set the value at index l*K*K + j*K + i to 1 or -1 to fit \(a_{ij,l}\) or \(-a_{ij,l}\) in the model. Set the value to 0 to exclude \(a_{ij,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 \( \pm a_{ij,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 $$ \hat{Y}_{t+h} = E[Y_{t+h}|Y_s, 0 \le s \le t] $$ uses the conditional expectation of \(Y_{t+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: $$ \hat{Y}_{t+h} = \sum_{j=1}^{p}\hat{A}_j\hat{Y}_{t+h-j} + \delta $$ where \(Y =(Y_1,...,Y_K)^T\) is the vector time series and \(\delta=(I - \hat{A}_1-\hat{A}_2-\cdots-\hat{A}_p)\mu.\)
double
matrix T-nT by
maxStepsAhead
* K containing the forecasts.
Note that the forecast \(\hat{Y_k}_{t+h}\) is stored in location [t-nT][(h-1)*K + k] of the returned forecast matrix.
Copyright © 2020 Rogue Wave Software. All rights reserved.