# Statistical similarity of time series

Supposing one has a time series from which one can take various measurements such as period, maximum, minimum, average etc. and then use these to create a model sine wave with the same attributes, are there any statistical approaches one can use that could quantify how closely the actual data fit the assumed model? The number of data points in the series would range between 10 and 50 points.

A very simplistic first thought of mine was to ascribe a value to the directional movement of the sine wave, i.e. +1 +1 +1 +1 -1 -1 -1 -1 -1 -1 -1 -1 +1 +1 +1 +1, do the same to the actual data, and then somehow quantify the degree of similarity of directional movement.

Edit: Having given more thought to what I really want to do with my data, and in light of responses to my original question, what I need is a decision making algorithm to choose between competing assumptions: namely that my data is basically linear (or trending) with noise that could possibly have cyclic elements; my data is basically cyclic with no directional trend to speak of; the data is essentially just noise; or it is transitioning between any of these states.

My thoughts now are to maybe combine some form of Bayesian analysis and Euclidean/LMS metric. The steps in this approach would be

Create the assumed sine wave from data measurements

Fit a LMS straight line to the data

Derive an Euclidean or LMS metric for departures from the original data for each of the above

Create a Bayesian prior for each based on this metric i.e. 60 % of the combined departures attach to one, 40 % to the other, hence favour the 40 %

slide a window one data point along the data and repeat the above to obtain new % metrics for this slightly changed data set - this is the new evidence - do the Bayesian analysis to create a posterior and change the probabilities that favour each assumption

repeat along the whole data set (3000+ data points) with this sliding window (window length 10-50 data points). The hope/intent is to identify the predominant/favoured assumption at any point in the data set and how this changes with time

Any comments on this potential methodology would be welcome, particularly on how I could actually implement the Bayesian analysis part.

The Euclidean distance is a common metric in machine learning. The following slides provide a good overview of this area along with references:

Also see the references on Keogh's benchmarks page for time series classification:

If you have a specific model you wish to compare against: I would recommend Least-squares as a metric to minimize and score possible parameter values against a specific dataset. All you basically have to do is plug in your parameter estimates, use those to generate predicted values, and compute the average squared deviation from the true values.

However, You might consider turning your question around slightly: "Which model would best fit my data?" In which case I would suggest making an assumption of a normally distributed error term ~ something one could argue is akin to the least squares assumption. Then, depending on your choice of model, you could make an assumption about how you think the other model parameters are distributed (assigning a Bayesian prior) and the use something like the MCMC package from R to sample from the distribution of the parameters. Then you could look at posterior means & variances to get an idea of which model has the best fit.

• If I have two possible models to fit to my data, the sine wave as described in my original question and a LMS straight line fit, could I simply compare the average squared deviation from the true data values of the sine wave with the residuals of the LMS fit line and then choose the model with the lower overall value on the grounds that this model exhibits a more accurate fit to the data? If so, would it also be valid to perhaps split the data into halves and do the same with each half separately, using the same sine wave/LMS fits to see how each model may be improving/getting worse with time? – babelproofreader Oct 5 '10 at 22:24
• I'm not sure. My suggestion was to use a Least Squares metric, but I wasn't saying to run linear regression. You might check out Periodic Regression. – M. Tibbits Oct 6 '10 at 3:41
• As to your other question, could you cut the data in half, I would be very cautious in doing so -- because that would double the minimum frequency you could consider. I think you may end up needing to look at Fourier coefficients (take an FFT or a DCT and regress on them?!? -- Not sure). Or perhaps periodic regression as mentioned above. – M. Tibbits Oct 6 '10 at 3:47

Your "simplistic first thought" of qualitatively representing just the directional movement is similar in spirit to Keogh's SAX algorithm for comparing time series. I'd recommend you take a look at it: Eamonn Keogh & Jessica Lin: SAX.

From your edit, it sounds like you're now thinking about tackling the problem differently, but you might find that SAX provides a piece of the puzzle.

While I'm a bit late to the party, if you are thinking about anything sinusoidal, wavelet transforms are a good tool to have in your pocket also. In theory, you can use wavelet transforms to decompose a sequence into various "parts" (e.g., waves of different shapes/frequencies, non-wave components such as trends, etc). A specific form of wave transform that is used a ton is the Fourier transform, but there's a lot of work in this area. I'd love to be able to recommend a current package, but I haven't done signal analysis work in quite a while. I recall some Matlab packages supporting functionality on this vein, however.

Another direction to go if you're only trying to find trends in cyclic data is something like the Mann-Kendall Trend test. It's used a lot for things like detecting changes in weather or water quality, which has strong seasonal influences. It doesn't have the bells and whistles of some more advanced approaches, but since it's a veteran statistical test it is fairly easy to interpret and report.