euclidean: Euclidean and related distances

Description Usage Arguments Details Value Examples

Description

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

Usage

1
2
3
4
5
6
7
8
9
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) = √{∑_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) = √{\frac{1}{n} ∑_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, √{∑_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} ≤ft(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:

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
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)

abdiv documentation built on Jan. 20, 2020, 5:07 p.m.