2
$\begingroup$

With the below code, I have run Holt's linear and Holt-Winters forecasts using Excel / Solver. I wanted to replicate this using R (Excel can be a pain) but I am getting the below error with hw().

It is my first time running this with R so I am trying to go by the docs. I assume running the function will pick the initialization and also optimize the parameters? Or am I way off?

Either way, I thought hw() would work, but clearly I am doing something wrong here.

   x<-c(12638.8,11583.3,13024.1,12594.2,13068.1,12765.4,13125.6,13316.3,13054.7,13879.3,14436.6,17861,13923.8,12418.4,13854.4,13558.8,14335,13639.9,14132.2,14457.2,14045.4,14941.2,15556,18984.2,14825.5,13138.3,14473.6,14507.6,15055.9,14384.2,15199.7,15169.7,15223.5,16412.9,16662.9,20638.9,16154.8,14696,15793.8,15804.2,15895,15868.6,16435.6,15945.9,16381.4,17084.2,17261,21652.6,16330.6,14840.5,16419.8,16104.2,16326.2,16453.4,16750.3,16678,16816.4,17431.7,17920.6,22491.3,17016.6,15534.8,17339.2,17065.6,17313.3,17448.2,17617.5,17814.2,17747.6,18592.4,19223.3,23636.1)
    x.ts <- ts(x, start=2001, frequency=12)

plot(x.ts)

####Holt's Linear
holt(x, h=12, damped=FALSE, level=c(80,95), fan=FALSE, 
    initial=c("optimal"), exponential=FALSE,
    alpha=NULL, beta=NULL)

#Holt-Winters
hw(x, h=2*frequency(x), seasonal="multiplicative", damped=FALSE, 
    level=c(80,95), fan=FALSE, initial=c("optimal"), 
    exponential=TRUE, alpha=NULL, beta=NULL, gamma=NULL)

# hw gives the following error
#Error in ets(x, "AAA", alpha = alpha, beta = beta, gamma = gamma, damped = damped,  : Nonseasonal data
$\endgroup$
2
  • $\begingroup$ Some confusion here. Holt was the supervisor and Winters was his student and co-author. Their methods are thus often known as Holt-Winters. Nothing to do with the season "winter". $\endgroup$
    – Nick Cox
    Oct 8, 2013 at 14:38
  • $\begingroup$ Corrected title. Cheers for the spot. $\endgroup$
    – digdeep
    Oct 8, 2013 at 14:43

1 Answer 1

2
$\begingroup$

The error tells you the problem. You have passed non-seasonal data to hw(). Note that you have passed x rather than x.ts to both functions.

$\endgroup$
5
  • $\begingroup$ Wow that was a comical error. (late night coding) Thanks for the response. Looking at the HoltWinters() function this morning, is this the preferred method? If my dataset is a seasonal Multiplicative data set, is this the only thing that needs to be coded using R that will estimate and optimise the parameters, (m <- HoltWinters(AirPassengers, seasonal = "mult")) $\endgroup$
    – digdeep
    Oct 9, 2013 at 0:20
  • $\begingroup$ You are better off using ets() from the forecast package. It includes Holt-Winters as a special case, but provides a much richer class of models and selects the best one for you. $\endgroup$ Oct 9, 2013 at 3:54
  • $\begingroup$ Thanks for the tip. Using ets() I would specify ets(x.ts, model="MAN" with the opt.crit=c("mse") for Holt's Linear and for Holt-Winters' model="MAM" I want to be able to demonstrate the differences between these 2 models rather than let the algorithm decide which model best suits. $\endgroup$
    – digdeep
    Oct 9, 2013 at 4:55
  • $\begingroup$ Use model="ZAN" for Holt and "ZAM" for Holt-Winters additive. The Z allows ets() to decide if you it is better to use an additive or multiplicative error. And use damped=FALSE if you don't want damping. $\endgroup$ Oct 9, 2013 at 11:36
  • $\begingroup$ Great! tks. Does the algorithm iterate through the parameters? I left alpha=NULL, beta=NULL and I used opt.crit=c("mse") However, the number produced for the ZAN model is 2490139. I tested for arbitrary parameter of 0.5 for both alpha and beta and the number is even bigger. Is the 2490139 an acceptable value for MSE? seems rather large.. Or is this because the data set I am using is multiplicative (tested using model="ZZZ") & using a model that does not factor seasonal will produce this large number? Where as model="ZAM" does a much better job because it factors seasonal with HW model. $\endgroup$
    – digdeep
    Oct 9, 2013 at 23:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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