1

I have a seasonal (7 days interval) time series, daily data for 30 days. What is the best approach for a reasonable forecast? The time series contains orders made with a app, it shows a seasonality of 1 week (lower sales at the beginning of the week). I try the holt winters approach with this code:

(m <- HoltWinters(ts,seasonal = "mult"))
 plot(m)
 plot(fitted(m))

but it gives me an error like: Error in decompose(ts(x[1L:wind], start = start(x), frequency = f),seasonal) : time series has no or less than 2 periods

What do you suggest?

EDIT: data here

chopin_is_the_best
  • 1,951
  • 2
  • 23
  • 39

2 Answers2

1

You must first determine a ts object. Assuming your data is called df:

ts <- ts(df$install, frequency = 7)
(m <- HoltWinters(ts,seasonal = "mult"))
 plot(m)
 plot(fitted(m))

enter image description here

Then you can make prediction like (10 steps-ahead):

predict(m, n = 10)
Time Series:
Start = c(4, 5) 
End = c(5, 7) 
Frequency = 7 
            fit
 [1,] 1028.8874
 [2,] 1178.4244
 [3,] 1372.5466
 [4,] 1165.2337
 [5,]  866.6185
 [6,]  711.6965
 [7,]  482.2550
 [8,]  719.0593
 [9,]  807.6147
[10,]  920.3250

The question about the best method is too difficult to answer. Usually one compares the performance of different models considering their out-of-sample accuracy and chooses the one whith the best result.

DatamineR
  • 10,428
  • 3
  • 25
  • 45
  • Thanks for the hint. Do you think theory wise holt winters approach is a reasonable choice? – chopin_is_the_best Nov 15 '15 at 15:13
  • Really difficult to answer. I don't know your data. The HoltWinters method is characterized by its property to give more weight to newer observations. If you can assume for your data that the newer observations are more represenative for the future this might be a reasonable approach. – DatamineR Nov 15 '15 at 15:16
  • thanks. I should test different models and test performance. But: how to plot the real data and the fitted values in the same graph? showing time in x in the right format? – chopin_is_the_best Nov 15 '15 at 15:23
0

You can use df$data to keep the dates that correspond to each day in the ts series.

ts_series <- ts(df$install, frequency = 7)
ts_dates <- as.Date(df$data, format = "%d/%m/%Y")

In a similar way, dates for the forecasted values can be kept in another sequence

m <- HoltWinters(ts_series, seasonal = "mult")
predict_values <- predict(m, 10)
predict_dates <- seq.Date(tail(ts_dates, 1) + 1, length.out = 10, by = "day")

With the dates sequence, the daily series can be plot with dates in x axis with the right format. More control on the x axis ticks can be obtained with the axis.Date function

plot(ts_dates, ts_series, typ = "o"
  , ylim = c(0, 4000)
  , xlim = c(ts_dates[1], tail(predict_dates, 1))
  , xlab = "Date", ylab = "install", las = 1)
lines(predict_dates, predict_values, lty = 2, col = "blue", lwd = 2)
grid()

enter image description here

josep maria porrà
  • 1,198
  • 10
  • 18