【问题标题】:Extracting p,d,q values from a fitted ARIMA model in R?从 R 中的拟合 ARIMA 模型中提取 p,d,q 值?
【发布时间】:2016-06-24 16:17:22
【问题描述】:

我正在使用forecast::auto.arima 运行时间序列预测,我试图查看是否有办法提取分配给pdq 的值(如果适用,还可以按季节进行) 来自拟合的时间序列对象。示例:

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

【问题讨论】:

    标签: r time-series forecasting


    【解决方案1】:

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

    【讨论】:

    • 谢谢,更新的版本正是我想要的!
    • 谢谢我正在寻找这个定义!最初我认为它是 p,d,q,P,D,Q,m 就像在 Statsmodel (Python) 中一样..
    猜你喜欢
    • 2020-12-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-09
    • 2020-10-01
    • 1970-01-01
    • 2019-05-06
    • 2021-10-21
    相关资源
    最近更新 更多