From bb3891c28f9f76c182077eb170faf7bfadacd28f Mon Sep 17 00:00:00 2001 From: Rob Hyndman Date: Wed, 24 Jul 2024 09:06:40 +1000 Subject: [PATCH] ets() robust to non-integer seasonality --- R/HoltWintersNew.R | 7 +++++++ R/ets.R | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/R/HoltWintersNew.R b/R/HoltWintersNew.R index 52137040..1f25ded7 100644 --- a/R/HoltWintersNew.R +++ b/R/HoltWintersNew.R @@ -272,6 +272,13 @@ zzhw <- function(x, lenx, alpha=NULL, beta=NULL, gamma=NULL, seasonal="additive" phi <- 1 } + if(abs(m - round(m)) > 1e-4) { + # Ignore seasonality + m <- 1 + } else { + m <- round(m) + } + # initialise array of l, b, s level <- trend <- season <- xfit <- residuals <- numeric(lenx) SSE <- 0 diff --git a/R/ets.R b/R/ets.R index 6744d8d9..cf95c4ad 100644 --- a/R/ets.R +++ b/R/ets.R @@ -142,6 +142,11 @@ ets <- function(y, model="ZZZ", damped=NULL, stop("nmse out of range") } m <- frequency(y) + if(abs(m - round(m)) > 1e-4) { + warning("Non-integer seasonal period. Only non-seasonal models will be considered.") + } else { + m <- round(m) + } if (any(upper < lower)) { stop("Lower limits must be less than upper limits")