从 R 中的拟合 ARIMA 模型中提取 p、d、q 值?

Extracting p,d,q values from a fitted ARIMA model in R?

我是 运行 使用 forecast::auto.arima 的时间序列预测,我想看看是否有办法提取分配给 p、[=14= 的值], q(如果适用,还有季节性)来自拟合的时间序列对象。示例:

fit <- auto.arima(mydata)

假设 auto.arima() 选择了一个 ARIMA(1,1,0)(0,1,1)[12] 模型。有没有办法从拟合中提取pdq(和PDQ)的值?最后我想自动分配六个变量如下:

p=1, d=1, q=0, P=0, D=1, Q=1

如果你看一下?auto.arima,你就会知道它returns和stats::arima是同一个对象。如果进一步查看 ?arima,您会发现可以从返回值的 $model 中找到所需的信息。 $model 的详细信息可以从 ?KalmanLike:

中读取
phi, theta: numeric vectors of length >= 0 giving AR and MA parameters.

     Delta: vector of differencing coefficients, so an ARMA model is
            fitted to ‘y[t] - Delta[1]*y[t-1] - ...’.

所以,你应该这样做:

p <- length(fit$model$phi)
q <- length(fit$model$theta)
d <- fit$model$Delta

示例来自 ?auto.arima

library(forecast)
fit <- auto.arima(WWWusage)

length(fit$model$phi)  ## 1
length(fit$model$theta)  ## 1
fit$model$Delta  ## 1

fit$coef
#       ar1       ma1 
# 0.6503760 0.5255959 

或者(其实更好),可以参考$arma值:

arma: A compact form of the specification, as a vector giving the
      number of AR, MA, seasonal AR and seasonal MA coefficients,
      plus the period and the number of non-seasonal and seasonal
      differences.

但你需要正确仔细地匹配它们。对于上面的例子,有:

fit$arma
# [1] 1 1 0 0 1 1 0

使用符号ARIMA(p,d,q)(P,D,Q)[m],我们可以添加名称属性以便清楚地表示:

setNames(fit$arma, c("p", "q", "P", "Q", "m", "d", "D"))
# p q P Q m d D 
# 1 1 0 0 1 1 0