@@ -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