gower | R Documentation |
Gower beta diversity metric.
gower(counts, weighted = TRUE, pairs = NULL, cpus = n_cpus())
counts |
An OTU abundance matrix where each column is a sample, and
each row is an OTU. Any object coercible with |
weighted |
If |
pairs |
Which combinations of samples should distances be
calculated for? The default value ( |
cpus |
How many parallel processing threads should be used. The
default, |
A dist
object.
Each row (OTU) of counts
is rescaled to the range 0-1. In cases where a
row is all the same value, those values are replaced with 0
.
counts scaled recounts A B C D A B C D OTU1 0 0 0 0 -> OTU1 0.0 0.0 0.0 0 OTU2 0 8 9 10 -> OTU2 0.0 0.8 0.9 1 OTU3 5 5 5 5 -> OTU3 0.0 0.0 0.0 0 OTU4 2 0 0 0 -> OTU4 1.0 0.0 0.0 0 OTU5 4 6 4 1 -> OTU5 0.6 1.0 0.6 0
In the formulas below, x
and y
are two columns (samples) from the scaled
counts. n
is the number of rows (OTUs) in counts
.
D = \displaystyle \frac{1}{n}\sum_{i = 1}^{n} |x_i - y_i|
x <- c(0, 0, 0, 1, 0.6) y <- c(0, 0.8, 0, 0, 1) sum(abs(x-y)) / length(x) #> 0.44
Gower JC 1971. A general coefficient of similarity and some of its properties. Biometrics. 27(4). \Sexpr[results=rd]{tools:::Rd_expr_doi("10.2307/2528823")}
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")}
Other beta_diversity:
bray_curtis()
,
canberra()
,
euclidean()
,
generalized_unifrac()
,
jaccard()
,
kulczynski()
,
manhattan()
,
unweighted_unifrac()
,
variance_adjusted_unifrac()
,
weighted_normalized_unifrac()
,
weighted_unifrac()
# Example counts matrix
ex_counts
# Gower weighted distance matrix
gower(ex_counts)
# Gower unweighted distance matrix
gower(ex_counts, weighted = FALSE)
# Only calculate distances for A vs all.
gower(ex_counts, pairs = 1:3)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.