Skip to content

Commit

Permalink
MASE only uses seasonal naive when there is at least 2 years of data
Browse files Browse the repository at this point in the history
  • Loading branch information
robjhyndman committed Dec 24, 2024
1 parent 1408ab2 commit 7e08414
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions R/accuracy-gts.R
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,12 @@ accuracy.gts <- function(object, test, levels, ..., f = NULL) {
else
histy <- aggts(object, levels, forecasts = FALSE)
if (!is.null(histy)) {
scale <- colMeans(abs(diff(histy, lag = max(1, round(stats::frequency(histy))))),
na.rm = TRUE)
m <- max(1, round(stats::frequency(histy)))
if(m > 1 & NROW(histy) < 2*m) {
warning("Not enough historical data to use seasonal naive method for MASE. Using naive method instead.")
m <- 1
}
scale <- colMeans(abs(diff(histy, lag = m)), na.rm = TRUE)
q <- sweep(res, 2, scale, "/")
mase <- colMeans(abs(q), na.rm = TRUE)
}
Expand Down

0 comments on commit 7e08414

Please sign in to comment.