5

I am using the HoltWinters forecast package in R to generate forecasts from monthly call volume data.

It works well most of the time but has a tendency to overfit data, particularly if there are special periods, for example a step change in call demand.

In a recent example which has a step change in the middle sets alpha as 0.94, beta as 0 and gamma as 0, which generates an odd looking forecast.

Month   Data
1   7082
2   6407
3   5479
4   5480
5   5896
6   6038
7   5686
8   6126
9   6280
10  6893
11  6028
12  5496
13  3569
14  3383
15  3718
16  3351
17  3340
18  3559
19  3722
20  3201
21  3494
22  2810
23  2611
24  2471
25  7756
26  6922
27  7593
28  6716
29  7278
30  7071

This is the R script that I have been using

scandata <-read_csv("525-gash.csv");
pages <-scandata[,2];
myts <-ts(pages , start=c(2015, 1), frequency = 12)
myforecast <- HoltWinters (myts, seasonal ="additive", 
          optim.start = c(alpha = 0.2, beta = 0.1, gamma = 0.1));
myholt = predict(myforecast, 12 , prediction.interval = FALSE);
plot(myforecast,myholt);

In comparison if I set the Exponential smoothing parameters to standard accepted values - alpha as 0.2, beta as 0.1 and gamma as 0.1, I get a much better looking forecast.

I would still like to use the auto fitting part of the forecast, but would like to put a range around alpha, beta and gamma.

I have been trying to set limits on the automatic fitting so that alpha has to be between 0.1 and 0.5, gamma between 0.1 and 0.3 and gamma as between 0.1 and 0.3.

https://stat.ethz.ch/R-manual/R-devel/library/stats/html/HoltWinters.html

It looks like this should be possible by setting the

optim.control = list() 

function but I have not been able to find a way to successfully set limits on alpha, beta and gamma to get this working.

Does anyone know how to do this?

Jonty5817
  • 335
  • 2
  • 3
  • 13

1 Answers1

3

For multi-parameter optimisation, HoltWinters uses L-BFGS-B algorithm. It is possible to set lower and upper limits for all parameters by adjusting original HoltWinters function.

Edit function:

fix(HoltWinters)

by changing line 66 from:

enter image description here

to

enter image description here

Close the window and save changes (this will affect this session only). Run the code as you did before:

myforecast <- HoltWinters (myts, seasonal ="additive", 
      optim.start = c(alpha = 0.2, beta = 0.1, gamma = 0.1))
Lstat
  • 1,450
  • 1
  • 12
  • 18
  • Looks promising. I have tried this but I get this error message. Error in hw(p[1L], p[2L], p[3L]) : object 'C_HoltWinters' not found – Jonty5817 Aug 10 '17 at 10:57
  • I should have added that I am using Rstudio – Jonty5817 Aug 10 '17 at 11:07
  • I got a similar error when I tried to save the function under different name. Have you tried R Gui? – Lstat Aug 10 '17 at 11:09
  • Have just found the RGui programme. It works, but is there a way to do this as a batch process without needing to run fix() every time? – Jonty5817 Aug 10 '17 at 11:37
  • I can only think of rewriting the function and saving it under different name. I tried to do it but some errors occurred and I don't know how to solve it now. That's why I only posted this one-session solution. – Lstat Aug 10 '17 at 11:49
  • It looks like it is looking for a c file C_HoltWinters and getting confused see [link](https://stackoverflow.com/questions/36438723/r-wont-reference-cant-find-a-compiled-loaded-c-code) – Jonty5817 Aug 10 '17 at 13:44