为何Arima()中均值选择是否需显式设置取决于季节性成分是否差分?
Arima()函数中均值项与季节性差分的关系解析
先看两段对比代码及运行结果:
第一段代码(带季节性差分)
Arima(ts(rnorm(100), freq=4), order=c(1,0,1), seasonal=c(1,1,1), fixed = c(phi=0.5, theta=-0.4, Phi=0.3, Theta=-0.2))
运行结果:
Series: ts(rnorm(100), freq = 4) ARIMA(1,0,1)(1,1,1)[4] Coefficients: ar1 ma1 sar1 sma1 0.5 -0.4 0.3 -0.2 sigma^2 = 2.045: log likelihood = -170.59 AIC=343.18 AICc=343.22 BIC=345.74
第二段代码(无季节性差分)
Arima(ts(rnorm(100), freq=4), order=c(1,0,1), seasonal=c(1,0,1), fixed = c(phi=0.5, theta=-0.4, Phi=0.3, Theta=-0.2))
运行错误:
Error in stats::arima(x = x, order = order, seasonal = seasonal, include.mean = include.mean, : wrong length for 'fixed'
核心原因解析
Arima()默认设置include.mean = TRUE,但这个参数是否实际生效,完全取决于序列的差分配置:
- 当序列存在**季节性差分(D≥1)或普通差分(d≥1)**时,差分操作会消除序列的均值趋势,此时模型会自动忽略
include.mean参数,不会在模型中加入均值项。第一段代码里季节性差分D=1,所以模型只包含4个系数(ar1、ma1、sar1、sma1),和传入的fixed参数长度匹配,运行正常。 - 当序列**无任何差分(d=0且D=0)**时,
include.mean = TRUE会让模型额外增加一个均值系数,此时模型总系数数量为AR项+MA项+季节性AR项+季节性MA项+1(均值),也就是5个。但第二段代码的fixed参数只给了4个,长度不匹配,因此触发错误。
如果要让第二段代码正常运行,要么显式设置include.mean = FALSE,要么在fixed参数中多加入一个均值的固定值(比如fixed = c(phi=0.5, theta=-0.4, Phi=0.3, Theta=-0.2, mean=0))。
内容的提问来源于stack exchange,提问作者Antoni Parellada
相关产品推荐
相关产品推荐

