Description Usage Arguments Details Value Examples
The correlation and cosine distances, which are derived from the dot product of the two vectors.
1 2 3 | correlation_distance(x, y)
cosine_distance(x, y)
|
x, y |
Numeric vectors |
For vectors x and y, the cosine distance is defined as the
cosine of the angle between the vectors,
d(x, y) = 1 - \frac{x \cdot y}{|x| |y|},
where |x| is the magnitude or L2 norm of the vector, |x| = √{∑_i x_i^2}. Relation to other definitions:
Equivalent to the cosine() function in
scipy.spatial.distance.
The correlation distance is simply equal to one minus the Pearson correlation between vectors. Mathematically, it is equivalent to the cosine distance between the vectors after they are centered (x - \bar{x}). Relation to other definitions:
Equivalent to the correlation() function in
scipy.spatial.distance.
Equivalent to the 1 - mempearson calculator in Mothur.
The correlation or cosine distance. These are undefined if either
x or y contain all zero elements, that is, if |x| = 0
or |y| = 0. In this case, we return NaN.
1 2 3 4 5 6 7 8 9 10 | x <- c(2, 0)
y <- c(5, 5)
cosine_distance(x, y)
# The two vectors form a 45 degree angle, or pi / 4
1 - cos(pi / 4)
v <- c(3.5, 0.1, 1.4)
w <- c(3.3, 0.5, 0.9)
correlation_distance(v, w)
1 - cor(v, w)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.