4
$\begingroup$

I try to fit data with Holt-Winters function in R. Nevertheless, i am getting the following message:

ts1<-ts(data$nb_decl,frequency=53)
hw1<-HoltWinters(ts1)

Warning message:
In HoltWinters(ts1) :
  optimization difficulties: ERROR: ABNORMAL_TERMINATION_IN_LNSRCH

'data' counts 313 lines and if I just delete or change the last value (or add 314th value), the code works... Am I doing something wrong? or what is the problem with my data?

see bellow the data used:

data
    week year nb_decl
1     00 2006       0
2     01 2006       0
3     02 2006       0
4     03 2006       1
5     04 2006       0
6     05 2006       1
7     06 2006       0
8     07 2006       0
9     08 2006       0
10    09 2006       0
11    10 2006       1
12    11 2006       0
13    12 2006       2
14    13 2006       1
15    14 2006       1
16    15 2006       0
17    16 2006       2
18    17 2006       0
19    18 2006       1
20    19 2006       0
21    20 2006       0
22    21 2006       0
23    22 2006       0
24    23 2006       1
25    24 2006       0
26    25 2006       1
27    26 2006       1
28    27 2006       0
29    28 2006       1
30    29 2006       0
31    30 2006       0
32    31 2006       0
33    32 2006       0
34    33 2006       0
35    34 2006       1
36    35 2006       0
37    36 2006       1
38    37 2006       0
39    38 2006       0
40    39 2006       0
41    40 2006       1
42    41 2006       1
43    42 2006       0
44    43 2006       0
45    44 2006       0
46    45 2006       1
47    46 2006       3
48    47 2006       2
49    48 2006       4
50    49 2006       2
51    50 2006       1
52    51 2006       1
53    52 2006       0
54    01 2007       0
55    02 2007       1
56    03 2007       1
57    04 2007       1
58    05 2007       0
59    06 2007       2
60    07 2007       0
61    08 2007       1
62    09 2007       1
63    10 2007       1
64    11 2007       1
65    12 2007       1
66    13 2007       1
67    14 2007       1
68    15 2007       1
69    16 2007       1
70    17 2007       0
71    18 2007       0
72    19 2007       1
73    20 2007       0
74    21 2007       0
75    22 2007       3
76    23 2007       0
77    24 2007       0
78    25 2007       1
79    26 2007       0
80    27 2007       2
81    28 2007       0
82    29 2007       1
83    30 2007       0
84    31 2007       0
85    32 2007       1
86    33 2007       0
87    34 2007       2
88    35 2007       1
89    36 2007       1
90    37 2007       1
91    38 2007       1
92    39 2007       2
93    40 2007       0
94    41 2007       3
95    42 2007       0
96    43 2007       0
97    44 2007       0
98    45 2007       3
99    46 2007       0
100   47 2007       0
101   48 2007       0
102   49 2007       0
103   50 2007       1
104   51 2007       1
105   52 2007       0
106   53 2007       0
107   00 2008       1
108   01 2008       9
109   02 2008       0
110   03 2008       0
111   04 2008       1
112   05 2008       0
113   06 2008       0
114   07 2008       2
115   08 2008       0
116   09 2008       2
117   10 2008       2
118   11 2008       1
119   12 2008       0
120   13 2008       0
121   14 2008       3
122   15 2008       1
123   16 2008       0
124   17 2008       1
125   18 2008       2
126   19 2008       1
127   20 2008       1
128   21 2008       1
129   22 2008       1
130   23 2008       2
131   24 2008       1
132   25 2008       1
133   26 2008       0
134   27 2008       0
135   28 2008       3
136   29 2008       0
137   30 2008       4
138   31 2008       1
139   32 2008       0
140   33 2008       1
141   34 2008       1
142   35 2008       2
143   36 2008       0
144   37 2008       1
145   38 2008       0
146   39 2008       0
147   40 2008       1
148   41 2008       0
149   42 2008       2
150   43 2008       1
151   44 2008       0
152   45 2008       1
153   46 2008       2
154   47 2008       0
155   48 2008       3
156   49 2008       3
157   50 2008       2
158   51 2008       0
159   52 2008       0
160   00 2009       2
161   01 2009       3
162   02 2009       3
163   03 2009       2
164   04 2009       3
165   05 2009       1
166   06 2009       1
167   07 2009       1
168   08 2009       1
169   09 2009       2
170   10 2009       3
171   11 2009       1
172   12 2009       1
173   13 2009       2
174   14 2009       1
175   15 2009       2
176   16 2009       4
177   17 2009       0
178   18 2009       0
179   19 2009       3
180   20 2009       0
181   21 2009       2
182   22 2009       0
183   23 2009       0
184   24 2009       1
185   25 2009       1
186   26 2009       1
187   27 2009       1
188   28 2009       3
189   29 2009       0
190   30 2009       3
191   31 2009       4
192   32 2009       0
193   33 2009       1
194   34 2009       3
195   35 2009       0
196   36 2009       2
197   37 2009       1
198   38 2009       1
199   39 2009       1
200   40 2009       2
201   41 2009       0
202   42 2009       0
203   43 2009       1
204   44 2009       3
205   45 2009       2
206   46 2009       2
207   47 2009       1
208   48 2009       0
209   49 2009       2
210   50 2009       0
211   51 2009       0
212   52 2009       0
213   00 2010       1
214   01 2010       2
215   02 2010       3
216   03 2010       2
217   04 2010       1
218   05 2010       2
219   06 2010       0
220   07 2010       2
221   08 2010       0
222   09 2010       1
223   10 2010       1
224   11 2010       1
225   12 2010       1
226   13 2010       1
227   14 2010       0
228   15 2010       1
229   16 2010       0
230   17 2010       1
231   18 2010       1
232   19 2010       1
233   20 2010       2
234   21 2010       0
235   22 2010       2
236   23 2010       4
237   24 2010       3
238   25 2010       4
239   26 2010       1
240   27 2010       1
241   28 2010       1
242   29 2010       2
243   30 2010       2
244   31 2010       2
245   32 2010       0
246   33 2010       0
247   34 2010       2
248   35 2010       0
249   36 2010       1
250   37 2010       1
251   38 2010       1
252   39 2010       1
253   40 2010       2
254   41 2010       4
255   42 2010       2
256   43 2010       1
257   44 2010       3
258   45 2010       1
259   46 2010       0
260   47 2010       6
261   48 2010       1
262   49 2010       1
263   50 2010       1
264   51 2010       2
265   52 2010      11
266    0 2011       0
267    1 2011       3
268    2 2011       2
269    3 2011       0
270    4 2011       3
271    5 2011       0
272    6 2011       4
273    7 2011       2
274    8 2011       1
275    9 2011       1
276   10 2011       1
277   11 2011       2
278   12 2011       2
279   13 2011       3
280   14 2011       1
281   15 2011       5
282   16 2011       3
283   17 2011       3
284   18 2011       1
285   19 2011       2
286   20 2011       1
287   21 2011       3
288   22 2011       0
289   23 2011       2
290   24 2011       1
291   25 2011       2
292   26 2011       1
293   27 2011       2
294   28 2011       2
295   29 2011       2
296   30 2011       1
297   31 2011       0
298   32 2011       0
299   33 2011       2
300   34 2011       0
301   35 2011       2
302   36 2011       1
303   37 2011       1
304   38 2011       1
305   39 2011       3
306   40 2011       3
307   41 2011       2
308   42 2011       2
309   43 2011       1
310   44 2011       2
311   45 2011       1
312   46 2011       1
313   47 2011       0

