euclidean {abdiv}R Documentation

Euclidean and related distances


These distance and diversity measures are mathematically similar to the Euclidean distance between two vectors.


euclidean(x, y)

rms_distance(x, y)

chord(x, y)

hellinger(x, y)

geodesic_metric(x, y)


x, y

Numeric vectors


For vectors x and y, the Euclidean distance is defined as

d(x, y) = \sqrt{\sum_i (x_i - y_i) ^ 2}.

Relation of euclidean() to other definitions:

The root-mean-square distance or average distance is similar to Euclidean distance. As the name implies, it is computed as the square root of the mean of the squared differences between elements of x and y:

d(x, y) = \sqrt{\frac{1}{n} \sum_i^n (x_i - y_i) ^ 2}.

Relation of rms_distance() to other definitions:

The chord distance is the Euclidean distance after scaling each vector by its root sum of squares, \sqrt{\sum_i x_i^2}. The chord distance between any two vectors ranges from 0 to \sqrt{2}. Relation of chord() to other definitions:

The Hellinger distance is equal to the chord distance computed after a square-root transformation. Relation of hellinger() to other definitions:

The geodesic metric is a transformed version of the chord distance.

d(x, y) = \textrm{arccos} \left(1 - \frac{d_c^2(x, y)}{2} \right),

where d_c is the chord distance. It gives the length of the arc on a hypersphere between the vectors, if the vectors are normalized to unit length. Relation of geodesic_metric() to other definitions:


The distance between x and y. The chord distance, Hellinger distance, and geodesic metric are not defined if all elements of either vector are zero. We return NaN in this case.


x <- c(15, 6, 4, 0, 3, 0)
y <- c(10, 2, 0, 1, 1, 0)
euclidean(x, y)
# The "distance between species profiles"
euclidean(x / sum(x), y / sum(y))
rms_distance(x, y)
chord(x, y)
hellinger(x, y)
# Hellinger is chord distance after square root transform
chord(sqrt(x), sqrt(y))
geodesic_metric(x, y)

# No species in common with x
v <- c(0, 0, 0, 5, 0, 5)
chord(v, x)

[Package abdiv version 0.2.0 Index]