Learn R Programming

ume (version 1.5.2)

calc_shannon_index: Calculate the Shannon Diversity Index

Description

The Shannon diversity index is calculated to quantify the diversity of molecular formulas based on their relative abundances. This index considers both the richness (number of unique formulas) and the evenness (distribution of abundances). Higher values indicate greater diversity.

The Shannon index is defined as: $$H = -\sum (p_i \cdot \ln(p_i))$$ where:

  • \(p_i\) is the relative abundance of the \(i\)-th molecular formula.

Zero-abundance formulas are excluded from the calculation.

Usage

calc_shannon_index(mf, magnitude)

Value

A single numeric value representing the Shannon diversity index. Returns 0 if magnitude is all zeros.

Arguments

mf

Character vector. A list of unique molecular formulas.

magnitude

Numeric vector. A list of respective abundances (intensities) for each molecular formula. Must be non-negative and have the same length as mf.

Examples

Run this code
calc_shannon_index(
  mf = c("C10H20O5", "C12H18O3", "C18H30O6"),
  magnitude = c(1982375, 2424, 312410)
)

Run the code above in your browser using DataLab