【问题标题】:forecast with R用 R 预测
【发布时间】:2015-09-21 10:33:58
【问题描述】:

我有 2010 年 1 月至 2015 年 7 月的登革热指数每日数据:

date    dengue_index
1/1/2010    0.169194109
1/2/2010    0.172350434
1/3/2010    0.174939783
1/4/2010    0.176244642
1/5/2010    0.176658068
1/6/2010    0.177815751
1/7/2010    0.17893075
1/8/2010    0.1813232
1/9/2010    0.182199531
1/10/2010   0.185091158
1/11/2010   0.185267748
1/12/2010   0.185894524
1/13/2010   0.18511499
1/14/2010   0.188080728
1/15/2010   0.190019472
…   …
7/20/2015   0.112748885
7/21/2015   0.113246022
7/22/2015   0.111755091
7/23/2015   0.112164176
7/24/2015   0.11429011
7/25/2015   0.113951836
7/26/2015   0.11319131
7/27/2015   0.112918734

我想使用 R 预测到 2016 年底的值。

library(forecast)
setwd("...")
dengue_series <- read.csv(file="r_wikipedia-googletrends-model.csv",head=TRUE,sep=";")
dengue_index <- ts(dengue_series$dengue_index, frequency=7)
plot(dengue_index)
# lambda=0 -> predict positive values
fit <- auto.arima(dengue_index, lambda=0)
fit
# predict until December 2016
forecast_series <- forecast(fit, 500)
forecast_series
plot(forecast_series)

问题:预测不好!

如何改进预测?

链接到数据源: https://www.dropbox.com/s/wnvc4e78t124fkd/r_wikipedia-googletrends-model.csv?dl=0

【问题讨论】:

  • 这里好像也有每月的季节性,你需要添加它。在auto.arima中的xreg参数中添加一个二进制变量
  • 例如参见here。虽然有更好的方法可能看到here
  • 请提供重现此行为的数据示例。
  • 刚刚更新了我的帖子,提供了指向数据源的链接

标签: r forecasting


【解决方案1】:

您可以尝试指定为多季节时间序列对象msts,然后使用tbats 进行预测。 tbats 在 David Arenburg 在 cmets 中提到的论文中被引用。

下面是从 taylor 数据集的 forecast 包中的示例数据中提取的示例,该数据集的季节性时段为一天 48 个半小时时段,一周有 336 个半小时时段(即 336 / 48 = 7)。

x <- msts(taylor, seasonal.periods=c(48,336), ts.frequency=48, start=2000+22/52)
fit <- tbats(x)
fc <- forecast(fit)

# not shown, but the forecast seems to capture both seasonal patterns
plot(fc)

有关taylor 的更多信息,另请参阅http://users.ox.ac.uk/~mast0315/CompareUnivLoad.pdf

对于包含每日数据和每日/每月季节性模式的数据集,也许

tsdat <- msts(dat, seasonal.periods=c(7, 84), ts.frequency=7, start=2010)

或者

 tsdat <- msts(dat, seasonal.periods=c(7, 365.25), ts.frequency=7, start=2010)

编辑

使用提供的数据,看起来像是具有每日/每周季节性的不错预测。

data <- read.table("r_wikipedia-googletrends-model.csv", header=TRUE, sep=";")
dengue_index <- msts(data$dengue_index, seasonal.periods=c(7, 365), ts.frequency=7)
fit <- tbats(dengue_index)

fc <- forecast(fit)
plot(fc)

【讨论】:

  • 我刚试过你的最后两个例子。我有同样的结果:(。
  • 嗯,很抱歉。可以试试seasonal.periods = c(7, 52, 365)。如果您可以提供指向您的实际数据的链接,我可以对其进行破解。
  • 刚刚更新了我的原始帖子,提供了指向数据源的链接
  • 它成功了!非常感谢你 :)。因此,据我了解,在您的解决方案中,无需使用 arima 方法。
  • 不客气。很高兴这有帮助。不,您不需要在此方法中直接调用 ARIMA。
猜你喜欢
  • 1970-01-01
  • 2016-08-21
  • 2014-04-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-05-13
相关资源
最近更新 更多