robjhyndman / forecast

Forecasting Functions for Time Series and Linear Models
http://pkg.robjhyndman.com/forecast
1.11k stars 341 forks source link

More questions on auto.arima #832

Closed Apratimguha closed 4 years ago

Apratimguha commented 4 years ago

Please refer to the following codes and output. auto.arima, with seasonal component disabled, fits an ARIMA(0,1,1) model, with AICc 494. However, Arima(1,1,2) model, which should come under the default scope of auto.arima, gives an AICc of 492. I am getting this even if I am initializing auto.arima at p = 1,d = 1,q = 2.

pigs1=window(pigs,start=1990)/1000 auto.arima(pigs1,d=1,seasonal=F) Series: pigs1 ARIMA(0,1,1)

Coefficients: ma1 -0.7203 s.e. 0.1094

sigma^2 estimated as 88.51: log likelihood=-245.11 AIC=494.23 AICc=494.42 BIC=498.64

Arima(pigs1,order = c(1,1,2)) Series: pigs1 ARIMA(1,1,2)

Coefficients: ar1 ma1 ma2 -0.7542 0.2277 -0.7723 s.e. 0.0899 0.1136 0.1106

sigma^2 estimated as 79.91: log likelihood=-241.81 AIC=491.62 AICc=492.26 BIC=500.44

mitchelloharawild commented 4 years ago

The auto.arima function does not consider models that choose ARMA roots with coefficients that are close to failing stationarity and invertibility conditions. One of the characteristic roots from your Arima() model is close to the boundary (the left MA root), which makes this model close to failing the invertibility condition.

More details here: https://otexts.com/fpp2/arima-r.html

library(forecast)
#> Registered S3 method overwritten by 'xts':
#>   method     from
#>   as.zoo.xts zoo
#> Registered S3 method overwritten by 'quantmod':
#>   method            from
#>   as.zoo.data.frame zoo
#> Registered S3 methods overwritten by 'forecast':
#>   method             from    
#>   fitted.fracdiff    fracdiff
#>   residuals.fracdiff fracdiff
pigs1 <- window(fma::pigs,start=1990)/1000
fit_auto <- auto.arima(pigs1,d=1,seasonal=FALSE)
autoplot(fit_auto)


fit_manual <- Arima(pigs1,order = c(1,1,2))
autoplot(fit_manual)

Created on 2019-11-13 by the reprex package (v0.2.1)

Apratimguha commented 4 years ago

Thanks. I admit not manually checking the conditions as I assumed that only causal and invertible models will be fitted.

However, here is another example. Here the roots appear to be fine, but still an "inferior" model is being chosen.

I am really sorry to bug you but I am not sure what exactly is happening with the algorithm. What is the criteria for choosing the final model? Is there any way to understand what definition of "close" is being used by auto.arima, and control it?

Is there somewhere a more detailed manual?

mcopper1=window(mcopper, end = 2005) Arima(mcopper1,order=c(2,1,0)) Series: mcopper1 ARIMA(2,1,0)

Coefficients: ar1 ar2 0.3734 -0.1866 s.e. 0.0423 0.0423

sigma^2 estimated as 3426: log likelihood=-2962.88 AIC=5931.77 AICc=5931.81 BIC=5944.64

The roots are fine

polyroot(c(1,-0.3734,0.1866)) [1] 1.000536+2.087579i 1.000536-2.087579i image

auto.arima(mcopper1,seasonal = F,stepwise = F,start.p = 2,start.q = 0,d=1) Series: mcopper1 ARIMA(1,1,2)

Coefficients: ar1 ma1 ma2 0.9349 -0.5784 -0.3863 s.e. 0.0278 0.0441 0.0384

sigma^2 estimated as 3419: log likelihood=-2961.95 AIC=5931.89 AICc=5931.97 BIC=5949.06

robjhyndman commented 4 years ago

The most complete descriptions are in the package vignette https://cran.r-project.org/web/packages/forecast/vignettes/JSS2008.pdf and in the fpp2 book https://otexts.com/fpp2/arima-r.html.

In this case, the approximations used to speed up the algorithm lead to a slightly non-optimal result. Turn them off and you get this:

library(fpp2)
mcopper1 <- window(mcopper, end = 2005)
auto.arima(mcopper1, 
           seasonal = FALSE, 
           approximation = FALSE, 
           stepwise = FALSE)
#> Series: mcopper1 
#> ARIMA(2,1,3) 
#> 
#> Coefficients:
#>          ar1      ar2      ma1     ma2     ma3
#>       0.9048  -0.9773  -0.5599  0.6140  0.3533
#> s.e.  0.0187   0.0172   0.0424  0.0437  0.0411
#> 
#> sigma^2 estimated as 3325:  log likelihood=-2953.63
#> AIC=5919.26   AICc=5919.42   BIC=5945.01

Created on 2019-11-14 by the reprex package (v0.3.0)