繁体   English   中英

R预测包中的Auto.Arima()行为不规律

[英]Auto.Arima() in R Forecast package behaving erratically

我正在使用R和Rob Hyndman的预测版5.4插件。 这是一个非常好的软件包,但它看起来很奇怪,预测类似数据的结果差异很大。 我很确定它与数据末尾生成的警告消息有关,但我不确定如何修复它。

     library(forecast)
     v <- vector("numeric")
     v <- append(v,0.0)
     v <- append(v,115.0)
     v <- append(v,0.0)
     v <- append(v,0.0)
     v <- append(v,0.0)
     v <- append(v,115.0)
     v <- append(v,0.0)
     v <- append(v,0.0)
     v <- append(v,0.0)
     v <- append(v,115.0)
     v <- append(v,0.0)
     v <- append(v,0.0)
     v <- append(v,0.0)
     v <- append(v,0.0)
     v <- append(v,117.0)
     v <- append(v,0.0)
     v <- append(v,0.0)
     v <- append(v,0.0)
     v <- append(v,117.0)
     v <- append(v,0.0)
     v <- append(v,0.0)
     v <- append(v,0.0)
     v <- append(v,117.0)
     v <- append(v,0.0)
     v <- append(v,0.0)
     v <- append(v,0.0)
     v <- append(v,0.0)
     v <- append(v,0.0)
     v <- append(v,113.0)
     v <- append(v,0.0)
     v <- append(v,0.0)
     v <- append(v,0.0)
     v <- append(v,112.0)
     v <- append(v,0.0)
     v <- append(v,0.0)
     v <- append(v,0.0)
     v <- append(v,0.0)
     v <- append(v,0.0)
     v <- append(v,0.0)
     v <- append(v,0.0)
     v <- append(v,120.0)
     v <- append(v,0.0)
     v <- append(v,0.0)
     v <- append(v,0.0)
     v <- append(v,119.0)
     v <- append(v,0.0)
     v <- append(v,0.0)
     v <- append(v,0.0)
     series <- ts(v, frequency=12)
     series
  Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
1   0 115   0   0   0 115   0   0   0 115   0   0
2   0   0 117   0   0   0 117   0   0   0 117   0
3   0   0   0   0 113   0   0   0 112   0   0   0
4   0   0   0   0 120   0   0   0 119   0   0   0
     a <- auto.arima(series)
     // Note there is no error

     v <- vector("numeric")
     v <- append(v,0.0)
     v <- append(v,109.0)
     v <- append(v,0.0)
     v <- append(v,0.0)
     v <- append(v,0.0)
     v <- append(v,120.0)
     v <- append(v,0.0)
     v <- append(v,0.0)
     v <- append(v,0.0)
     v <- append(v,114.0)
     v <- append(v,0.0)
     v <- append(v,0.0)
     v <- append(v,0.0)
     v <- append(v,0.0)
     v <- append(v,125.0)
     v <- append(v,0.0)
     v <- append(v,0.0)
     v <- append(v,0.0)
     v <- append(v,135.0)
     v <- append(v,0.0)
     v <- append(v,0.0)
     v <- append(v,0.0)
     v <- append(v,130.0)
     v <- append(v,0.0)
     v <- append(v,0.0)
     v <- append(v,0.0)
     v <- append(v,0.0)
     v <- append(v,0.0)
     v <- append(v,104.0)
     v <- append(v,0.0)
     v <- append(v,0.0)
     v <- append(v,0.0)
     v <- append(v,114.0)
     v <- append(v,0.0)
     v <- append(v,0.0)
     v <- append(v,0.0)
     v <- append(v,0.0)
     v <- append(v,0.0)
     v <- append(v,0.0)
     v <- append(v,0.0)
     v <- append(v,126.0)
     v <- append(v,0.0)
     v <- append(v,0.0)
     v <- append(v,0.0)
     v <- append(v,114.0)
     v <- append(v,0.0)
     v <- append(v,0.0)
     v <- append(v,0.0)
     series <- ts(v, frequency=12)
     a <- auto.arima(series)
Warning message:
In max(which(abs(testvec)          1e-08)) :
  no non-missing arguments to max; returning -Inf
     series
  Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
1   0 109   0   0   0 120   0   0   0 114   0   0
2   0   0 125   0   0   0 135   0   0   0 130   0
3   0   0   0   0 104   0   0   0 114   0   0   0
4   0   0   0   0 126   0   0   0 114   0   0   0

您可以看到数据集几乎相同,但第二个会发出警告消息。 如果您复制并粘贴到R中,您可以看到第二个的预测也已关闭。

有想法该怎么解决这个吗?

*更新*

请注意,此示例在大约一天的R体验之后被放在一起,并且只是记录器文本。 使用JRI(R的Java接口),我想出了以下模拟ArrayList。 早期的原型并不总是最漂亮的。

            eval(re, "v <- vector(\"numeric\")");
            for (int i = 0; i < months.size(); i++) {
                eval(re, "v <- append(v," + months.get(i) + ")");
            }

这是您的数据,输入效率更高。 为什么要使用append语句???

library(forecast)
v1 <- ts(c(0, 115, 0, 0, 0, 115, 0, 0, 0, 115, 0, 0, 0, 0, 117, 0, 0, 
          0, 117, 0, 0, 0, 117, 0, 0, 0, 0, 0, 113, 0, 0, 0, 112, 0, 0, 
          0, 0, 0, 0, 0, 120, 0, 0, 0, 119, 0, 0, 0), frequency=12)
fit1 <- auto.arima(v1)
plot(forecast(fit1))

v2 <- ts(c(0, 109, 0, 0, 0, 120, 0, 0, 0, 114, 0, 0, 0, 0, 125, 0, 0, 
       0, 135, 0, 0, 0, 130, 0, 0, 0, 0, 0, 104, 0, 0, 0, 114, 0, 0, 
       0, 0, 0, 0, 0, 126, 0, 0, 0, 114, 0, 0, 0), frequency=12)
fit2 <- auto.arima(v2)
plot(forecast(fit2))

警告即将到来,因为auto.arima试图拟合恰好具有等于零的所有估计系数的模型。 预测包的下一个版本(可从https://github.com/robjhyndman/forecast获得 )修复了此警告。

在任何情况下,ARIMA模型都不适合这两个时间序列。 尝试了解导致零和非零的原因,并构建适合数据的模型。 例如,它可能包括两个过程 - 一个用于非零值之间的时间,另一个用于非零值的大小。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM