inv_simpson: Inverse Simpson

inv_simpsonR Documentation

Inverse Simpson

Description

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 as phyloseq, rbiom, SummarizedExperiment, and TreeSummarizedExperiment objects.

cpus

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

Value

A numeric vector.

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})

  x <- c(4, 0, 3, 2, 6)[-2]  
  p <- x / sum(x)
  1 / sum(p * log(p))
  #>  -0.7636352

References

Simpson EH 1949. Measurement of diversity. Nature, 163. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1038/163688a0")}

See Also

Other alpha_diversity: chao1(), faith(), shannon(), simpson()

Examples

    # Example counts matrix
    ex_counts
    
    # Inverse Simpson diversity values
    inv_simpson(ex_counts)
    
    # Low diversity
    inv_simpson(c(100, 1, 1, 1, 1)) # 1.08
    
    # High diversity
    inv_simpson(c(20, 20, 20, 20, 20)) # 5
    
    # Low richness
    inv_simpson(1:3) # 2.57
    
    # High richness
    inv_simpson(1:100) # 75.37
    

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