Skip to content

Commit 6bb2cfa

Browse files
Fix ARIMA() re-estimation when all MLE fits produce Inf ic
Resolves #412
1 parent 7b2a6e8 commit 6bb2cfa

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
* More robust calculations of `ARIMA()` AR and MA roots (#417).
1919
* Fixed `refit()` method for `ETS()` models applying transformations twice (#407).
2020
* Fixed recycling warning in `generate()` method for `SNAIVE()` models (#436).
21+
* Fixed automatic `ARIMA()` with `approximation = TRUE` storing incorrect model
22+
specifications when secondary MLE model estimates are all rejected (#412).
2123

2224
# fable 0.4.1
2325

R/arima.R

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -372,18 +372,29 @@ This is generally discouraged, consider removing the constant or reducing the nu
372372
cat("\n--- Re-estimating best models without approximation ---\n\n")
373373
}
374374

375+
approx_best <- best
376+
approx_spec <- which.min(est_ic)
377+
375378
method <- "CSS-ML"
376379
best <- NULL
377380
sm_best <- Inf
378381
step_order <- order(est_ic)[seq_len(sum(!is.na(est_ic)))]
379382
est_ic <- rep_len(Inf, length(est_ic)) # Ignore all approximate models until re-estimated
380-
for (mod_spec in step_order)
381-
{
382-
est_ic[mod_spec] <- do.call(compare_arima, model_opts[mod_spec, ])
383-
if (isTRUE(is.finite(est_ic[mod_spec]))) {
383+
for (i in step_order) {
384+
est_ic[i] <- do.call(compare_arima, model_opts[i, ])
385+
if (has_mle_fit <-isTRUE(is.finite(est_ic[i]))) {
386+
mod_spec <- i
384387
break
385388
}
386389
}
390+
391+
if(!has_mle_fit) {
392+
if(trace) {
393+
cat("\n--- Re-estimating best models without approximation failed, returning CSS fits ---\n\n")
394+
}
395+
best <- approx_best
396+
mod_spec <- approx_spec
397+
}
387398
} else {
388399
mod_spec <- which.min(est_ic)
389400
}
@@ -409,14 +420,14 @@ This is generally discouraged, consider removing the constant or reducing the nu
409420
if (is_empty(fit_se)) {
410421
fit_se <- NULL
411422
}
412-
else if (model_opts[which.min(est_ic), "constant"] && is.null(xreg)) {
423+
else if (model_opts[mod_spec, "constant"] && is.null(xreg)) {
413424
fit_coef["constant"] <- fit_coef["constant"] * (1 - sum(best$model$phi))
414425
fit_se["constant"] <- fit_se["constant"] * (1 - sum(best$model$phi))
415426
}
416427

417428
# Compute regression residuals
418429
reg_resid <- as.numeric(y)
419-
if (model_opts[which.min(est_ic), "constant"]) {
430+
if (model_opts[mod_spec, "constant"]) {
420431
xreg <- cbind(xreg, constant = arima_constant(length(y), seas_d, seas_D, period))
421432
}
422433
if (!is.null(xreg)) {

0 commit comments

Comments
 (0)