euclidean {abdiv} | R Documentation |
Euclidean and related distances
Description
These distance and diversity measures are mathematically similar to the Euclidean distance between two vectors.
Usage
euclidean(x, y)
rms_distance(x, y)
chord(x, y)
hellinger(x, y)
geodesic_metric(x, y)
Arguments
x , y |
Numeric vectors |
Details
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:
Equivalent to R's built-in
dist()
function withmethod = "euclidean"
.Equivalent to
vegdist()
withmethod = "euclidean"
.Equivalent to the
euclidean()
function inscipy.spatial.distance
.Equivalent to the
structeuclidean
calculator in Mothur, tospeciesprofile
ifx
andy
are transformed to relative abundance, and tomemeuclidean
ifx
andy
are transformed to presence/absence.Equivalent to
D_1
in Legendre & Legendre.Equivalent to the distance between species profiles,
D_{18}
in Legendre & Legendre ifx
andy
are transformed to relative abundance.
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:
Equivalent to
D_2
in Legendre & Legendre.
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:
Equivalent to
D_3
in Legendre & Legendre.
The Hellinger distance is equal to the chord distance computed after
a square-root transformation. Relation of hellinger()
to other
definitions:
Equivalent to
D_{17}
in Legendre & Legendre.Equivalent to the
hellinger
calculator in Mothur.
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:
Equivalent to
D_4
in Legendre & Legendre.
Value
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.
Examples
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)
sqrt(2)