【发布时间】:2020-09-28 04:41:42
【问题描述】:
我正在尝试在我的 VECM 上运行每月注册数据,其中固定数据和虚拟变量作为外生变量。我希望它预测未来 2 年。所以我使用最后 24 个观察结果
library(tsDyn)
exogen1<-rnorm(120,0,10)
exogen2<-rnorm(120,0,10)
dc <- rep(0, 120)
dc[60:80] <- 1 #dummy variable representation
x<-rnorm(120,0,10)
y<-rnorm(120,0,15)
i<-1:120
x1<-sapply(i,function(k) sum(x[1:k]))
x2<-x1+y
plot(x1,type="l")#non-stationary macro variable x1 to predict on the model
lines(x2,col="red")#non-stationary macro variable x2 cointegrated with x1
lines(exogen1,col="green")#stationary variable exogen1 that explains the other variables
lines(exogen2,col="blue")#stationary variable exogen2 that explains the other variables
endogen<-cbind(x1,x2)
exogen<- cbind(exogen1, exogen2, dc)
mdl<- VECM(endogen, lag=1, estim = "ML", r=1, exogen = exogen)
new_endogen <-tail(cbind(x1,x2),24)
new_exogen <- tail(cbind(exogen1,exogen2,dc),24)
predict(mdl, newdata=new_endogen, exoPred = new_exogen, n.ahead=24)
我在运行最后一行代码时收到此错误消息:Error in predict.VAR(mdl, newdata = new_endogen, exoPred = new_exogen, : Please provide newdata with nrow=lag
为什么测试数据(newdata)和VECM的lag长度一样???
我尝试将 lag 更改为 24(newdata 中的行数)或 48(newdata 的总长度)只是为了看看它是否会改变结果。但它保持不变
我还尝试将 newdata 的长度更改为 1(vecm 的 lag 的长度)和 2(var 模型的 lag 的长度),但始终得到相同的结果
可能出了什么问题?
【问题讨论】: