Search code examples
rtime-seriespredictionholtwinters

HoltWinters forecast in R


I have a time series divided in 30 days and hour , so 720 values (24h*30).

enter image description here

Every Saturday and Sunday as you can see I have the lowest values at the time series . (It starts from friday).

I divided the time series in 3 week for "train" and 1 for test with the 4th. I applied HoltWinters method at first 3 week and then I did a forecast on 4th week and make a comparison beetween observed value and simulated.

Test<-function(ID,Unique,i){
  DfIn<-ID$V4[1:552]
  DfReal<-ID$V4[553:720]
  x<-ts(data=DfIn,frequency=24)
  HW<-HoltWinters(x,beta = FALSE)
  Pred<-forecast.HoltWinters(HW,168)
  print("Accuracy")
  print(accuracy(Pred,DfReal))
  Box1<-Box.test(Pred$residuals,type="Ljung-Box")
  P<-Box1$p.value
  return (P)
}

This is the comparison enter image description here where Blue line are simulated value and Red line are observed value.

The problem is , why simulated value don't follow the red line when timeseries got the lowest value on saturday and sunday? Is there a way to get more accuracy and let prediction to be more similar to observed?

Update:

enter image description here


Solution

  • You might try

    x<-ts(data=DfIn,frequency=7*24)