This function creates the dependent variable (Y) and predictor variable (X) matrices.
Arguments
- data
Numeric matrix. The time series data with dimensions
t
byk
, wheret
is the number of observations andk
is the number of variables.- p
Integer. The order of the VAR model (number of lags).
Value
List containing the dependent variable (Y)
and predictor variable (X) matrices.
Note that the resulting matrices will have t - p
rows.
Details
The YX()
function creates the Y
and X
matrices
required for fitting a Vector Autoregressive (VAR) model.
Given the input data
matrix with dimensions t
by k
,
where t
is the number of observations and k
is the number of variables,
and the order of the VAR model p
(number of lags),
the function constructs lagged predictor matrix X
and the dependent variable matrix Y
.
The steps involved in creating the Y
and X
matrices are as follows:
Determine the number of observations
t
and the number of variablesk
from the input data matrix.Create matrices
X
andY
to store lagged variables and the dependent variable, respectively.Populate the matrices
X
andY
with the appropriate lagged data. The predictors matrixX
contains a column of ones and the lagged values of the dependent variables, while the dependent variable matrixY
contains the original values of the dependent variables.The function returns a list containing the
Y
andX
matrices, which can be used for further analysis and estimation of the VAR model parameters.
Examples
set.seed(42)
time <- 50L
burn_in <- 10L
k <- 3
p <- 2
constant <- c(1, 1, 1)
coef <- matrix(
data = c(
0.4, 0.0, 0.0, 0.1, 0.0, 0.0,
0.0, 0.5, 0.0, 0.0, 0.2, 0.0,
0.0, 0.0, 0.6, 0.0, 0.0, 0.3
),
nrow = k,
byrow = TRUE
)
chol_cov <- chol(diag(3))
y <- SimVAR(
time = time,
burn_in = burn_in,
constant = constant,
coef = coef,
chol_cov = chol_cov
)
yx <- YX(data = y, p = 2)
str(yx)
#> List of 2
#> $ X: num [1:48, 1:7] 1 1 1 1 1 1 1 1 1 1 ...
#> $ Y: num [1:48, 1:3] 1.8 3.28 1.95 0.61 1.44 ...