Hierarchical and grouped time series
Today let's understand how a set of related time series is organised, and why that organisation decides how you can forecast it.
Let's say you plan tourism for two Australian states, Tasmania and Western Australia. Tourism Research Australia counts the overnight trips visitors make, every quarter, from 1998 Q1 to 2016 Q4. Tasmania has 5 tourism regions and Western Australia has 5.
The planning team wants three kinds of forecast: one for the two states together, one for each state, and one for each region.
So the team is not forecasting one series. It is forecasting a set of series where each higher one is the sum of the lower ones.
The widget shows the three levels, and together they hold 13 series: 1 + 2 + 10.
The bottom-level series in a tidy table
Let's start with the data, because everything in this lesson is built from it.
The tourism table lives in the tsibble package. A tsibble is a data frame for time series with two extra ideas. The index is the column that holds the time, here Quarter. The keys are the columns that together identify one series, here Region, State and Purpose.
We keep the two states and every quarter up to 2016 Q4. The call filter_index(. ~ "2016 Q4") does the second part: the dot stands for the start of the data, so it keeps everything up to and including 2016 Q4. Press Run.
tsibble gives the data structure, fabletools gives aggregate_key() and fable gives the forecasting models, so all three are loaded.
The range confirms the window: 1998 Q1 to 2016 Q4, which is 76 quarters. There are 3,040 rows and 40 keys. Each row is one quarter of one series, and 40 series times 76 quarters gives 3,040.
Each series is one region and one purpose of travel, which is Business, Holiday, Other or Visiting. The first one in the output is business trips in Australia's Coral Coast, and Trips is the number of overnight trips, in thousands. These 40 are the bottom-level series: the finest series the data gives us.
Now let's list each region with the state it sits in.
There are 10 regions, 5 in each state, so 10 regions times 4 purposes gives the 40 series. Every region appears under one state only. That one-state-per-region property is what a hierarchy is built on.