Search code examples
rarimaforecast

in R, how to capture ARIMA elements from auto.arima results


I have a bunch of series to forecast using forecast::auto.arima function. I like to save what type of model did auto.arima fit. If you run the following code:

library(forecast)

set.seed(123)

y <- sin(seq(-pi,pi,0.05))+(rnorm(length(seq(-pi,pi,0.05)))/4)

arima.model <- auto.arima(y)

arima.model

the result of the last line execution shows

Series: y 

**ARIMA(1,1,2)** 

Coefficients:
         ar1      ma1     ma2

      0.9594  -1.7285  0.7740

s.e.  0.0380   0.0745  0.0658

sigma^2 estimated as 0.06534:  log likelihood=-6.1

AIC=20.2   AICc=20.53   BIC=31.51

How can I capture ARIMA(1,1,2) and save results? I was hoping to do something like arima.model$ and capture what I need to but I could not figure it out.


Solution

  • You can try summary(arima.model), arima.model$coef, arima.model$aic, arima.model$bic.

    If you want a tidy format, you can use broom package like this:

    library(broom) 
    tidy(arima.model) #ar/ma terms
    glance(arima.model) #information criteria
    
    tidy(arima.model)
    # A tibble: 3 x 3
      term  estimate std.error
      <fct>    <dbl>     <dbl>
    1 ar1      0.959    0.0380
    2 ma1     -1.73     0.0745
    3 ma2      0.774    0.0658
    
    glance(arima.model)
    # A tibble: 1 x 4
      sigma logLik   AIC   BIC
      <dbl>  <dbl> <dbl> <dbl>
    1 0.256  -6.10  20.2  31.5