Skip to content

Commit 4411495

Browse files
Fix handling of -Inf aicc in ETS()
Resolves #425
1 parent 0231ec6 commit 4411495

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

R/ets.R

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,13 @@ train_ets <- function(.data, specials, opt_crit,
6767
}
6868
new <- new$result
6969

70-
if ((new[[ic]] %||% Inf) < (best[[ic]] %||% Inf) && is.finite(new[[ic]]) || is.null(best)) {
70+
71+
new_ic <- if(isTRUE(is.finite(new[[ic]]))) new[[ic]] else Inf
72+
73+
if (new_ic < (best[[ic]] %||% Inf) || is.null(best)) {
7174
best <<- new
7275
}
73-
new[[ic]] %||% Inf
76+
new_ic
7477
}
7578
ic <- pmap_dbl(model_opts, compare_ets)
7679

tests/testthat/test-ets.R

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,3 +164,14 @@ test_that("Multiplicative ETS models", {
164164
)
165165
})
166166

167+
test_that("Automatic ETS selection bug (#425)", {
168+
train <- tsibble(
169+
YM = yearmonth("2022 Jan") + 0:35,
170+
value = rep(c(rep(-78040, 11), -78061), 3),
171+
index = YM
172+
)
173+
expect_identical(
174+
model_sum(model(train, ets=ETS(value))$ets[[1]]),
175+
"ETS(A,N,N)"
176+
)
177+
})

0 commit comments

Comments
 (0)