Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

distance

Calculate distance, dissimilarity


Description

Takes a phyloseq-class object and method option, and returns a distance object suitable for certain ordination methods and other distance-based analyses. Only sample-wise distances are currently supported (the type argument), but eventually species-wise (OTU-wise) distances may be supported as well.

Usage

distance(physeq, method, type = "samples", ...)

## S4 method for signature 'phyloseq,ANY'
distance(physeq, method)

## S4 method for signature 'otu_table,character'
distance(physeq, method,
  type = "samples", ...)

## S4 method for signature 'phyloseq,character'
distance(physeq, method, type = "samples",
  ...)

Arguments

physeq

(Required). A phyloseq-class or an otu_table-class object. The latter is only appropriate for methods that do not require any additional data (one-table). For example, the “wunifrac” option (UniFrac) requires phyloseq-class that contains both an otu_table and a phylogenetic tree (phylo).

method

(Required). A character string. Provide one of the currently supported options. See distanceMethodList for a detailed list of the supported options here, and links to accompanying documentation.

Note that for the common definition of Jaccard distance using the vegan-package implementation, an additional argument is needed, with the full call having the form: distance(physeq, method = "jaccard", binary = TRUE)

The following methods are implemented explicitly within the phyloseq-package, and accessed by the following method options:

"unifrac"

Original (unweighted) UniFrac distance, UniFrac

"wunifrac"

weighted-UniFrac distance, UniFrac

"dpcoa"

sample-wise distance used in Double Principle Coordinate Analysis, DPCoA

"jsd"

Jensen-Shannon Divergence, JSD

Alternatively, you can provide a character string that defines a custom distance method, if it has the form described in designdist.

type

(Optional). A character string. The type of pairwise comparisons being calculated: sample-wise or taxa-wise. The default is c("samples").

...

Additional arguments passed on to the appropriate distance function, determined by the method argument.

Details

Depending on the method argument, distance() wraps one of UniFrac, DPCoA, JSD, vegdist, betadiver, designdist, or dist.

Value

An object of class “dist” suitable for certain ordination methods and other distance-based analyses.

See Also

Examples

data(esophagus)
distance(esophagus, "uunifrac") # Unweighted UniFrac
distance(esophagus, "wunifrac") # weighted UniFrac
distance(esophagus, "jaccard", binary = TRUE) # vegdist jaccard
distance(esophagus, "gower") # vegdist option "gower"
distance(esophagus, "g") # designdist method option "g"
distance(esophagus, "minkowski") # invokes a method from the base dist() function.
distance(esophagus, "(A+B-2*J)/(A+B)") # designdist custom distance
distanceMethodList
help("distance")

phyloseq

Handling and analysis of high-throughput microbiome census data

v1.34.0
AGPL-3
Authors
Paul J. McMurdie <joey711@gmail.com>, Susan Holmes <susan@stat.stanford.edu>, with contributions from Gregory Jordan and Scott Chamberlain
Initial release
2019-04-23

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.