forecTheta (version 1.0)

errorMetric: Error Metric Function

Description

This function implements some of the more used error metrics. These metrics are "sMAPE", "MAPE", "MAE", "MSE" and they respectively versions with median "sMdAPE", "MdAPE", "MdAE", "MdSE".

Usage

errorMetric(obs, forec, type="sAPE", statistic="M")

Arguments

obs
A vector or a matrix with the real values.
forec
A vector or a matrix with the estimated values.
type
The error type of "sAPE", "APE", "AE" and "SE".
statistic
The statistic to be returned. Use "M" or "Md" for return the mean or median of the errors. If "N" so a vector with all errors will be returned.

Value

  • If statistic="M" or statistic="Md" it is returned the respectively error metric result. If statistic="N" so is returned a vector with all errors points according to the chosen error type.

Details

The metric sMAPE is obtained using type = "sAPE" and statistic = "M" The metric sMdAPE is obtained using type = "sAPE" and statistic = "Md" The metric MAPE is obtained using type = "APE" and statistic = "M" The metric MdAPE is obtained using type = "APE" and statistic = "Md" The metric MAE is obtained using type = "AE" and statistic = "M" The metric MdAE is obtained using code{type = "AE"} and statistic = "Md" The metric MSE is obtained using type = "SE" and statistic = "M" The metric MdSE is obtained using type = "SE" and statistic = "Md"

See Also

forecTheta-package

Examples

Run this code
##############################################################	

y1 = 2+ 0.15*(1:20) + rnorm(20,2)
y2 = y1[20]+ 0.3*(1:30) + rnorm(30,2)
y =  as.ts(c(y1,y2))

otm.fit <- otm(y=as.ts(y[1:40]), h=10)

### sMAPE metric
errorMetric(obs=as.ts(y[41:50]), forec=otm.fit$mean)

### sMdAPE metric
errorMetric(obs=as.ts(y[41:50]), forec=otm.fit$mean, statistic = "Md")

### MASE metric
meanDiff1 = mean(abs(diff(as.ts(y[1:40]), lag = 1)))
errorMetric(obs=as.ts(y[41:50]), forec=otm.fit$mean, type = "AE", statistic = "M") / meanDiff1

Run the code above in your browser using DataLab