Why don't you try reading the documentation. Here is what it says about the first argument, f
:
An object of class "forecast", or a numerical vector containing forecasts. It will also work with Arima, ets and lm objects if x is omitted – in which case in-sample accuracy measures are returned.
VAR
does not return an object of class "forecast", but you can compute a numerical vector containing forecasts.
Now read about the second argument, x
.
An optional numerical vector containing actual values of the same length as object, or a time series overlapping with the times of f.
OK, that's pretty straightforward. Just give it the actual values in x
and the forecast values in f
.
But that won't give you the MASE as further down the help page it explains that the "MASE calculation is scaled using MAE of in-sample naive forecasts for non-seasonal time series, in-sample seasonal naive forecasts for seasonal time series and in-sample mean forecasts for non-time series data." So it can't do that calculation without the historical data, and unless you are passing an object of class 'forecast' it won't know about them.
However, it is not hard to trick it into giving what you want. Here is some code that does it:
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]))
}