Mat

Thanks a lot, that is exactly what I am looking for!


Regards
Karl

On Tue, Nov 24, 2009 at 2:23 PM, Matthieu Stigler <
matthieu.stigler@gmail.com> wrote:

> Same remark as before, please provide reproducible code!!
>
> Ok, sorry, showed only the case for var, not vec2var. Well it is more
> complicated as there is no corresponding lm object.
> (reason is the var in level you obtain is estimated under constraint
> of cointegration, so estimating yourself with usual lm won't lead to
> same results).
>
> So what you do is simply extract the coef and mutliply with your
> predicted values, something like (using again last value, so can see
> it's same as using predict):
> data(Canada)
> sjf.vecm <- ca.jo(Canada, ecdet = "none", type = "eigen", K = 2,spec =
> "longrun")
> converted<-   vec2var(sjf.vecm, r = 1)
>
> coefe<-c( converted$A$A1[1,],
> converted$deterministic[1],converted$A$A2[1,])
> predval<-converted$datamat[nrow(converted$datamat),c(1:9)]
> coefe%*%predval
> predict(converted, n.ahead=1)
>
> Hope this helps
>
> Mat
>
>
> 2009/11/24 Karl Schriek <kschriek@gmail.com>:
> > Hi Mat
> >
> > Yes, this is exactly what I would like to do. Only problem this that I
> > generate the model using VECM and and then convert to VAR form using
> > vec2var. (i.e. the object is of type vec2var, not varest)
> >
> > I am not sure how to extract the lm from vec2var.
> >
> >
> > Karl
> >
> >
> > On Mon, Nov 23, 2009 at 3:46 PM, Matthieu Stigler <
> > matthieu.stigler@gmail.com> wrote:
> >
> >> Hi Karl
> >>
> >> Please provide reproducible code when you ask questions, we don't have
> >> access to your local drive!!
> >> So use rather datasets in R, as for example:
> >> data(Canada)
> >> colnames(Canada)
> >>  var.2c <- VAR(Canada, p = 1, type = "none")
> >>
> >> You will note that there is a predict.varest function which does
> forecasts:
> >>     pred<-predict(var.2c, n.ahead = 8, ci = 0.95)
> >>
> >> This is not exactly what you want... you want to change some
> >> forecasted values, and see the influence, right? This is not available
> >> i the predict.varest. You will need to do some manipulations,
> >> basically extracting the lm object and using predict(lm, newdata)
> >>
> >>
> >> Construct data frame with forecasted values. It should include all
> >> variables you see when in the output of var.2c. To keep simple, I used
> >> the simplest model (1 lag, no intercept), so need only to give 4
> >> values (the lag-1). For the example, I took last dat of data Canada,
> >> change as you want:
> >> :
> >> yourPred<-as.data.frame(matrix(Canada[nrow(Canada),], nrow=1))
> >> colnames(yourPred)<-colnames(model.frame(var.2c$varresult$e))[-1] #you
> >> need to give same names as in var result!
> >>
> >> predict(var.2c$varresult$e, newdata=yourPred)
> >>
> >> Note that this is exactly the same as what does forecast.varest,
> >> except you can now change it manually!
> >>
> >> pred$fcst$e[1,1]
> >>
> >> And now you can change the values in yourPred as you want.
> >>
> >> Hope this helps
> >>
> >> Mat
> >>
> >> 2009/11/23 Karl Schriek <kschriek@gmail.com>:
> >> > Hi
> >> >
> >> > I've fitted a VECM model in R, and converted in to a VAR
> representation.
> >> I
> >> > would like to use this model to predict the future value of a response
> >> > variable based on different scenarios for the explanatory variables.
> >> >
> >> > Here is the code for the model:
> >> >
> >> > library(urca)
> >> > library(vars)
> >> >
> >> > input <-read.csv("data.csv")
> >> > ts <- ts(input[16:52,],c(2000,1),frequency=4)
> >> > dat1 <- cbind(ts[,"dx"], ts[,"u"],
> >> ts[,"cci"],ts[,"bci"],ts[,"cpi"],ts[,"gdp"])
> >> >
> >> > args('ca.jo')
> >> > vecm <- ca.jo(dat1, type = 'trace', K = 2, season =
> >> > NULL,spec="longrun",dumvar=NULL)
> >> > vecm.var <- vec2var(vecm,r=2)
> >> >
> >> > Now what I would like do is to predict "dx" into the future by varying
> >> the
> >> > others. I am not sure if something like "predict dx if
> >> > u=30,cpi=15,bci=50,gdp=..." in the next period would work. So what I
> have
> >> in
> >> > mind is something along the lines of: increase "u" by 15% in the next
> >> period
> >> > (which would obviously impact on all the other variables as well,
> >> including
> >> > "dx") and predict the impact into the future.
> >> >
> >> > Also, I am not sure if the "vec2var" step is necessary, so please
> ignore
> >> it
> >> > if you think it is redundant.
> >> >
> >> > Thanks
> >> > Karl
> >> >
> >> >        [[alternative HTML version deleted]]
> >> >
> >> > _______________________________________________
> >> > R-SIG-Finance@stat.math.ethz.ch mailing list
> >> > https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> >> > -- Subscriber-posting only.
> >> > -- If you want to post, subscribe first.
> >> >
> >>
> >
> >        [[alternative HTML version deleted]]
> >
> > _______________________________________________
> > R-SIG-Finance@stat.math.ethz.ch mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> > -- Subscriber-posting only.
> > -- If you want to post, subscribe first.
> >
>

	[[alternative HTML version deleted]]

