# Quantifying similarity between two data sets

Summary: Trying to find the best method summarize the similarity between two aligned data sets of data using a single value.

Details:

My question is best explained with a diagram. The graphs below show two different data sets, each with values labeled nf and nr. The points along the x-axis represent where measurements were taken, and the values on the y-axis are the resulting measured value.

For each graph I want a single number to summarize the similarity of nf and nr values at each measurement point. In this example it's visually obvious that the results in the first graphs are less similar than the ones in the second graph. But I have a lot of other data where the difference is less obvious, so being able to rank this quantitatively would be helpful.

I thought there might be a standard techniques that is typically used. Searching for statistical similarity has given a lot of different results, but I'm not sure what is best to pick or if things I've ready apply to my problem. So I thought this question might be worth asking here in case there is a simple answer. • You may want to look at this paper which has a plethora of measures listed. (users.uom.gr/~kouiruki/sung.pdf) If the link doesn't work its called "Comprehensive Survey on Distance/Similarity Measures Between Probability Density Functions" by Sung-Hyuk Cha in the International Journal of Mathematical Models and Methods in Applied Science which reviews a plethora of measures of similarity. – arie64 Dec 1 '16 at 5:43
• Dynamic Time Warping is used to measure the similarity between two time-series. This technique can do the task here. Check this link: en.wikipedia.org/wiki/Dynamic_time_warping – Aman Anand Jun 19 '19 at 19:59

Area between 2 curves may give you the difference. Hence sum(nr-nf) (sum of all differences) will be an approximation of the area between 2 curves. If you want to make it relative, sum(nr-nf)/sum(nf) can be used. These will give you a single value indicating similarity between 2 curves for each graph.

Edit: Above method of sum of differences will be useful even if these are separate points or observations and not connected lines or curves, but in that case, mean of differences can also be an indicator and may be better since it would take into account the number of observations.

• I'll try this and see how it works. I'm still hoping to be able to relate it to a more formalized technique. I've been reading about Euclidean Distance and it seems like it's pretty similar to the technique here. Also as an additional note even though my graph has connecting lines I only care about the individual points. I'm not really comparing curves, just the measured values. I don't know if that was clear in my question. – Gabriel Southern Mar 19 '15 at 4:36
• It should work even if the points are not connected. – rnso Mar 19 '15 at 5:12

You need to define more what you mean by 'similarity'. Does magnitude matter? Or only shape?

If only shape matters, you'll want to normalize both time series by their max value ( so they are both from 0 to 1).

If you are looking for a linear correlation, a simple pearson correlation will work fine - which essentially measures the covariance.

There are other techniques, for instance, that could fit a line or polynomial to the time series (essentially smoothing it), and then comparing the smooth polynomials.

If you are looking for periodic similarity (i.e. the time series has a certain sinusoidal component or seasonality), consider using a time series decomposition into the trend, and seasons components first. Or using something like FFT to compare the data in the frequency domain.

Thats about all I know without more definition of what 'similar' should be. Hope it helps.

You could use (nr-nf) for every measurement point, the smaller the number (absolute value) the more similar the value. Not exactly the most scientific approach, please forgive me, I have no real formal training in this stuff. If you are just looking for a numerical representation of the visual, that ought to do it.

• Thanks for your suggestion. I thought about that too, but the problem is it will be weighted by the absolute difference rather than the relative difference. In the example I included the more similar data sets also had smaller absolute values, but if the situation were reversed you could get an incorrect interpretation using this technique. I need to summarize the relative similarity/difference rather than an absolute difference. – Gabriel Southern Mar 19 '15 at 1:13
• Would (nr-nf)/nf work? That would get you relative. I'm really interested in seeing the real answer since I'm dealing with the same sort of situation myself. – Mike G Mar 19 '15 at 1:45
• If they're all on a comparable scale the fact that your similar ones are generally lower isn't about relative values, it's about interpretation of the similarity. If the values in the second graph ranged from 101-104 would it change the interpretation of their similarity? If so, you need to explain that. More details on what exactly the y-variable is would be necessary. – John Mar 19 '15 at 2:25
• @John that's a good point. I guess I need to think about this more. The values on y are speedup values for a benchmark and I'm trying to compare similarity between a variety of different configurations. So I guess the suggestion in this answer could work, I might try it just to see what the numbers look like. I'd still prefer to use a statistical technique that is more formally accepted (if there is one for my problem). – Gabriel Southern Mar 19 '15 at 3:39