canberra: Canberra and related distances

canberraR Documentation

Canberra and related distances

Description

The Canberra distance and Clark's coefficient of divergence are measures that use the absolute difference over the sum for each element of the vectors.

Usage

canberra(x, y)

clark_coefficient_of_divergence(x, y)

Arguments

x, y

Numeric vectors

Details

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

d(x, y) = \sum_i \frac{|x_i - y_i|}{x_i + y_i}.

Elements where x_i + y_i = 0 are not included in the sum. Relation of canberra() to other definitions:

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

  • Equivalent to the vegdist() function with method = "canberra", multiplied by the number of entries where x > 0, y > 0, or both.

  • Equivalent to the canberra() function in scipy.spatial.distance for positive vectors. They take the absolute value of x_i and y_i in the denominator.

  • Equivalent to the canberra calculator in Mothur, multiplied by the total number of species in x and y.

  • Equivalent to D_{10} in Legendre & Legendre.

Clark's coefficient of divergence involves summing squares and taking a square root afterwards:

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

where n is the number of elements where x > 0, y > 0, or both. Relation of clark_coefficient_of_divergence() to other definitions:

  • Equivalent to D_{11} in Legendre & Legendre.

Value

The Canberra distance or Clark's coefficient of divergence. If every element in x and y is zero, Clark's coefficient of divergence is undefined, and we return NaN.

Examples

x <- c(15, 6, 4, 0, 3, 0)
y <- c(10, 2, 0, 1, 1, 0)
canberra(x, y)
clark_coefficient_of_divergence(x, y)

kylebittinger/abdiv documentation built on Nov. 22, 2023, 8:16 p.m.