2

I'm trying to reuse a HoltWinters model previously generated in R. I have found a related entry here, but it does not seem to work with HoltWinters. Basically I have tried something like this:

myModel<-HoltWinters(ts(myData),gamma=FALSE)
predict(myModel,n.ahead=10)

#time to change the data
predict(myModel,n.ahead=10,newdata=myNewData)

When I try to predict using the new data I get the same prediction.

I would appreciate any suggestion.

Community
  • 1
  • 1
Juan
  • 23
  • 2

2 Answers2

3

You can use update:

mdl <- HoltWinters(EuStockMarkets[,"FTSE"],gamma=FALSE)

predict(mdl,n.ahead=10)
Time Series:
Start = c(1998, 170) 
End = c(1998, 179) 
Frequency = 260 
           fit
 [1,] 5451.093
 [2,] 5447.186
 [3,] 5443.279
 [4,] 5439.373
 [5,] 5435.466
 [6,] 5431.559
 [7,] 5427.652
 [8,] 5423.745
 [9,] 5419.838
[10,] 5415.932

predict(update(mdl,x=EuStockMarkets[,"CAC"]),n.ahead=10)]
Time Series:
Start = c(1998, 170) 
End = c(1998, 179) 
Frequency = 260 
           fit
 [1,] 3995.127
 [2,] 3995.253
 [3,] 3995.380
 [4,] 3995.506
 [5,] 3995.633
 [6,] 3995.759
 [7,] 3995.886
 [8,] 3996.013
 [9,] 3996.139
[10,] 3996.266
James
  • 65,548
  • 14
  • 155
  • 193
3

predict.HoltWinters doesn't have a newdata argument, which is why the data doesn't get replaced. This is because the prediction doesn't require any data – it is described entirely by the coefficients argument of the model.

m <- HoltWinters(co2)
m$coefficients         #These values describe the model completely; 
                       #adding new data makes no difference
Richie Cotton
  • 118,240
  • 47
  • 247
  • 360