Fitting a TBATS model for complex seasonality

Today let's understand a model built for a series that repeats on more than one clock at once, and watch it work out every piece of that seasonal pattern for itself, without you specifying a single term by hand.

Here's the running example. Victoria, the Australian state, records its electricity grid demand from half-hourly meters. Average that into hourly totals and take three consecutive weeks in winter, 504 hours of real demand in megawatts (MW), from the Australian Energy Market Operator.

Plot the hour index, 1 through 504, against that hour's demand.

The line climbs and falls once a day, and riding on top of that a slower rise and fall repeats once a week: notice how the whole shape sits a little higher in the middle stretch of the plot than at either end.

What each letter in TBATS stands for

TBATS is a name built from five letters, and every one of them names one piece this model adds on top of a plain forecast.

  • T, Trigonometric seasonal terms. A repeating shape represented as a pair of numbers for each seasonal period, and that pair is allowed to update at every new observation instead of staying fixed for the whole series. A model like this one is called a state space model, and "state" just means a number, or a small set of numbers, the model keeps in memory and updates as new data arrives, rather than one number chosen once and never touched again.
  • B, Box-Cox transformation. A power transform on the raw series, controlled by one number called lambda, that steadies a swing that grows or shrinks along with the level of the series, before anything else gets fit.
  • A, ARMA errors. Once trend and season are pulled out, whatever short-run pattern is still left in the residuals, the gap between the fitted value and the real one at each hour, gets modeled with an ARMA process: p of its own recent lags (the autoregressive part) and q of its own recent forecast errors (the moving average part).
  • T, Trend. A smoothed level, meaning a running estimate of the series' typical size that updates a bit at a time, together with an optional slope for how fast that level climbs or falls, and an optional damping parameter that can flatten that slope out the further into the future the forecast reaches.
  • S, Seasonal. However many periods repeat in the series get modeled at once. This series carries two, a 24-hour day and a 168-hour week, and TBATS is not capped at two the way seasonal ARIMA is capped at one.

Notice T appears twice, once for Trigonometric and once for Trend. They are two different letters describing two different pieces of the model, and this lesson will name them out in full each time to keep them apart.

Start with B, the Box-Cox transformation, since it acts on the raw series before anything else does.

\[ w_t = \begin{cases} \dfrac{y_t^{\lambda} - 1}{\lambda} & \lambda \neq 0 \\[4pt] \log(y_t) & \lambda = 0 \end{cases} \]

Here \(y_t\) is demand at hour \(t\) in its original megawatt units, and \(w_t\) is demand after the transform. Set \(\lambda = 0\) and the formula becomes \(\log(y_t)\), an ordinary log. Set \(\lambda = 1\) and it becomes \(y_t - 1\), the series shifted down by one, so its shape barely changes at all. Every value between those two extremes reshapes the series somewhere in between those two, pulling large values in harder than small ones, which is exactly what steadies a swing that would otherwise grow along with the level of demand.