# Similarity of time series

I try to find out the smallest window size for calculating statistical values on a stream. To illustrate my problem: I record the average car counts per brand on a street using different sliding windows. The graphs below show the average value using sliding windows from 90 to 7200 seconds. Of course the absolute figures are different, because if a window is larger then more values can be counted, but the time-series progress look very similar. Thus I assume that window size of 90 seconds is sufficient to decently reflect the average car count per brand.

Now my question is thus, how do I not only visually but correctly provide statistical evidence for the similarity of the time-series data and determine a reasonable lower size of the sliding window?

Or to say, why should I "slow down" my system by using data from a 7200 second window, if I can do everything with data from 90 seconds.

The histogram of the data suggest the data is not normally distributed, thus I used Spearman's rank correlation. The correlation values are all above 0.8, which would support my claim. But is this test reasonable for this purpose and are there any methods better suited for this type of analysis?

ARMA or should I do tests on the distributions of the moving average values, like Kruskal-Wallis for the distribution itself or Levene's test for the variances?

• But if I use a sliding window of only 30 seconds for instance, the values fluctuate more, but it seems that the small window nevertheless approximates the values of the large window very well. Commented Jul 30, 2014 at 21:28
• I believe that you can use dynamic time warping (DTW) as an analytic approach to assessing similarity of time series. Please see my answer for more details and resources. Commented Jan 13, 2015 at 7:25
• Frank I just edited your question to replace "correctly statistically prove" (which doesn't really have a coherent meaning in my opinion), with "correctly provide statistical evidence," which is what I think you are asking about. Let me know if you disagree, and I will roll it back. Commented Oct 19, 2015 at 20:26

After one forms what might be regarded as a common model ( perhaps slightly over-specified) one could incorporate anomaly detection http://www.unc.edu/~jbhill/tsay.pdf to obtain robust model parameter estimates for each series separately. It would then be straightforward to globally estimate parameters and then perform a CHOW TEST http://en.wikipedia.org/wiki/Chow_test for the constancy of parameters across the K groups. AUTOBOX http://www.autobox.com/cms/ a piece of software that I have helped develop uses this test to evaluate the constancy of parameters over time. There is a free 30 day version that might be useful to you to demonstrate what I have laid out here.

• Thanks I'll definitely have a look. In the meantime do you think that the Spearman, Levene and Kruskal-Wallis test are valid in this scenario, too? In fact I'm not interested in predicting any future values, but I want to verify that it is valid to use the small windows for calculation instead of the larger ones. Commented Jun 1, 2014 at 15:23
• No. The idea here is to account for time series "complications" . Forecasting is not in play for you but it could be ! Commented Jun 1, 2014 at 22:13

I'm puzzled why you would want to prove that using the same data with the same procedure -- except for window width -- would give similar results. Why would you expect anything different? I must be misunderstanding somewhere...

If my understanding is correct, you could do something like a mathematical proof by induction on the size of the window (W), with a difference between a window of size W and W-1, D. I don't think you actually need any statistical test or even any real data.

(If you use a statistical procedure, you also need to account for the fact that time series are usually autocorrelated, which can fool you.)

• You've hit a point, I was also thinking about. Why should the larger window values differ from the smaller ones, if I use the same raw data and the same procedure. But I can't wrap my head around how to correctly formulate the problem then. I mean, I can't definitely use a window size of 1 second instead of e.g. 3600 seconds, because this wouldn't reflect any properties of the data. But how to determine the critical mass/size of the window, from which on it doesn't matter if I increase its size? Commented Jun 2, 2014 at 15:02
• Again, proof by induction. Base case is a window of width 1, i.e. the original points for a difference of zero. If you have a window width of N and add a point on each side for a window of width N+2, how much can those two points change your average? Well, calculate the greatest difference between any two points in the time series, let's call it D. Etc... Commented Jun 2, 2014 at 23:43
• Just happened to return to this "problem". I'm not a mathematician. Therefore I don't know how to this via induction. Commented Jul 31, 2014 at 4:00
• @FrankD: You can look up mathematical induction on wikipedia, but the basic idea is: Prove that some property that you're interested in holds true in a base case -- in this example a window width of 1. Then assume that the property is true for a window width of W, and prove that it will still hold true for a window width of W+1. If you can to that, you've proved it holds true for all W: you proved it for W=1, so by your second proof it holds true for W=1+1=2, and thus for W=2+1=3, and so on for all W. Commented Nov 19, 2015 at 20:39

The mathematical tool that you're using is called a filter, it does convolution of sorts. In your case it's probably the simplest form of filtering: summation or equal weight moving average (the same thing).

These filters have certain frequency characteristics, e.g. your filter cuts out high frequencies, i.e. it's a low pass filter.

You're looking for optimal window size. What is optimal depends on what you're looking for. The name low pass implies that you probably don't want high frequencies, at the same time you don't want to lose too much information (you cal it slow).

I assumed here that by sliding you meant a moving average filter, i.e. something like this: $y_h(t) = \sum_{i=0}^{h-1} y(t-i)$, where $h$ is window size and $t=0,1,2,...\infty$.
Notice, this is not the same as down sampling, where $t=0,h,2h,...\infty$.