EDA for time series
Today let's understand how to look at a time series properly, before you ever fit a model to it, using one real dataset.
Here is 37 years of real data: the monthly turnover of cafes, restaurants and takeaway food outlets in Victoria, Australia, from April 1982 to December 2018, in $ million. That's 441 months in a row, published by the Australian Bureau of Statistics, plotted once, in full.
Look at that shape for a second. It climbs for nearly four decades, but it is not a smooth climb: small bumps ride on top of it every single year. Everything in this lesson is about reading that shape properly, one piece at a time, before fitting anything to it.
The plots-first workflow and autoplot()
Before you fit anything to a time series, look at it properly first. That is exploratory data analysis, EDA for short, applied to a time series: a short, repeatable checklist you run before any model touches the data.
For a time series, that checklist covers six things, always in this order:
- Shape - what does the series look like, overall?
- Season-and-year summaries - how does it move within a year, and across years?
- Outliers - which points do not fit the pattern the rest of the series follows?
- Calendar effects - do those "outliers" actually repeat every year, at the same point in the calendar?
- Structural breaks - did the whole series shift level at some point?
- Missing runs - are there gaps in the data itself?
You already saw the first item on the cover: the raw shape of the series. To make that same plot in R, use autoplot(), the plotting function built for a tsibble that skips ggplot2's usual setup. Build the tsibble first.
aus_retail is a large keyed tsibble bundled with the tsibbledata package: one series per Australian state and industry. Filtering down to Victoria's cafes, restaurants and takeaway food services leaves one series, 441 months, from April 1982 to December 2018. [1M] in the header says its index moves in fixed 1-month steps.
Now plot it with autoplot().
autoplot() reads the tsibble's index directly, so you only name the column to plot, Turnover, and it draws the line correctly ordered by Month without you writing a single ggplot() call. The plot is the same one from the cover: a level that rises for nearly four decades, an unmistakable trend, with a small wave riding on top of it every year.