timeline - seasonality detection (I)
This interactive visualization tests a time series for seasonality by comparing it against a shifted version of itself. The left panel displays the original series and its lagged copy as draggable points, while the right panel plots the correlation coefficient for different shift amounts. Users can adjust the suspected season length and the magnitude of the seasonal component. The D3 v3 code computes autocorrelation values, visually linking the lagged timeline, the correlation plot, and a bar chart. Data comes from a CSV file and is rendered as SVG with animated transitions.
AI-generated descriptionIf you suspect a time serie has a seasonality component, this is an example of how to validate/invalidate this hypothesis.
Seasonality means that the time serie has a periodic component, repeating the same pattern on each period. For example, sales of a store may have a week-based seasonality: sales increase on saturday, while there is no sale at all on sunday.
Graphically speaking, detecting a seasonality is (quite) easy: just look for a repeating pattern. Note that it could be difficult if the pattern has a long period, or/and the order of magnitude of the seasonilaty is low (ie. lowest and highest values are not so far from the season's mean, but in this case there might be no seasonality at all ! ).
Computationnaly speaking, one can use the autocorrelation technique. Correlation is a technique that allows to determine if 2 time series are correlated (ie. if they behave in the same way). Autocorrelation is the same technique applied to only 1 time serie: it allows to compare the correlation between a time serie and the same time serie shifted by a certain amount of time. Hence, if you suspect a seasonality of 7 days, then the autocorrelation between the time serie and the same time serie shifted by 7 days will validate (autocorrelation near 1) or invalidate (autocorrelation near 0) the seasonality.
Usages :
- in the left graph, Drag & Drop points to update the timeline and create seasons of your choice (below the graph are some shortcuts)
- then test for a particular seasonality period, and see how the coefficient of correlation behaves;
- decrease the order of magnitude of the season component to see that when this order is small, then it becomes difficult to detect a season; this is because the coefficient of correlation is constantly high; even for the test of a suspected season's length that is not the real one.
Notes:
- another <a href='http://bl.ocks.org/Kcnarf/1e6da47724c39156adb3'>block</a> explains time series correlation
- another <a href='http://bl.ocks.org/Kcnarf/0a8fe1caa2ac025c8e86'>block</a> deals with the impact of seasonality when computing the trend of a timeline
Acknowledgments:
- done with D3 v3.5.5
- <a href='http://blockbuilder.org'>blockbuilder.org</a>