Solved – Seasonal naive in forecast package with multi-step prediction

forecastingrtime series

I am working on predicting a time series of daily data for one month that looks like this:
Time-series daily data

As can be seen, the time-series has a weekly seasonality. I am trying to predict the next week's data (horizon=7), updating my forecasts every day, so at each time-step, I am getting forecasts for the next 7 time-steps.

I have tried a number of methods but I would expect at least the snaive method to give me something reasonable. The code I am using is (tseries is an XTS object with the daily data):

for (t in horizon:(length(a)-horizon)) { # Every day
  timeseries <- ts(a[1:(t+horizon)], frequency=7)
  fit <- snaive(timeseries[1:t], h=horizon)
  plot(forecast(fit, h=horizon))
  lines(1:(t+horizon),timeseries, col='black')
}

The method consistently gives me flat predictions, looking like this:
SNaive prediction for the next 7 days

Has anyone had any similar problems? Is it because I set frequency=7 for my daily data?

Best Answer

The answer from the comment of RandomDude:

fit <- snaive(ts(timeseries[1:t],freq=7), h=horizon) 

snaive() gives you already a forecast btw

It did not work probably because of the way how the user sliced the ts-object, he actually just extracted the values

Related Question