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

时间:2016-06-24 16:17:23

标签: r time-series forecasting

我正在使用forecast::auto.arima运行时间序列预测,我正在尝试查看是否有提取分配给pd,{{1}的值的方法从拟合的时间序列对象中(和季节性的,如果适用的话)。例如:

q

fit <- auto.arima(mydata) 选择auto.arima()模型。有没有办法从适合中提取ARIMA(1,1,0)(0,1,1)[12]pd(以及qPD)的值?最后,我想自动分配六个变量,如下所示:

Q

1 个答案:

答案 0 :(得分:4)

如果查看?auto.arima,您将知道它返回与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