Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to extract integration order (d) from auto.arima

Tags:

r

basically we can extract optimum AR order from auto.arima by

> auto.arima(ret.fin.chn,trace=TRUE,allowdrift=TRUE)

  ARIMA(2,0,2) with non-zero mean : -14242.19
  ARIMA(0,0,0) with non-zero mean : -14239.24
  ARIMA(1,0,0) with non-zero mean : -14241.3
  ARIMA(0,0,1) with non-zero mean : -14238.16
  ARIMA(1,0,2) with non-zero mean : -14237.65
  ARIMA(3,0,2) with non-zero mean : -14242.72
  ARIMA(3,0,1) with non-zero mean : -14239.52
  ARIMA(3,0,3) with non-zero mean : -14242.5
  ARIMA(2,0,1) with non-zero mean : -14237.15
  ARIMA(4,0,3) with non-zero mean : -14238.06
  ARIMA(3,0,2) with zero mean     : -14244.39
  ARIMA(2,0,2) with zero mean     : -14243.98
  ARIMA(4,0,2) with zero mean     : -14241.45
  ARIMA(3,0,1) with zero mean     : -14241.23
  ARIMA(3,0,3) with zero mean     : -14244.04
  ARIMA(2,0,1) with zero mean     : -14238.78
  ARIMA(4,0,3) with zero mean     : -14239.73


 Best model: ARIMA(3,0,2) with zero mean


 Series: ret.fin.chn 
 ARIMA(3,0,2) with zero mean     

 Coefficients:
          ar1      ar2     ar3      ma1     ma2
       0.5497  -0.4887  0.0461  -0.5691  0.4923
 s.e.  0.3525   0.1764  0.0232   0.3534  0.1878

 sigma^2 estimated as 0.0003277:  log likelihood=7127.67
 AIC=-14243.35   AICc=-14243.32   BIC=-14207.83
 Warning messages:
 1: In if (is.constant(x)) { :
   the condition has length > 1 and only the first element will be used
 2: In if (is.constant(x)) return(d) :
   the condition has length > 1 and only the first element will be used
 3: In if (is.constant(dx)) { :
   the condition has length > 1 and only the first element will be used

now store the result to object a

> a<-auto.arima(ts(ret.fin.chn),trace=TRUE,allowdrift=TRUE)

then

> a$arma[1]

while for optimum MA order by

> a$arma[2]

now look at this part Best model: ARIMA(3,0,2) with zero mean this is the ARIMA(p,d,q) order i've known how to extract the AR(p) and MA(q) order but how to extract the Integration(d) order and note in mind that i've tried the ndiffs and sometimes it gives different result than the best model perhaps it's somewhere in $arma[?]???

like image 942
Firhat Nawfan H. Avatar asked Sep 17 '25 22:09

Firhat Nawfan H.


2 Answers

More generally, the order (d) is the next to last element; the seasonal order (D) is the last. So-

  • a$arma[length(a$arma)-1] is the order d
  • a$arma[length(a$arma)] is the seasonal order
like image 60
Rafael Zayas Avatar answered Sep 19 '25 10:09

Rafael Zayas


As pointed out by Rob Hyndman, one of the authors of the forecast package, in an answer to a similar question on Cross Validated, an easy way to extract the order vector (p,d,q) is to use the forecast::arimaorder function.

In your example, this would work as follows:

arimaorder(a)

The output is a named integer with the values of p, d and q:

p d q 
3 0 2 
like image 37
Lino Ferreira Avatar answered Sep 19 '25 11:09

Lino Ferreira