Domanda

Thanks in advance. In this post, I asked the question of how to choose specific lags in a VAR model. After a quick reply and information of the 'restrict' and 'coef' functions I was able to successfully run a VAR model with the specific lags I wanted. However, what's the code I need to use the restricted VAR model to make forecasts?

Sample of my code is below:

 ##Attempt to Restrict VAR Coefficients
 ##VAR has 5 lags with three variables plus constant and 11 seasonal dummies.

 library("vars")
 var1 <- VAR(DVARmat, p = 5, type ="const", season = 12)
 restrict <- matrix (c(1,0,0,1,0,1,0,0,0,0,0,1,0,1,0,0,0,1,0,0,1,0,1,0,0,0,0,
                       1,0,0,1,0,1,0,0,0,0,0,1,0,1,0,0,0,1,0,0,1,0,1,0,0,0,0,
                       1,0,0,1,0,1,0,0,0,0,0,1,0,1,0,0,0,1,0,0,1,0,1,0,0,0,0),
                     nrow = 3, ncol = 27, byrow = T)
 var1_restrict <- coef(restrict(var1, method ="man", resmat = restrict))
 var1_restrict

I know the forecast code after a normal VAR, but can't seem to fudge the restricted VAR into it. Thanks again.

È stato utile?

Soluzione

After generating the restricted coefficient matrix restrict, you can use predict on restrict(...) since restrict(...) also returns an object of class varest :

 ##Attempt to Restrict VAR Coefficients
     ##VAR has 5 lags with three variables plus constant and 11 seasonal dummies.

         library("vars")
         var1 <- VAR(DVARmat, p = 5, type ="const", season = 12)
         restrict <- matrix (c(1,0,0,1,0,1,0,0,0,0,0,1,0,1,0,0,0,1,0,0,1,0,1,0,0,0,0,
                               1,0,0,1,0,1,0,0,0,0,0,1,0,1,0,0,0,1,0,0,1,0,1,0,0,0,0,
                               1,0,0,1,0,1,0,0,0,0,0,1,0,1,0,0,0,1,0,0,1,0,1,0,0,0,0),
                             nrow = 3, ncol = 27, byrow = T)
         var1_restrict <- coef(restrict(var1, method ="man", resmat = restrict))
         var1_restrict

         expostrestrict <- predict(restrict(var1, method="man", resmat = restrict), n.ahead = 13, ci=.95)

Note that restrict(var1, method="man", resmat = restrict) is an object that could be generated, thus if one prefers they may also use the following :

restrict_var <- restrict(var1, method="man", resmat = restrict)
expostrestrict <- predict(restrict_var, n.ahead = 13, ci=.95)
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top