# How to fit an ARIMA model with multiple/complex seasonality in R

My dataset contains the following information aggregated into 5-minute intervals over one month:

1. average vehicle speed in km/h
2. time of the observations
3. the day of the week

Thus having 288 (12*24) data points a day. I'm trying to predict the average vehicle speed during the peak hours of the day with a seasonality of 24 hours as well as considering the day of the week by including dummy variables as xreg. However, I don't know if this is the right approach to deal with multiple / complex seasonality in daily data.

My code is the following:

speed <- ts(data$$avgVehicleSpeed, frequency = 288) xreg <- model.matrix(~factor(data$$day)+0)[, 2:7]

arima <- auto.arima(speed, seasonal = TRUE, xreg = xreg)
forecast <- forecast(arima, h = 12, xreg = xreg)


However, when running this code the auto.arima function takes FOREVER to run. Even a predetermined ARIMA model with the same inputs takes very long to run. I have a feeling that it's because of frequency = 288. So my question is, why does R takes so long to determine the "best" ARIMA model for the given inputs? Or what am I doing wrong trying to fit the seasonal ARIMA model.

## 1 Answer

auto.arima() searches for the best ARIMA model in a stepwise fashion, by changing the AR or MA orders and refitting. This can indeed take a long time, especially for long seasonality (in your case, 288 observations to a cycle), since each fit takes a while, and since there are many possible models.

I would indeed recommend that you look into models that specifically address the (intra-daily and intra-weekly) present in your data, e.g. or . Both are readily available in the forecast package.