euclidean: Euclidean

euclideanR Documentation

Euclidean

Description

Euclidean beta diversity metric.

Usage

euclidean(counts, weighted = TRUE, pairs = NULL, cpus = n_cpus())

Arguments

counts

An OTU abundance matrix where each column is a sample, and each row is an OTU. Any object coercible with as.matrix() can be given here, as well as phyloseq, rbiom, SummarizedExperiment, and TreeSummarizedExperiment objects.

weighted

If TRUE, the algorithm takes relative abundances into account. If FALSE, only presence/absence is considered.

pairs

Which combinations of samples should distances be calculated for? The default value (NULL) calculates all-vs-all. Provide a numeric or logical vector specifying positions in the distance matrix to calculate. See examples.

cpus

How many parallel processing threads should be used. The default, n_cpus(), will use all logical CPU cores.

Value

A dist object.

Calculation

In the formulas below, x and y are two columns (samples) from counts. n is the number of rows (OTUs) in counts.

D = \displaystyle \sqrt{\sum_{i = 1}^{n} (x_i - y_i)^{2}}

  x <- c(4, 0, 3, 2, 6)  
  y <- c(0, 8, 0, 0, 5)  
  sqrt(sum((x-y)^2))
  #>  9.69536

References

Gower JC, Legendre P 1986. Metric and Euclidean Properties of Dissimilarity Coefficients. Journal of Classification. 3. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1007/BF01896809")}

Legendre P, Caceres M 2013. Beta diversity as the variance of community data: dissimilarity coefficients and partitioning. Ecology Letters. 16(8). \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1111/ele.12141")}

See Also

Other beta_diversity: bray_curtis(), canberra(), generalized_unifrac(), gower(), jaccard(), kulczynski(), manhattan(), unweighted_unifrac(), variance_adjusted_unifrac(), weighted_normalized_unifrac(), weighted_unifrac()

Examples

    # Example counts matrix
    ex_counts
    
    # Euclidean weighted distance matrix
    euclidean(ex_counts)
    
    # Euclidean unweighted distance matrix
    euclidean(ex_counts, weighted = FALSE)
    
    # Only calculate distances for A vs all.
    euclidean(ex_counts, pairs = 1:3)
    

ecodive documentation built on Aug. 23, 2025, 1:13 a.m.