stick function for the EDA in time series

You have probably seen my post about the STI classification of Hans Levenbach (this one). Well, I’ve decided to implement it, and it has landed in the greybox package for R/Python.

What’s greybox? It is a package for statistical modelling focusing on forecasting and time series analysis. I created it back in 2018 to split the static models (such as linear regression) from the dynamic ones that landed in the smooth package. Greybox has evolved since then, and now has linear regression (alm), regression selection (stepwise) and combinations (calm), a variety of tools for feature generation, diagnostics, forecast evaluation (e.g. rolling origin) etc. You can read more about it here. Originally, the package was available for R only, but Claude and I ported its main functions to Python back in February.

The Exploratory Data Analysis techniques for time series fit the package quite well, although I don’t have many of those yet. So, I’ve implemented the main idea of the STI of Hans Levenbach in a function called “stick” (Seasonal, Trend, Irregular Contribution Kit) in the greybox package for R/Python. The idea is straightforward: apply stick to a time series, it will use ANOVA, and give you the strength of each component. Here, for example, is how to apply the function to the AirPassengers data (everyone’s favourite toy time series) in R:

library(greybox)
stick(AirPassengers)

and in Python:

from fcompdata import AirPassengers
from greybox import stick

result = stick(AirPassengers.y, lags=12)
print(result)

which gives exactly the same result:

Strength of the components:
seasonal12      trend  irregular
    0.1061     0.8613     0.0326

So, trend dominates the time series, explaining 86.13% of its variability, meaning that if you capture it correctly, you solve a big chunk of the problem. This split also gives you a rough idea about the structure-versus-noise breakdown in the time series, although it assumes that the seasonal component does not evolve over time.

The function supports several seasonal components, and I might extend it to include external information (e.g. promotions) in the future if there is demand for it.

Leave a Reply