'Vector Autoregressive (VAR) Model subset selection in R

The number of subset models of a VAR grow exponentially with the lag order, p, and the square of the number of dependent variables. To ='fix' this problem, I want to consider a number of models with low AIC values and average their residuals.

For each model equation, I consider up to 20 lowest-AIC subset equations to form a subset VAR model. To do so, I implement a VAR model from the subset equations that has the lowest AIC; then the VAR model from the subset equations that has the second-lowest AIC.

I am planning to continue with this procedure until the 20th-lowest AIC.

I am using the VARselect from the vars package in R.

Basically what I did but I am not sure how it works is that I used a for-loop for each variabl and the I stored the AIC values in a vector.

lag_max = 10 #number of maximum lags
n_vars = 5 #number of variables

#Create empty list:
model = list(
  variable1 = list(rep(0, 4), matrix(0, nrow = 4, ncol = lag_max)),
  variable2 = list(rep(0, 4), matrix(0, nrow = 4, ncol = lag_max)),
  variable3 = list(rep(0, 4), matrix(0, nrow = 4, ncol = lag_max)),
  variable4 = list(rep(0, 4), matrix(0, nrow = 4, ncol = lag_max)),
  variable5 = list(rep(0, 4), matrix(0, nrow = 4, ncol = lag_max))
)
#Create empty vector to store the AIC values so I can next fit the model:
order = rep(0, n_vars)

for (vars in 1:n_vars) {
  model[[vars]] = VARselect(data[vars], #endogenous and exogenous variables
                  lag.max = lag_max,
                  type = "const")
  order[vars] = model[[vars]][["selection"]][["AIC(n)"]]
}

> print(order)
[1] 2 9 7 3 1

> print(model$variable1)
$selection
AIC(n)  HQ(n)  SC(n) FPE(n) 
     2      2      2      2 

$criteria
                  1           2            3            4            5
AIC(n) -5.628543991 -5.72103779 -5.717512388 -5.714557013 -5.710886705
HQ(n)  -5.620748146 -5.70934403 -5.701920697 -5.695067400 -5.687499169
SC(n)  -5.608844664 -5.69148880 -5.678113732 -5.665308694 -5.651788722
FPE(n)  0.003593804  0.00327631  0.003287882  0.003297615  0.003309744
                  6            7            8            9          10
AIC(n) -5.709131608 -5.704237044 -5.704986954 -5.702984175 -5.69903789
HQ(n)  -5.681846150 -5.673053663 -5.669905650 -5.664004949 -5.65616074
SC(n)  -5.640183962 -5.625439733 -5.616339980 -5.604487537 -5.59069159
FPE(n)  0.003315562  0.003331835  0.003329345  0.003336028  0.00334923

I am just not entirely sure how VARselect() works and if the values for AIC I am getting are what I need to retrieve the residuals and then get the average.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source