I'm trying to learn a vector autoregressive model using the vars
package in R. This package doesn't have any way to measure the accuracy of the returned model.
Specifically, I want to use MASE as defined in the accuracy
function from the forecast
package in R to compare forecasting with VAR with forecasting using Arima models on each component time series (I'm using 4 possibly correlated time series). accuracy
doesn't recognize the varest
object returned by vars
. How can I get the MASE for each forecasted component? I want to calculate both in-sample and out-of-sample accuracy
Code example:
library(vars)
library(forecast)
data(Canada)
v<- VAR(window(Canada, end=c(1998,4)), p=2)
accuracy(v$varresult[[1]])
The argument of accuracy
is an lm object and returns the training accuracy for series 1 as:
ME RMSE MAE MPE MAPE MASE
Training set 1.536303e-15 0.3346096 0.2653946 -1.288309e-05 0.0281736 0.03914555
I want to get the out-of-sample test accuracy using something like (not exactly this, since the forecast period needs to be specified):
accuracy(v$varresult[[1]], window(Canada[,1], start=c(1999,1)))
but this is not supported for lm objects and returns the error
Error in testaccuracy(f, x, test) : Unknown list structure
And if I use the values directly as follows, I don't get the MASE, which needs information about the training set. This is also prone to off-by-one errors because values are used and not ts
objects, for which accuracy
will match the stored times directly:
p<-predict(v, n.ahead=8)
accuracy(p$fcst[[1]][,"fcst"],window(Canada[,1], start=c(1999,1)))
ME RMSE MAE MPE MAPE ACF1 Theil's U
Test set -0.1058358 0.8585455 0.7385238 -0.01114099 0.07694492 0.5655117 1.359761
Ideally, I should like to forecast it as:
fr<-forecast(v$varresult[[1]], h=8)
but this can't work because it needs the other series for the prediction, and gives:
Error in eval(expr, envir, enclos) : object 'datamat' not found
I could try copying the functionality of forecast.Arima
etc and try writing a forecast.varresult
package, but is there a simpler way out?