Why does Matlab use 1-d for the correlation distance

Viewed 97

I want to use the correlation distance in knnsearch in Matlab. I'm wondering why for the correlation, "'correlation' — One minus the sample linear correlation between observations (treated as sequences of values)." is used. With knnsearch I want to find the k nearest neighbors. But isn't a perfect correlation (which would mean the closest match) be the correlation and not 1-correlation?

1 Answers

Using correlation as a "distance" would not make much sense. Given two vectors x1 and x2, if x1equals x2 you would expect the distance to be 0. However, the correlation (coefficient) of a vector with itself is 1. If you compute 1 - correlation you do get 0 for equal vectors.

In general, the "closer" the vectors are (smaller distance) the more correlated they are (higher correlation). So 1 - correlation makes sense as a measure of similarity.

Note, however, that although 1 - correlation is a measure of similarity it is not really a distance, because it does not satisfy the triangle inequality. As a counterexample, consider the following vectors:

x1 = [1 9 8 5];
x2 = [0 7 6 9];
x3 = [9 3 2 6];

Then

>> pdist([x1; x2], 'correlation') + pdist([x2; x3], 'correlation')
ans =
   1.919533190739275
>> pdist([x1; x3], 'correlation')
ans =
   1.967870959140932
Related