From bb49d37e32ef3057ce3840a60472dbf389197295 Mon Sep 17 00:00:00 2001 From: Jesse Wheeler Date: Thu, 26 Oct 2023 14:32:37 -0400 Subject: [PATCH] Added var check --- DESCRIPTION | 2 +- NEWS.md | 4 ++++ R/arima.R | 7 ++++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 833a512..dee105b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: arima2 Title: Likelihood Based Inference for ARIMA Modeling -Version: 3.0.3.9000 +Version: 3.0.4.9000 Authors@R: c( person("Jesse", diff --git a/NEWS.md b/NEWS.md index 9642bcd..3450383 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,9 @@ # arima2 (development version) +# arima2 3.0.4 + +* Added a check to ensure a random restart is considered an improvement only if it returns a model that has a proper variance matrix for estimated coefficients. + # arima2 3.0.3 * Added `aicc` option to `aicTable`, and removed superfluous arguments. diff --git a/R/arima.R b/R/arima.R index 5e6389e..bd4ae2d 100644 --- a/R/arima.R +++ b/R/arima.R @@ -542,7 +542,12 @@ arima <- function(x, order = c(0L, 0L, 0L), ) # End trycatch ) - if (restart_result$error == 0 && restart_result$i_value + (eps_tol * 2) < best_value) { + # Make sure the best fit also has a proper covariant matrix for coefficients. + suppressWarnings( + inv_test <- !is.null(restart_result$i_var) && !any(is.nan(sqrt(diag(restart_result$i_var)))) + ) + + if (restart_result$error == 0 && restart_result$i_value + (eps_tol * 2) < best_value && inv_test) { best_coef <- restart_result$i_coef best_res <- restart_result$i_res best_var <- restart_result$i_var