Fulfilling Social Responsibility Via Technology

Technology has transformed life as we know it, and now SAP is harnessing the power of technology to make the world a better place.

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Forecasting Hierarchical Time Series using R

Time series can often be naturally disaggregated in a hierarchical structure using attributes such as geographical location, product type, etc. For example, the total number of Member of Parliaments(MPs) in a given election can come from different States and in turn given a particular State ,from different cities, districts and so forth.Such disaggregation imposes a hierarchical structure. We refer to these as hierarchical time series.

Another possibility is that series can be naturally grouped together based on attributes without necessarily imposing a hierarchical structure. For example the MPs in the above context can be filtered down also on the basis of sex viz.Male ,Female and Others. Grouped time series can be thought of as hierarchical time series that do not impose a unique hierarchical structure in the sense that the order by which the series can be grouped is not unique.

Though in this blog we will talk solely about hierarchical time series though grouped time series can also be handled symmetrically.

Let’s plot some hierarchical time series below.This one pertains to Total quarterly visitor nights from 1998–2011 for eight regions of Australia:

I will show below some graphs and tables pertaining to the Data at hand so as to expose it better.

Australia Visitor Nights Hierarchy

Pretty self explanatory right.

Pretty simple right !

Now implementing this is even simpler.I will demonstrate a working example via one of the above techniques and rest one can catch up via the documentation of hts package in R language.

The above command creates a hierarchical time series with 3 levels(top most level one does not have to specify) with 4 nodes/states in the middle and 8 nodes/cities in bottom most level.(Argument ‘nodes’ does the trick for you here,also notice 2 cities are tagged to each state.)

Forecasts across all the Hierarchies

The above command will give you forecasts(dotted lines in respective colours are the forecasts) across all levels in the hierarchy using top-down forecast proportions approach discussed above for 8 periods(quarters in our case) ahead.

Just to reiterate:

Below animation captures forecast by various(some) combinations of parameters/methods.

Animation capturing forecasts across hierarchy using different algorithms.

In this post we have been able to learn from scratch(atleast at an applied and intuitive) level how open source tools like R and hts package can be leveraged to build time series models quite simply in complicated hierarchical structural data for forecasting purposes.

Also many things have been missed out courtesy paucity of space and time but in the above framework in lieu of Arima or classical statistical models one can define user defined function as well for prediction purposes which suits the context. There are many other great things one can explore in this amazing package/module.

Hope this blog was helpful.See you soon then.

Peace…

Add a comment

Related posts:

Choosing One of the Best Rental Home Cleaning Nashville Services

There are many different types of Rental Home Cleaning Nashville services that can be done. When homeowners get busy, they need to find someone to fill in where they cannot. They may need someone to…

My Binance Story

I started the first investment on the Binance exchange in September, 2017. What impressed me the most was a highly stable exchange. With new users like me, Binance provides simple, easy-to-use and…

The Importance of Choosing the Right Nursing Home for Your Loved One

Choosing the right nursing home for your loved one is not an easy task. There are so many nursing homes in the country and many of them are good and many are not so good. Thus, narrowing down the…