The code below gets a: error in mean(abs((y_true - y_pred)/y_true)) : argument "y_true" is missing, with no default

I've seen MAPE used on forecasts. Can one use this and similar methods on models? Or is there some other R package that would work?

Edit 1: Seems lke MAPE wants a forecast. While my arima:

> class(arima)
[1] "forecast_ARIMA" "ARIMA"          "Arima"  

might be a forecast MAPE does not work. Using summary, i get:

Training set error measures:
                      ME     RMSE      MAE          MPE
Training set 0.003245791 1.473989 1.051721 -0.001574146
                  MAPE      MASE         ACF1
Training set 0.5306977 0.9908161 -0.001193281

Doing a ??MAP gets me nine packages (with many different names for methods ans parameters). This is confusing. Is there any doc on which types of objects work with what?

Original code:

symbols <- c("SPY","EFA", "IJS", "EEM","AGG")
prices <- getSymbols(symbols,
               src = 'yahoo',
               from = "2012-12-31",
               to = "2017-12-31",
               auto.assign = TRUE,
               warnings = FALSE) 

arima = auto.arima(ts)

1 Answer 1


MAPE is just a calculation. The functions from MLmetrics might not be specifically designed for time series, but if you give the MLmetrocs::MAPE function the true and predicted values, you will get the desired mean absolute percent error for the predictions made by your ARIMA model.

Note that MAPE, despite what seems to be a nice interpretation, has some problem that are worth knowing.

Since it is fine to use the function from MLmetrics, you do not have to write your own MAPE function. However, if you have defined the y_true and y_pred variables in your code, you seem to have given the right calculation (though it seems you have not defined y_true anywhere, which would explain your error).

  • $\begingroup$ nice link. thanks. $\endgroup$
    – Ray Tayek
    May 28, 2023 at 21:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.