Learn R Programming

greybox (version 0.6.4)

ME: Error measures

Description

Functions allow to calculate different types of errors for point and interval predictions:

  1. ME - Mean Error,

  2. MAE - Mean Absolute Error,

  3. MSE - Mean Squared Error,

  4. MRE - Mean Root Error (Kourentzes, 2014),

  5. MIS - Mean Interval Score (Gneiting & Raftery, 2007),

  6. MPE - Mean Percentage Error,

  7. MAPE - Mean Absolute Percentage Error (See Svetunkov, 2017 for the critique),

  8. MASE - Mean Absolute Scaled Error (Hyndman & Koehler, 2006),

  9. RMSSE - Root Mean Squared Scaled Error (used in M5 Competition),

  10. rMAE - Relative Mean Absolute Error (Davydenko & Fildes, 2013),

  11. rRMSE - Relative Root Mean Squared Error,

  12. rAME - Relative Absolute Mean Error,

  13. rMIS - Relative Mean Interval Score,

  14. sMSE - Scaled Mean Squared Error (Petropoulos & Kourentzes, 2015),

  15. sPIS- Scaled Periods-In-Stock (Wallstrom & Segerstedt, 2010),

  16. sCE - Scaled Cumulative Error,

  17. sMIS - Scaled Mean Interval Score.

Usage

ME(actual, forecast)

MAE(actual, forecast)

MSE(actual, forecast)

MRE(actual, forecast)

MIS(actual, lower, upper, level = 0.95)

MPE(actual, forecast)

MAPE(actual, forecast)

MASE(actual, forecast, scale)

RMSSE(actual, forecast, scale)

rMAE(actual, forecast, benchmark)

rRMSE(actual, forecast, benchmark)

rAME(actual, forecast, benchmark)

rMIS(actual, lower, upper, benchmarkLower, benchmarkUpper, level = 0.95)

RelMAE(actual, forecast, benchmark)

RelRMSE(actual, forecast, benchmark)

RelAME(actual, forecast, benchmark)

RelMIS(actual, lower, upper, benchmarkLower, benchmarkUpper, level = 0.95)

sMSE(actual, forecast, scale)

sPIS(actual, forecast, scale)

sCE(actual, forecast, scale)

sMIS(actual, lower, upper, scale, level = 0.95)

Arguments

actual

The vector or matrix of actual values.

forecast

The vector or matrix of forecasts values.

lower

The lower bound of the prediction interval.

upper

The upper bound of the prediction interval.

level

The confidence level of the constructed interval.

scale

The value that should be used in the denominator of MASE. Can be anything but advised values are: mean absolute deviation of in-sample one step ahead Naive error or mean absolute value of the in-sample actuals.

benchmark

The vector or matrix of the forecasts of the benchmark model.

benchmarkLower

The lower bound of the prediction interval of the benchmark model.

benchmarkUpper

The upper bound of the prediction interval of the benchmark model.

Value

All the functions return the scalar value.

Details

In case of sMSE, scale needs to be a squared value. Typical one -- squared mean value of in-sample actuals.

If all the measures are needed, then measures function can help.

There are several other measures, see details of pinball and hm.

References

See Also

pinball, hm, measures

Examples

Run this code
# NOT RUN {

y <- rnorm(100,10,2)
testForecast <- rep(mean(y[1:90]),10)

MAE(y[91:100],testForecast)
MSE(y[91:100],testForecast)

MPE(y[91:100],testForecast)
MAPE(y[91:100],testForecast)

# Measures from Petropoulos & Kourentzes (2015)
MASE(y[91:100],testForecast,mean(abs(y[1:90])))
sMSE(y[91:100],testForecast,mean(abs(y[1:90]))^2)
sPIS(y[91:100],testForecast,mean(abs(y[1:90])))
sCE(y[91:100],testForecast,mean(abs(y[1:90])))

# Original MASE from Hyndman & Koehler (2006)
MASE(y[91:100],testForecast,mean(abs(diff(y[1:90]))))

testForecast2 <- rep(y[91],10)
# Relative measures, from and inspired by Davydenko & Fildes (2013)
rMAE(y[91:100],testForecast2,testForecast)
rRMSE(y[91:100],testForecast2,testForecast)
rAME(y[91:100],testForecast2,testForecast)

#### Measures for the prediction intervals
# An example with mtcars data
ourModel <- alm(mpg~., mtcars[1:30,], distribution="dnorm")
ourBenchmark <- alm(mpg~1, mtcars[1:30,], distribution="dnorm")

# Produce predictions with the interval
ourForecast <- predict(ourModel, mtcars[-c(1:30),], interval="p")
ourBenchmarkForecast <- predict(ourBenchmark, mtcars[-c(1:30),], interval="p")

MIS(mtcars$mpg[-c(1:30)],ourForecast$lower,ourForecast$upper,0.95)
sMIS(mtcars$mpg[-c(1:30)],ourForecast$lower,ourForecast$upper,mean(mtcars$mpg[1:30]),0.95)
rMIS(mtcars$mpg[-c(1:30)],ourForecast$lower,ourForecast$upper,
       ourBenchmarkForecast$lower,ourBenchmarkForecast$upper,0.95)

### Also, see pinball function for other measures for the intervals

# }

Run the code above in your browser using DataLab