Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我能';t使用tsDyn软件包进行VECM预测(测试数据行数与VAR/VECM中的滞后数不同(?)_R_Var_Predict - Fatal编程技术网

我能';t使用tsDyn软件包进行VECM预测(测试数据行数与VAR/VECM中的滞后数不同(?)

我能';t使用tsDyn软件包进行VECM预测(测试数据行数与VAR/VECM中的滞后数不同(?),r,var,predict,R,Var,Predict,我试图在我的VECM上运行一个月注册数据,使用平稳数据和虚拟变量作为外生变量。我希望它能预测未来两年。所以我使用了最后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)

我试图在我的VECM上运行一个月注册数据,使用平稳数据和虚拟变量作为外生变量。我希望它能预测未来两年。所以我使用了最后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)
库(tsDyn)

exogen1您尝试使用2行是正确的(这是模型中水平的滞后数,无可否认这有点棘手)。不知道为什么它不起作用

库(tsDyn)
#>已注册的S3方法被“quantmod”覆盖:
#>方法自
#>as.zoo.data.frame-zoo
包装版本(“tsDyn”)
#> [1] '0.9.48.999'

我不知道为什么在第一次尝试时我做不到。谢谢