Species diversity in a dataset can be calculated by first taking the
weighted average of species proportional abundances in the dataset, and then taking the
inverse of this. The equation is: :\lim_{q \rightarrow 1} {}^q\!D = \exp\left(-\sum_{i=1}^S p_i \ln p_i\right), which is the exponential of the
Shannon entropy.
q = 2 corresponds to the
arithmetic mean. As
q approaches
infinity, the generalized mean approaches the maximum p_{i} value. In practice,
q modifies species weighting, such that increasing
q increases the weight given to the most abundant species, and fewer equally abundant species are hence needed to reach mean proportional abundance. Consequently, large values of
q lead to smaller species diversity than small values of
q for the same dataset. If all species are equally abundant in the dataset, changing the value of
q has no effect, but species diversity at any value of
q equals species richness. Negative values of
q are not used, because then the effective number of species (diversity) would exceed the actual number of species (richness). As
q approaches negative infinity, the generalized mean approaches the minimum p_{i} value. In many real datasets, the least abundant species is represented by a single individual, and then the effective number of species would equal the number of individuals in the dataset. The same equation can be used to calculate the diversity in relation to any classification, not only species. If the individuals are classified into genera or functional types, p_{i} represents the proportional abundance of the
ith genus or functional type, and
qD equals genus diversity or functional type diversity, respectively. ==Diversity indices==