# euclidean: Euclidean and related distances In kylebittinger/abdiv: Alpha and Beta Diversity Measures

## 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:

• Equivalent to R's built-in dist() function with method = "euclidean".

• Equivalent to vegdist() with method = "euclidean".

• Equivalent to the euclidean() function in scipy.spatial.distance.

• Equivalent to the structeuclidean calculator in Mothur, to speciesprofile if x and y are transformed to relative abundance, and to memeuclidean if x and y are transformed to presence/absence.

• Equivalent to D_1 in Legendre & Legendre.

• Equivalent to the distance between species profiles, D_18 in Legendre & Legendre if x and y 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) = √{\frac{1}{n} ∑_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, √{∑_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} ≤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:

• 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

  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) 

kylebittinger/abdiv documentation built on Jan. 31, 2020, 3:13 p.m.