如果您查看?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