4

I have 10 minutes-intervaled wait-times data for a coffee shop for 4 weeks between 9am-5pm. I use R's ts for my analysis. What should be the frequency parameter?

Is it (48=# of intervals per day) or just 1?

fatih
  • 201
  • 1
  • 3
  • 7

1 Answers1

7

Most likely you have two seasonal periods: 48 (number of intervals per day) and 48x5 (number of intervals per week assuming a 5-day week).

The tbats() function from the forecast package in R will handle multiple seasonal periods. For example (where x is the data):

library(forecast)
x <- msts(x, seasonal.periods=c(48, 48*5))
fit <- tbats(x)
fc <- forecast(fit, h=48*5)
plot(fc)

Alternatively (and the only easy option if there are missing data) is to use Fourier terms for the seasonal periods and ARMA errors to handle any remaining serial correlation. The ARIMA functions in R do not automatically handle multiple seasonal periods, but the following R code should work:

x <- ts(x, frequency=48)
seas1 <- fourier(x, K=3)
seas2 <- fourier(ts(x, freq=48*5), K=3)
fit <- auto.arima(x, xreg=cbind(seas1,seas2))

seas1.f <- fourierf(x, K=3, h=48*5)
seas2.f <- fourierf(ts(x, freq=48*5), K=3, h=48*5)
fc <- forecast(fit, xreg=cbind(seas1.f,seas2.f))

The number of Fourier terms (arbitrarily set to 3 for both seasonal periods in the above code) can be selected by minimizing the AIC.

Rob Hyndman
  • 51,928
  • 23
  • 126
  • 178
  • Thanks Rob! In third week, Friday is missing, so if I give (48x5) as the periods it won't work. How to deal with this? – fatih Nov 03 '13 at 13:32
  • 1
    I've updated the answer for dealing with missing values. – Rob Hyndman Nov 03 '13 at 22:42
  • @RobHyndman I am having a little trouble with time series in R. I have created a [question](http://stats.stackexchange.com/questions/226713/creating-time-series-for-data-sampled-daily-in-r) for it. Could you please take a look? – Rahul Sharma Aug 01 '16 at 16:44