我有一个从 2013 年 1 月 7 日开始到 2016 年 5 月 23 日结束的每周级别的 R 时间序列。
我使用以下代码创建了时间序列:
start_date <- min(Orders_All_weekly$Week_Start)
Orders_Weekly.ts <- ts(Orders_All_weekly$Sales, start = decimal_date(ymd(start_date)), freq = (365.25/7))
Orders_Weekly.stl <- stl(Orders_Weekly.ts, s.window = 'periodic')
我正在尝试对这些数据运行 Holt Winters 时间序列,但收到错误
Orders_Weekly.hw <- HoltWinters(Orders_Weekly.stl)
Error in decompose(ts(x[1L:wind], start = start(x), frequency = f), seasonal) :
time series has no or less than 2 periods
我看到有几个人发布了这个错误,普遍的 react 是数据实际上没有至少两个周期......这是这个过程所必需的。除非我完全误解了这个的含义(这是可能的),否则我有超过所需的两个时期。我的数据是每周级别的,我有 3 年以上的观察。
我是否设置错误?或者错误本质上是说没有季节性?
ID Week_Start Sales
1 2013-04-08 932662.9
3 2013-05-13 1021574.4
4 2013-05-20 913812.9
5 2013-06-17 1086239.1
7 2013-08-26 762829.3
8 2013-11-18 1085033.0
9 2013-12-02 897158.4
10 2013-12-09 776733.7
11 2013-12-23 867362.8
12 2013-02-04 666362.0
13 2013-02-18 748603.2
15 2013-07-22 1005986.7
16 2013-09-02 896582.8
17 2013-10-28 868364.8
18 2014-01-06 814648.7
19 2014-02-10 847342.4
20 2014-02-17 869374.3
21 2014-03-17 827677.6
22 2014-03-24 897462.3
23 2014-03-31 850542.4
24 2014-04-21 1139619.4
25 2014-07-28 889043.3
26 2014-08-04 1097560.6
27 2014-09-08 1029379.4
28 2014-10-13 998094.8
29 2014-11-10 1238445.9
30 2014-12-15 1204006.6
31 2014-07-14 1106800.6
32 2014-09-01 730030.8
33 2014-10-06 1085331.8
34 2014-05-05 1072926.8
35 2014-05-19 863283.7
36 2015-01-19 1095186.1
37 2015-02-02 866258.2
38 2015-02-16 1006247.0
39 2015-03-23 1214339.7
40 2015-04-20 1181482.9
41 2015-05-18 1112542.4
42 2015-06-01 1188714.7
43 2015-07-20 1216050.4
45 2015-08-17 848302.8
46 2015-08-24 1081198.9
47 2015-09-14 916539.8
48 2015-09-28 957177.8
49 2015-10-26 964467.1
50 2015-11-02 1063949.1
51 2015-01-12 879343.9
53 2015-03-09 1245047.9
55 2015-11-16 913514.4
56 2015-02-09 1108247.6
57 2015-12-28 1014929.2
58 2016-01-25 946786.3
59 2016-02-01 891230.8
60 2016-02-29 1274039.8
61 2016-03-07 847501.8
62 2016-04-04 1057844.1
64 2016-04-11 1207347.4
65 2016-04-18 1159690.4
66 2016-05-02 1394727.6
67 2016-05-23 1044129.3
68 2013-03-04 1040017.1
69 2013-03-11 984574.2
70 2013-04-15 1054174.1
72 2013-04-29 952720.1
73 2013-05-06 1000977.1
74 2013-06-03 1091743.6
75 2013-07-01 955164.8
76 2013-08-12 808803.7
77 2013-09-23 960096.4
78 2013-09-30 814014.4
79 2013-10-14 743264.9
81 2013-01-28 956396.4
84 2013-10-21 959058.5
85 2013-11-11 915108.6
90 2013-01-14 867140.6
91 2014-01-27 910063.7
92 2014-03-10 963144.2
93 2014-04-07 975789.6
95 2014-04-28 1030313.7
97 2014-05-26 1139089.3
99 2014-06-09 1077980.6
100 2014-06-30 1019326.6
101 2014-09-15 666787.6
103 2014-11-03 1059089.4
105 2014-11-24 705428.6
106 2014-12-22 889368.8
108 2014-06-23 1046989.4
110 2015-02-23 1327066.4
112 2015-04-13 1110673.9
115 2015-06-08 1177799.1
116 2015-07-06 1314697.7
118 2015-07-27 1094805.6
119 2015-08-03 882394.2
120 2015-09-21 1159233.2
121 2015-10-19 1171636.9
122 2015-11-23 1036050.9
125 2015-12-21 984050.8
128 2016-01-04 1371348.3
129 2016-01-11 1086225.4
131 2016-02-22 1077692.4
137 2013-03-18 854699.1
141 2013-05-27 1011870.1
142 2013-08-05 893878.4
143 2013-12-16 801215.2
148 2013-10-07 805962.8
150 2013-11-04 801729.8
152 2013-08-19 726361.0
155 2014-02-24 979288.7
158 2014-04-14 1006729.5
161 2014-07-07 1102600.4
162 2014-08-11 979494.5
164 2014-10-20 901047.1
166 2014-10-27 1260062.0
169 2014-12-29 1022656.2
171 2014-08-18 976136.5
175 2015-03-02 897352.6
177 2015-03-30 1059103.8
178 2015-05-11 1033694.4
179 2015-06-29 1037959.4
182 2015-09-07 1230050.6
183 2015-10-12 975898.2
185 2015-12-07 1057603.4
186 2015-12-14 953718.2
189 2015-04-06 1233091.9
190 2015-04-27 1176994.2
192 2015-01-26 1256182.6
196 2016-01-18 955919.5
197 2016-02-15 954623.5
198 2016-03-14 740724.2
199 2013-01-07 924205.2
201 2013-02-11 672150.0
202 2013-03-25 769391.5
205 2013-06-10 870971.1
206 2013-06-24 1043166.2
208 2013-07-15 1106379.4
210 2013-09-09 916382.0
215 2013-04-22 934307.5
217 2013-12-30 974004.0
219 2014-01-13 972211.2
220 2014-01-20 952294.8
221 2014-02-03 946820.6
225 2014-06-02 1182837.6
228 2014-08-25 912550.8
234 2014-03-03 1013797.0
245 2015-06-15 946565.2
246 2015-07-13 1139633.6
248 2015-08-10 1080701.8
249 2015-08-31 1052796.2
253 2015-11-30 980493.4
259 2016-03-28 1105384.2
264 2016-02-08 897832.2
267 2013-02-25 766646.8
269 2013-04-01 954419.8
281 2013-11-25 852430.6
286 2013-09-16 997656.1
290 2014-07-21 1171519.8
294 2014-09-29 804772.4
298 2014-12-01 813872.0
299 2014-12-08 1005479.1
304 2014-06-16 981782.5
312 2015-03-16 1009182.7
315 2015-05-25 1166947.6
329 2015-01-05 903062.3
337 2016-03-21 1299648.7
338 2016-04-25 1132090.1
341 2013-01-21 818799.7
364 2014-05-12 1035870.7
367 2014-09-22 1234683.8
381 2015-06-22 990619.5
383 2015-10-05 1175100.6
385 2015-11-09 1095345.9
395 2016-05-16 1121192.5
399 2016-05-09 1175343.4
407 2013-07-08 1035513.8
430 2014-11-17 1024473.3
443 2015-05-04 1063411.6
476 2013-07-29 809045.3
最佳答案
我不确定这是否完全回答了问题,但我能够使用下面稍微修改的代码从您的数据中获得结果。
希望这可以帮助!
有一点,我首先按日期对数据进行排序,假设这是您的意图的一部分。
Orders_Sorted <- Orders_Weekly[order(Orders_Weekly$Week_Start),] # Sort by date (unless you want to keep the data out of date order for some reason)
Orders_Weekly.ts <- ts(Orders_Sorted$Sales, frequency = (365.25/7)) # Convert df to time series
Orders_Weekly.hw <- HoltWinters(x=Orders_Weekly.ts, beta = FALSE, gamma = FALSE) # Run HW
plot(Orders_Weekly.hw) # Show plot of HW output
这产生了下面的情节。
Plot of Holt-Winters exponential smoothing of data
关于R Holt Winters 分解 'no or less than 2 periods' 时出错,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/43498036/