Error in UseMethod("predict")

Hi!

I get an error I just can't get around. Been trying to find anything to read on this function "predict", but it is hard to find anything useful (too many hits in the help section). If I am correct, the function should be from the package "car"? Are there more functions named "predict" from other packages? I am trying to run the following code:

predict_VAR <- predict(Model_VAR, n.ahead = 16)

According to code by Hyndman, it should work:

trainingdata <- window(Canada, end=c(1998,4))
testdata <- window(Canada, start=c(1999,1))
v <- VAR(trainingdata, p=2)
p <- predict(v, n.ahead=8)
res <- residuals(v)
fits <- fitted(v)
for(i in 1:4)
{
  fc <- structure(list(mean=p$fcst[[i]][,"fcst"], x=trainingdata[,i],
     fitted=c(NA,NA,fits[,i])),class="forecast")
  print(accuracy(fc,testdata[,i]))
}

I get the following error when I use "Predict" with an uppercase letter P:
Error in UseMethod("predict") :
no applicable method for 'predict' applied to an object of class "varest"

And the following error when I use "predict" with a lowercase letter p:
Error in grnn.test(...) : unused argument (n.ahead = 16)

Any ideas of why it doesnt work? What function do I use to predict with my VAR_model?

Any help appreciated!

Ok, I solved it. It was masked by something in the package "BETS". Unloaded BETS and now it works. I first tried to use car::predict (or cars) but that didnt help.

btw, @robjhyndman Thank you for the for loop!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.