我正在尝试生成类似于此的图:
此处提供了演练 - > https://medium.com/@erickramer/beautiful-data-science-with-functional-programming-and-r-a3f72059500b
但是,本网站提供的代码并没有为我生成情节,而是出现了这样的错误:
> forecasts1 = tsdf %>%
+ map(auto.arima) %>%
+ map(forecast, h=10)
Error in is.constant(x) :
(list) object cannot be coerced to type 'double'
尽管我已经准确地复制了他们的数据格式。以下是我们用于比较的数据集:
> str(tsdf)
Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 89 obs. of 1 variable:
$ time_series:List of 89
..$ 1_1 : Time-Series from 2013 to 2017: 8981338 10707490 11410597 10816217 12263765 ...
..$ 1_10 : Time-Series from 2013 to 2017: 12645212 13510638 13133558 13542970 16074675 ...
..$ 1_2 : Time-Series from 2013 to 2017: 19028892 20626896 19952328 20865263 22547313 ...
..$ 1_3 : Time-Series from 2013 to 2017: 7081624 8317481 8374427 8330653 9643845 ...
..$ 1_4 : Time-Series from 2013 to 2017: 25421637 30934941 30756101 27977317 32417608 ...
提供的示例数据(根据网站,代码确实起作用):
> str(time_series)
List of 9
$ Germany : Time-Series [1:52] from 1960 to 2011: 684721 716424 749838 ...
$ Singapore : Time-Series [1:52] from 1960 to 2011: 7208 7795 8349 ...
$ Finland : Time-Series [1:37] from 1975 to 2011: 85842 86137 86344 ...
我似乎无法弄清楚,虽然这可能与他们的时间序列有一个可靠的终点这一事实有关,但我的时间序列有几个不同的月末点。
非常感谢任何帮助!
*更新*
在应用Akruns建议后,我将时间序列向量专门存储在如下列表中:
tsdf <- akrun %>%
select(time_series)
然后我按照这样的方式拟合模型:
tsdf$time_series %>% map(auto.arima) %>%
map(forecast, h=12)
......然后是情节...
......看起来很糟糕。
我需要转换y_axis比例吗?或者在绘制arima之前对数据进行某种差异处理?非常感谢任何建议!