【发布时间】:2015-02-23 03:18:39
【问题描述】:
在估计了具有固定外生变量的 VECM 模型后,我想使用 predict 函数和 newdata 参数计算预测。我正在使用 Dynts 库,该库提供了使用外生变量计算 VECM 模型的可能性,但我不知道如何将 predict 函数与 newdata 一起用于集成变量和外生变量。 以下代码不起作用。任何的想法 ?
library(tsDyn)
Fact1<-rnorm(100,0,10)
x<-rnorm(100,0,10)
y<-rnorm(100,0,15)
i<-1:100
Yniv2<-sapply(i,function(k) sum(x[1:k]))
Facti1<-Yniv2+y
Yniv2<-Yniv2[1:99]
plot(Yniv2,type="l")#variable macro que l'on cherche à prévoir à l'instant t
lines(Facti1,col="red")#variable macro cointégrée avec Y dont on dispose l'obs en t
lines(Fact1,col="green")#variable stationnaire qui explique également Y
exog_met1v1<-Fact1[2:99]
exog_i1<-cbind(Yniv2[1:98],Facti1[1:98])
mdl<-VECM(exog_i1, 1, r=1, include = "const", estim = "ML", LRinclude = "const", exogen = exog_met1v1)
newexogi1 <-cbind(Yniv2[1:99],Facti1[1:99])
new <- Fact1[2:100]
newdata<-cbind(newexogi1,new)
Prev_H_1<-data.frame(predict(mdl, newdata))[,1] #pbbb
如果我想要全局拟合,第一个错误
Please provide newdata with nrow=lag+1 (note lag=p in VECM representation corresponds to p+1 in VAR rep)
第二个错误,如果我只提供最后的观察结果
newexogi1 <-cbind(Yniv2[98:99],Facti1[98:99])
new <- Fact1[99:100]
newdata<-cbind(newexogi1,new)
Prev_H_1<-data.frame(predict(mdl, newdata))[,1] #pbbb
Erreur dans TVAR.gen(B = B, nthresh = 0, type = "simul", n = n, lag = lag, :
矩阵 B 指定错误:预期有 5 个元素( (lagK+ n inc) (nthresh+1) )但有 6 个
【问题讨论】:
-
请花时间定义代码中的所有变量并提供一些示例输入以解决您的问题reproducible,否则很难帮助您..
-
是的,这是一个错误。我会尽快解决的。