提前致谢。在this post中,我询问了如何在VAR模型中选择特定滞后的问题。快速回复并提供“限制”信息。和' coef'函数我能够成功运行VAR模型,具有我想要的特定滞后。但是,我需要使用限制VAR模型进行预测的代码是什么?
我的代码示例如下:
##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
我知道普通VAR后的预测代码,但似乎无法将限制的VAR推入其中。再次感谢。
答案 0 :(得分:0)
生成受限系数矩阵restrict
后,您可以predict
使用restrict(...)
,因为restrict(...)
也会返回类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)
请注意restrict(var1, method="man", resmat = restrict)
是可以生成的对象,因此如果有人愿意,也可以使用以下内容:
restrict_var <- restrict(var1, method="man", resmat = restrict)
expostrestrict <- predict(restrict_var, n.ahead = 13, ci=.95)