Reputation: 829
After having estimated a VECM model with stationary exogen variables, I would like to compute a prediction with the predict function and the newdata argument. I'm using the Dynts library that offers the possibility to compute VECM models with exogeneous variables, but I don't see how I can use the predict function with newdata for the integrated variables AND the exogeneous ones. The following code doesn't work. Any idea ?
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
First error if I want the global fit
Please provide newdata with nrow=lag+1 (note lag=p in VECM representation corresponds to p+1 in VAR rep)
Second error if I provide just the last observations
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, :
Matrix B badly specified: expected 5 elements ( (lagK+ n inc) (nthresh+1) ) but has 6
Upvotes: 0
Views: 1795
Reputation: 8940
I made some modifications, (subject to future changes!), but here you go:
## install development version:
library(devtools)
install_github("MatthieuStigler/tsDyn", ref="Dev94", subdir="tsDyn")
## use these arguments:
predict(mdl, newdata=newexogi1, exoPred=new, n.ahead=2)
Upvotes: 1