【发布时间】:2016-11-10 13:13:18
【问题描述】:
根据过去 156 周,我想对未来 52 周进行预测。以下代码工作正常
my.ds <- myDS[1, -c(3,4,5,6)] #reading my source file
my.start <- myDS[1, c(3)]
my.product <- myDS[1, c("Product")]
my.product <- myDS[1, c("Location")]
my.result <- melt(my.ds, id = c("Product","Location"))
my.result[order(my.result$variable),]
my.ts <- ts(my.result$value, frequency=52, start=c(my.start,1))
my.fc <- forecast(my.ts, h=52)
my.fc
预测给了我以下输出:
Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
2003.000 1637.7675 -8.610502 3284.146 -880.15039 4155.685
2003.019 1453.9059 -195.169681 3102.981 -1068.13753 3975.949
2003.038 8668.6921 7016.923492 10320.461 6142.53000 11194.854
2003.058 5851.0741 4196.616771 7505.531 3320.79997 8381.348
2003.077 4333.9240 2676.782333 5991.066 1799.54453 6868.303
2003.096 4284.5899 2624.768291 5944.412 1746.11178 6823.068
我现在想做的是:
- 将产品和位置重新添加到此结果集中
- 添加一个计算列:(Hi 95) - (Point Forecast)(我也需要这个 Point Forecast 列)
- 如下所示将表格转回
在这里尝试重塑,但由于结果似乎不是表格格式,因此不确定如何执行。
【问题讨论】:
-
myDS是什么?? -
先行数据对象的结构是什么 - my.result 和 my.ts?与 my.fc 相同的行/列长度?
-
@Sotos myDS 是 CSV 文件中的源数据集。
-
使用
as.data.frame应用于my.fc。之后reshape或dplyr会根据需要修改数据框。
标签: r reshape forecasting