【问题标题】:Auto.Arima() in R Forecast package behaving erraticallyR Forecast 包中的 Auto.Arima() 行为异常
【发布时间】:2014-06-05 02:04:33
【问题描述】:

我将 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 来创建向量并且每次只添加一个值?
  • 感谢建设性的批评或指点。也许教授创建向量的正确方法会更合适?

标签: r time-series forecasting jri


【解决方案1】:

这是您的数据,输入效率更高。为什么要使用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 模型都不适合这两个时间序列。尝试了解导致零和非零的原因,并构建适合数据的模型。例如,它可能包括两个过程——一个用于非零值之间的时间,另一个用于非零值的大小。

【讨论】:

  • 谢谢罗伯。我以为是因为设置关闭了。也感谢您提供创建矢量的正确方法。
  • auto.arima 在这种情况下的行为是否记录在案?从答案中显示的行为来看,预测结果似乎只是该系列结转的平均值,这很好。但我需要对我对 auto.arima 如何处理不合适的时间序列的理解充满信心。
猜你喜欢
  • 1970-01-01
  • 2016-09-28
  • 1970-01-01
  • 2023-03-23
  • 2020-02-21
  • 1970-01-01
  • 2013-09-10
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多