{ "cells": [ { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" }, "tags": [] }, "source": [ "# Forecasting hierarchical or grouped time series\n", "\n", "\n", "## Feng Li\n", "\n", "### Guanghua School of Management\n", "### Peking University\n", "\n", "\n", "### [feng.li@gsm.pku.edu.cn](feng.li@gsm.pku.edu.cn)\n", "### Course home page: [https://feng.li/bdcf](https://feng.li/bdcf)" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "\n", "\n", "- We discuss forecasting large collections of time series that must add up in some way. \n", "\n", "- The challenge is that we require forecasts that are **coherent** across the aggregation structure. \n", "\n", " That is, we require forecasts to add up in a manner that is consistent with the aggregation structure of the collection of time series. \n", " \n", "- We discuss several methods for producing coherent forecasts for both hierarchical and grouped time series." ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "## Hierarchical time series: Australian tourism\n", "\n", "- Australia is divided into six states and two territories, with each one having its own government and some economic and administrative autonomy. \n", "\n", "- For simplicity, we refer to both states and territories as “states”. Each of these states can be further subdivided into regions. \n", "\n", "- In total there are 76 such regions. Business planners and tourism authorities are interested in forecasts for the whole of Australia, for each of the states and territories, and also for the regions." ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "![Austrilia](figures/ausmap.png)" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "![HTS](figures/hts.png)\n", "\n", "- A simple hierarchical structure. At the top of the hierarchy is the “Total”, the most aggregate level of the data.\n", "\n", "- The total number of series in the hierarchy is $n=1+2+5=8$, while the number of series at the bottom level is $m=5$. Note that $n>m$ in all hierarchies." ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "# Matrix notation \n", "\n", "\\begin{equation*}\n", "\\begin{bmatrix}\n", " y_{t} \\\\\n", " y_{A,t} \\\\\n", " y_{B,t} \\\\\n", " y_{AA,t} \\\\\n", " y_{AB,t} \\\\\n", " y_{AC,t} \\\\\n", " y_{BA,t} \\\\\n", " y_{BB,t}\n", "\\end{bmatrix}\n", " =\n", " \\begin{bmatrix}\n", " 1 & 1 & 1 & 1 & 1 \\\\\n", " 1 & 1 & 1 & 0 & 0 \\\\\n", " 0 & 0 & 0 & 1 & 1 \\\\\n", " 1 & 0 & 0 & 0 & 0 \\\\\n", " 0 & 1 & 0 & 0 & 0 \\\\\n", " 0 & 0 & 1 & 0 & 0 \\\\\n", " 0 & 0 & 0 & 1 & 0 \\\\\n", " 0 & 0 & 0 & 0 & 1\n", " \\end{bmatrix}\n", " \\begin{bmatrix}\n", " y_{AA,t} \\\\\n", " y_{AB,t} \\\\\n", " y_{AC,t} \\\\\n", " y_{BA,t} \\\\\n", " y_{BB,t}\n", " \\end{bmatrix}\n", "\\end{equation*}\n", "\n", "or in more compact notation \n", "\n", "\\begin{equation}\n", " \\mathbf{y}_t=\\mathbf{S}\\mathbf{b}_{t},\n", "\\end{equation}" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "# Mapping matrices\n", "\n", "- Suppose we forecast all series ignoring any aggregation constraints. We call these the base forecasts and denote them by $\\mathbf{y}_h$ where $h$ is the forecast horizon. They are stacked in the same order as the data $\\mathbf{y}_t$.\n", "\n", "- Then all **coherent** forecasting approaches for either hierarchical or grouped structures can be represented as\n", "\n", "\\begin{equation}\n", " \\tilde{\\mathbf{y}}_h=\\mathbf{S}\\mathbf{G}\\hat{\\mathbf{y}}_h,\n", "\\end{equation}" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "- The $\\mathbf{G}$ matrix is defined according to the approach implemented. For example if the **bottom-up** approach is used to forecast the hierarchy, then \n", "\n", "\\begin{equation*}\n", "\\mathbf{G}=\n", " \\begin{bmatrix}\n", " 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0\\\\\n", " 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0\\\\\n", " 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0\\\\\n", " 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0\\\\\n", " 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1\\\\\n", " \\end{bmatrix}\n", "\\end{equation*}\n", "\n", "\n", "- If any of the **top-down** approaches were used then\n", "\n", "\\begin{equation*}\n", "\\mathbf{G}=\n", " \\begin{bmatrix}\n", " p_1 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\\\\n", " p_2 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\\\\n", " p_3 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\\\\n", " p_4 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\\\\n", " p_5 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\\\\n", " \\end{bmatrix}.\n", "\\end{equation*}" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "![tourismRegions](figures/tourismRegions.png)" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "![tourismStates](figures/tourismStates.png)" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "# Grouped time series\n", "\n", "- With grouped time series, the data structure does not naturally disaggregate in a unique hierarchical manner. \n", "\n", "- At the top of the grouped structure is the Total, the most aggregate level of the data, again represented by $y_t$. \n", "\n", "- The Total can be disaggregated by attributes (A, B) forming series $y_{A,t}$ and $y_{B,t}$, or by attributes $(X, Y)$ forming series $y_{X,t}$ and $y_{Y,t}$. \n", "\n", "- At the bottom level, the data are disaggregated by both attributes.\n", "\n", "![GroupTree](figures/GroupTree.png)" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "# Forecast reconciliation\n", "\n", "- The traditional methods considered so far are limited in that they only use base forecasts from a single level of aggregation which have either been aggregated or disaggregated to obtain forecasts at all other levels. Hence, they use limited information. \n", "\n", "- However, in general, we could use other $\\mathbf{G}$ matrices, and then $\\mathbf{SG}$ combines and reconciles all the base forecasts in order to produce coherent forecasts.\n", "\n", "- In fact, we can find the optimal $\\mathbf{G}$ matrix to give the most accurate reconciled forecasts." ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "## Further Reading\n", "\n", "- Gross, C. W., & Sohl, J. E. (1990). Disaggregation methods to expedite product line forecasting. Journal of Forecasting, 9, 233–254. DOI: https://doi.org/10.1002/for.3980090304 provide a good introduction to the top-down approaches.\n", " \n", " \n", "- Athanasopoulos, G., Gamakumara, P., Panagiotelis, A., Hyndman, R.J., Affan, M. (2020). Hierarchical Forecasting. In: Fuleky, P. (eds) Macroeconomic Forecasting in the Era of Big Data. Advanced Studies in Theoretical and Applied Econometrics, vol 52. Springer, Cham. DOI: https://doi.org/10.1007/978-3-030-31150-6_21\n" ] } ], "metadata": { "celltoolbar": "Slideshow", "kernelspec": { "display_name": "python3.12", "language": "python", "name": "python3.12" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.9" } }, "nbformat": 4, "nbformat_minor": 4 }