Skip to content

Commit

Permalink
Add support for RMSSE metric
Browse files Browse the repository at this point in the history
  • Loading branch information
albersonmiranda committed Apr 7, 2024
1 parent 3f444cf commit e231f82
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions R/accuracy-gts.R
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,15 @@ accuracy.gts <- function(object, test, levels, ..., f = NULL) {
else
histy <- aggts(object, levels, forecasts = FALSE)
if (!is.null(histy)) {
# MASE
scale <- colMeans(abs(diff(histy, lag = max(1, round(stats::frequency(histy))))),
na.rm = TRUE)
q <- sweep(res, 2, scale, "/")
mase <- colMeans(abs(q), na.rm = TRUE)
# RMSSE
mse <- colMeans(res^2, na.rm = TRUE)
scale_rmsse <- colMeans(diff(histy, lag = max(1, round(stats::frequency(histy))))^2, na.rm = TRUE)
rmsse <- sqrt(mse / scale_rmsse)
}
pe <- res/x * 100 # percentage error

Expand All @@ -110,9 +115,10 @@ accuracy.gts <- function(object, test, levels, ..., f = NULL) {

out <- rbind(me, rmse, mae, mape, mpe)
rownames(out) <- c("ME", "RMSE", "MAE", "MAPE", "MPE")
if (exists("mase")) {
out <- rbind(out, mase)
if (exists("mase") || exists("rmsse")) {
out <- rbind(out, mase, rmsse)
rownames(out)[6L] <- "MASE"
rownames(out)[7L] <- "RMSSE"
}
if (exists("fcasts")) {
colnames(out) <- colnames(fcasts)
Expand Down

0 comments on commit e231f82

Please sign in to comment.