我有这样的数据:
dat
# A tibble: 34 x 2
date_block_num sales
<int> <dbl>
1 0 131479
2 1 128090
3 2 147142
4 3 107190
5 4 106970
6 5 125381
7 6 116966
8 7 125291
9 8 133332
10 9 127541
# ... with 24 more rows
date_block_num
是每年的月份。
sales
日期块编号
0有63224行/箱,因为销售是按天计算的,并且它们指的是不同商店中的不同商品。每天分析数据也很有趣,但R不能处理这么多的数据。
我想对时间序列进行分解,以便分析趋势、季节性和随机成分。总的来说,时间序列有33个月(开始时间:2013年1月1日,结束时间:2015年10月1日)。
library(forecast)
ts(dat, frequency = 12) %>%
decompose() %>%
autoplot()
然而,将上述四个图中的第一个图与此图进行比较,这似乎是不对的:
plot(dat, type = "l")
structure(list(date_block_num = 0:33, sales = c(131479, 128090,
147142, 107190, 106970, 125381, 116966, 125291, 133332, 127541,
130009, 183342, 116899, 109687, 115297, 96556, 97790, 97429,
91280, 102721, 99208, 107422, 117845, 168755, 110971, 84198,
82014, 77827, 72295, 64114, 63187, 66079, 72843, 71056)), class = c("tbl_df",
"tbl", "data.frame"), row.names = c(NA, -34L))