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.