thank you for your help!

$\endgroup$
3
$\begingroup$

It looks like you ran into a bona fide singularity in the optimization. That can happen. What can we do about it?

I'd recommend looking into the forecast package. My first idea was to use ets(), but it turns out that ets() cannot handle frequencies above 24, so it won't work for your weekly data.

However, the error message very helpfully points us to the stlf() function, which performs an STL (season, trend, level) decomposition and subsequent ETS/smoothing or ARIMA modeling on the deseasonalized data.

model <- stlf(ts1)
plot(model)

default

As you see, stfl() (which by default fits an ETS model after STL decomposition) decided on a model with no trend and an additive error. If you definitely want a Holt-Winters-like forecast including trend, you can specify this as follows (look at ?ets to understand the etsmodel parameter, and note that stfl() will dampen the trend if you don't explicitly tell it not to dampen it):

model <- stlf(ts1,etsmodel="AAN",damped=FALSE)
plot(model)

Holt-Winters-like

$\endgroup$
0
$\begingroup$

ETS is applied on deseasonalized data. But I do not find that how to apply ARIMA on deseasonalized data using stlf. I think that there is no such option.

$\endgroup$
0
$\begingroup$

You can use Arima with stlm from the forecast package in R with the following command:

stlm(x, method = "arima", robust = T)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.