Forecast :: autolayer函数会产生每月时间序列的错误

时间:2018-08-17 12:15:39

标签: r ggplot2 time-series forecasting arima

我正尝试在样本(测试)数据上检查ARIMA模型的准确性并绘制。

我有以下时间序列。

> ts.all
     Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
2014 145 135 137 137 120 119 188 130 119 140 125 126
2015 186 174 178 239 189 181 270 174 228 270 247 190
2016 236 203 193 250 178 214 242 174 194 210 160 184
2017 182 164 177 250 170 222 268 279 196 264 241 218
2018 252 203 160 263 169 165

编辑dput(ts.all)的输出

> dput(ts.all)
structure(c(145, 135, 137, 137, 120, 119, 188, 130, 119, 140, 
125, 126, 186, 174, 178, 239, 189, 181, 270, 174, 228, 270, 247, 
190, 236, 203, 193, 250, 178, 214, 242, 174, 194, 210, 160, 184, 
182, 164, 177, 250, 170, 222, 268, 279, 196, 264, 241, 218, 252, 
203, 160, 263, 169, 165), .Tsp = c(2014, 2018.41666666667, 12
), class = "ts", .Names = c("Gross_Orders_Invoiced1", "Gross_Orders_Invoiced2", 
"Gross_Orders_Invoiced3", "Gross_Orders_Invoiced4", "Gross_Orders_Invoiced5", 
"Gross_Orders_Invoiced6", "Gross_Orders_Invoiced7", "Gross_Orders_Invoiced8", 
"Gross_Orders_Invoiced9", "Gross_Orders_Invoiced10", "Gross_Orders_Invoiced11", 
"Gross_Orders_Invoiced12", "Gross_Orders_Invoiced13", "Gross_Orders_Invoiced14", 
"Gross_Orders_Invoiced15", "Gross_Orders_Invoiced16", "Gross_Orders_Invoiced17", 
"Gross_Orders_Invoiced18", "Gross_Orders_Invoiced19", "Gross_Orders_Invoiced20", 
"Gross_Orders_Invoiced21", "Gross_Orders_Invoiced22", "Gross_Orders_Invoiced23", 
"Gross_Orders_Invoiced24", "Gross_Orders_Invoiced25", "Gross_Orders_Invoiced26", 
"Gross_Orders_Invoiced27", "Gross_Orders_Invoiced28", "Gross_Orders_Invoiced29", 
"Gross_Orders_Invoiced30", "Gross_Orders_Invoiced31", "Gross_Orders_Invoiced32", 
"Gross_Orders_Invoiced33", "Gross_Orders_Invoiced34", "Gross_Orders_Invoiced35", 
"Gross_Orders_Invoiced36", "Gross_Orders_Invoiced37", "Gross_Orders_Invoiced38", 
"Gross_Orders_Invoiced39", "Gross_Orders_Invoiced40", "Gross_Orders_Invoiced41", 
"Gross_Orders_Invoiced42", "Gross_Orders_Invoiced43", "Gross_Orders_Invoiced44", 
"Gross_Orders_Invoiced45", "Gross_Orders_Invoiced46", "Gross_Orders_Invoiced47", 
"Gross_Orders_Invoiced48", "Gross_Orders_Invoiced49", "Gross_Orders_Invoiced50", 
"Gross_Orders_Invoiced51", "Gross_Orders_Invoiced52", "Gross_Orders_Invoiced53", 
"Gross_Orders_Invoiced54"))

我已经找到了ARIMA模型(使用ACF / differencing / auto.arima /季节性测试等),并进行了这样的预测

ts.train = window(ts.all, start = c(2014,1), end = c(2017,6))
ts.test = window(ts.all, start = c(2017,7))
fit.train = arima(ts.train, order=c(1,1,0),seasonal = c(0,1,1))
pred.train = forecast(fit.train, h=12)
autoplot(ts.train) + autolayer(pred.train)

最后一行引发以下错误

Error: Invalid input: date_trans works with objects of class Date only

我查看了herehere,但对于如何格式化时间序列的 date 部分或如何修改{ {1}}函数可解决此问题。

版本信息:

autolayer

PS:我已经在R version 3.4.4 (2018-03-15) Package: forecast Version: 8.4 Package: ggplot2 Version: 3.0.0 包中的每日时间序列goog上尝试了类似的ARIMA预测。 fpp2函数在那里工作。

编辑:我并没有特别关注autolayerautoplot函数,基本图形或任何其他函数/库都很好,但是,我想在y轴上缩放标签(以1,000,000显示为1m),并且需要显示每个月在x轴上的次要中断和每个季度的主要中断,我已经为autolayer / ggplot找出了两者。

0 个答案:

没有答案