如何从auto.arima中提取集成顺序(d)

时间:2013-10-20 23:09:50

标签: r

基本上我们可以通过

从auto.arima中提取最佳AR顺序
> 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

现在将结果存储到对象

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

然后

> a$arma[1]

而最佳MA顺序

> a$arma[2]

现在看看这部分 最佳模特:ARIMA(3,0,2),零均值 这是ARIMA(p,d,q)订单 我已经知道如何提取AR(p)和MA(q)顺序,但是如何提取整合(d)顺序并记住我已经尝试了ndiffs,有时它会给出不同的结果最好的模型也许它在$arma[?] ???

的某个地方

4 个答案:

答案 0 :(得分:2)

您可以在arima下的帮助文件中看到价值(auto.arimaarima具有相同的价值)

ARMA
    一种紧凑的规范形式,作为一个向量,给出了AR,MA,季节性AR和季节性MA系数的数量,以及非季节性和季节性差异的周期和数量。

因此,值a$arma[6]包含非季节性差异,a$arma[7]包含季节性差异。

答案 1 :(得分:2)

更一般地说,顺序(d)是倒数第二个元素;季节性订单(D)是最后一个。所以 -

  • a$arma[length(a$arma)-1]是订单d
  • a$arma[length(a$arma)]是季节性订单

答案 2 :(得分:1)

an answer to a similar question on Cross Validatedforecast包的作者之一Rob Hyndman所指出的,提取阶数向量(p,d,q)的一种简单方法是使用{{1 }}功能。

在您的示例中,此操作如下:

forecast::arimaorder

输出是一个命名的整数,其值为arimaorder(a) pd

q

答案 3 :(得分:0)

我真的很抱歉Metrics似乎你的解决方案不太正确

> auto.arima(fin.gre,trace=TRUE,allowdrift=TRUE)$arma

 ARIMA(2,2,2)                    : 26148.84
 ARIMA(0,2,0)                    : 27846.32
 ARIMA(1,2,0)                    : 27209.88
 ARIMA(0,2,1)                    : 26161.36
 ARIMA(1,2,2)                    : 26146.27
 ARIMA(1,2,1)                    : 26144.37
 ARIMA(1,2,1)                    : 26144.37
 ARIMA(2,2,1)                    : 26146.69

 Best model: ARIMA(1,2,1)                    

a<-auto.arima(fin.gre,trace=TRUE,allowdrift=TRUE)

a$arma
[1] 1 1 0 0 1 2 0

在做str(a)时产生

    > str(a)
List of 16
 $ coef     : Named num [1:2] 0.0715 -0.9969
  ..- attr(*, "names")= chr [1:2] "ar1" "ma1"
 $ sigma2   : num 795
 $ var.coef : num [1:2, 1:2] 3.65e-04 -3.19e-06 -3.19e-06 3.39e-06
  ..- attr(*, "dimnames")=List of 2
  .. ..$ : chr [1:2] "ar1" "ma1"
  .. ..$ : chr [1:2] "ar1" "ma1"
 $ mask     : logi [1:2] TRUE TRUE
 $ loglik   : num -13078
 $ aic      : num 26162
 $ arma     : int [1:7] 1 1 0 0 1 2 0
 $ residuals: Time-Series [1:2750] from 1 to 2750: 0.39 -1.15 -3.64 -4.65 -11.57 ...
 $ call     : language auto.arima(x = structure(list(x = c(872.5, 880.78, 884.1, 884.1, 874.45, 855.3, 844.81,  837.14, 828.08, 830.74, 835.36, 839.25, 819.54, 802.27, 798.25, 793.01, 816.43, 831.87,  ...
 $ series   : chr "fin.gre"
 $ code     : int 0
 $ n.cond   : int 0
 $ model    :List of 10
  ..$ phi  : num 0.0715
  ..$ theta: num -0.997
  ..$ Delta: num [1:2] 2 -1
  ..$ Z    : num [1:4] 1 0 2 -1
  ..$ a    : num [1:4] 1.01 -1.72 62.87 62.78
  ..$ P    : num [1:4, 1:4] -2.22e-16 2.21e-16 1.74e-16 4.62e-17 2.21e-16 ...
  ..$ T    : num [1:4, 1:4] 0.0715 0 1 0 1 ...
  ..$ V    : num [1:4, 1:4] 1 -0.997 0 0 -0.997 ...
  ..$ h    : num 0
  ..$ Pn   : num [1:4, 1:4] 1.00 -9.97e-01 9.51e-17 1.71e-16 -9.97e-01 ...
 $ bic      : num 26180
 $ aicc     : num 26162
 $ x        :An ‘xts’ object on 2003-01-01/2013-07-16 containing:
  Data: num [1:2750, 1] 872 881 884 884 874 ...
  Indexed by objects of class: [Date] TZ: UTC
  xts Attributes:  
 NULL
 - attr(*, "class")= chr "Arima"

正如您可以看到$model[3]包含来自$arma[5]$arma[6]的两个号码似乎$arma[5]代表整合订单d,但我不确定关于它