5

Say I have values

10, 3, 6

What would be a way of finding a subjective difference between them. Or in other words, how close they are to each-other.

So if i had

3, 2.5, 2.8; they would be close together in relation to one another.

3, 10, 10.5; would not be close together, despite two values being similar.

Jamie W
  • 57

2 Answers2

10

Compute the standard deviation of the set.

In other words, let $m = \frac{1}{n} \sum_{i=1}^n x_i$ be the average of the set, then compute $$ \sigma = \sqrt{\frac{1}{n} \sum_{i=1}^n \left(x_i-m\right)^2} = \sqrt{\frac{1}{n} \sum_{i=1}^n x_i^2 - m^2} $$

It's nice that this will work for $n=1,2$ or even very large $n$.

UPDATE (thanks to BlueRaja - Danny Pflughoeft)

This is will handle a absolute difference reasonably. However, if you want a relative difference (e.g. $90,100,110$ should behave similar to $9,10,11$) - compute the relative standard deviation, dividing by the mean or the median of the set, i.e. $\sigma/m$.

gt6989b
  • 54,422
  • This was my first thought, but are "near" $0.001$, $0.1$ and $0.101$? Based on the example that OP has written, I'd say not. But let him/her decide... – ajotatxe May 20 '15 at 15:02
  • For OP's examples, $\sigma$ would be small in the first one and large in the second one. Whether he wants to account for relative (like in your answer) or absolute (like in my answer) scales, is not clear from the question... – gt6989b May 20 '15 at 15:05
  • This works to my needs thankyou. My values are between 0.0013 and 60, all over the place. (I'm mapping out a theoretical clock, working out the very pico-second the hands overlap perfectly if we take the hands as 2D objects) – Jamie W May 20 '15 at 15:07
  • 1
    To account for the relative differences, divide by the mean (or median). This is called relative standard deviation – BlueRaja - Danny Pflughoeft May 20 '15 at 16:45
  • @BlueRaja-DannyPflughoeft thank you, added an update to the answer reflecting your points – gt6989b May 20 '15 at 17:03
  • Shouldn't the left-hand side of the equation be $\sigma$, not $\sigma^2$ (since you already have a square root on the right-hand side)? – Frxstrem May 20 '15 at 21:52
  • @Frxstrem of course, another typo from multiple revisions, fixed now, thanks – gt6989b May 20 '15 at 21:58
2

I'm not completly sure if that is what you want, but, how about this?

Three positive numbers $x<y<z$ are "near" if $$\frac{z-x}{y}$$ is "small".

ajotatxe
  • 65,084
  • +1. I like accounting for relative distances, which my answer does not do. Unfortunately, won't generalize too well. Perhaps you need to divide this by the average instead of the median... Another question to think about is 0, 10, 10.001 are not close (OP's second example) but your metric would be fairly small... – gt6989b May 20 '15 at 15:06