Inverse Simpson alpha diversity metric.
Usage
inv_simpson(counts, 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 asphyloseq
,rbiom
,SummarizedExperiment
, andTreeSummarizedExperiment
objects.- cpus
How many parallel processing threads should be used. The default,
n_cpus()
, will use all logical CPU cores.
Calculation
Pre-transformation: drop all OTUs with zero abundance.
In the formulas below, \(x\) is a single column (sample) from counts
.
\(p\) are the relative abundances.
$$p_{i} = \displaystyle \frac{x_i}{\sum x}$$ $$D = \displaystyle 1 / \sum_{i = 1}^{n} p_{i}\times\ln(p_{i})$$
References
Simpson EH 1949. Measurement of diversity. Nature, 163. doi:10.1038/163688a0
Examples
# Example counts matrix
ex_counts
#> Saliva Gums Nose Stool
#> Streptococcus 162 793 22 1
#> Bacteroides 2 4 2 611
#> Corynebacterium 0 0 498 1
#> Haemophilus 180 87 2 1
#> Propionibacterium 1 1 251 0
#> Staphylococcus 0 1 236 1
# Inverse Simpson diversity values
inv_simpson(ex_counts)
#> Saliva Gums Nose Stool
#> 2.029446 1.233425 2.783607 1.013125
# Low diversity
inv_simpson(c(100, 1, 1, 1, 1)) # 1.08
#> [1] 1.081168
# High diversity
inv_simpson(c(20, 20, 20, 20, 20)) # 5
#> [1] 5
# Low richness
inv_simpson(1:3) # 2.57
#> [1] 2.571429
# High richness
inv_simpson(1:100) # 75.37
#> [1] 75.37313