Testing Accuracy of an ARIMA model

Asked

Viewed 110 times

2

I am creating a function to run ARIMA models. After storing the function results in an object to do the Accuracy test, returns the following error:

Warning message:

In trainingaccuracy(f, test, d, D) test Elements must be Within sample

However, when it is the model made via the original Arima function, the Accuracy test runs normally.

As in the code:

SARIMA <- function(x,p,d,q,P,D,Q) {

  m <- arima(x,order=c(0,1,1), seasonal = list(order = c(0, 1, 1), 
    period = 12, method="CSS"))

  m
}

teste <- arima.sim(n=10000, list(ar=c(0.8), ma=c(-0.3)))

f <- SARIMA(teste,p,d,q,P,D,Q)
f
accuracy(f)

m <- arima(teste,order=c(0,1,1), seasonal = list(order = c(0, 1, 1), 
  period = 12, method="CSS"))
accuracy(m)

The two objects (f and m) are from the "Arima" class and the same "list" mode".

Pq when using SARIMA function does not run Accuracy?

  • What is the function package accuracy?

  • It’s from the forecast package.

1 answer

3

Though your function SARIMA place on the screen the results of the adjusted time series, the R does not understand that m is, in fact, the end result of the function. Make the following change and everything will work:

library(forecast)

SARIMA <- function(x,p,d,q,P,D,Q) {

  m <- arima(x,order=c(0,1,1), seasonal = list(order = c(0, 1, 1), 
    period = 12, method="CSS"))

  return(m) # mude aqui, adicionando a funcao return
}

teste <- arima.sim(n=10000, list(ar=c(0.8), ma=c(-0.3)))

f <- SARIMA(teste,p,d,q,P,D,Q)
m <- arima(teste,order=c(0,1,1), seasonal = list(order = c(0, 1, 1), 
  period = 12, method="CSS"))

accuracy(f)
                       ME     RMSE       MAE      MPE     MAPE      MASE
Training set -0.001113768 1.050208 0.8411787 120.3188 585.0239 0.9316498
                   ACF1
Training set 0.04742673


accuracy(m)
                       ME     RMSE       MAE      MPE     MAPE      MASE
Training set -0.001113768 1.050208 0.8411787 57.34868 431.3339 0.9183245
                   ACF1
Training set 0.04742673
  • I tested the change, but it did not work. I got the same result. To get around this I removed the variable x from the function and saved the test object in x.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.