Skip to contents

This function creates the dependent variable (Y) and predictor variable (X) matrices.

Usage

YXExo(data, p, exo_mat)

Arguments

data

Numeric matrix. The time series data with dimensions t by k, where t is the number of observations and k is the number of variables.

p

Integer. The order of the VAR model (number of lags).

exo_mat

Numeric matrix. Matrix of exogenous variables with dimensions t by m.

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 variables k from the input data matrix.

  • Create matrices X and Y to store lagged variables and the dependent variable, respectively.

  • Populate the matrices X and Y with the appropriate lagged data. The predictors matrix X contains a column of ones and the lagged values of the dependent variables, while the dependent variable matrix Y contains the original values of the dependent variables.

  • The function returns a list containing the Y and X matrices, which can be used for further analysis and estimation of the VAR model parameters.

See also

The SimVAR() function for simulating time series data from a VAR model.

Other Simulation of Autoregressive Data Functions: BootCI(), BootSE(), SelectVARLasso(), SimVARExo(), SimVAR(), YX()

Author

Ivan Jacob Agaloos Pesigan

Examples

set.seed(42)
time <- 1000L
burn_in <- 200
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))
exo_mat <- MASS::mvrnorm(
  n = time + burn_in,
  mu = c(0, 0, 0),
  Sigma = diag(3)
)
exo_coef <- matrix(
  data = c(
    0.5, 0.0, 0.0,
    0.0, 0.5, 0.0,
    0.0, 0.0, 0.5
  ),
  nrow = 3
)
y <- SimVARExo(
  time = time,
  burn_in = burn_in,
  constant = constant,
  coef = coef,
  chol_cov = chol_cov,
  exo_mat = exo_mat,
  exo_coef = exo_coef
)
yx <- YXExo(
  data = y,
  p = 2,
  exo_mat = exo_mat[(burn_in + 1):(time + burn_in), ]
)
str(yx)
#> List of 2
#>  $ Y: num [1:998, 1:3] 2.73 2.89 1.61 1.37 2.5 ...
#>  $ X: num [1:998, 1:10] 1 1 1 1 1 1 1 1 1 1 ...