This function calculates the species evenness, which is a measure of how evenly individuals are distributed among the different species in a community. It is based on the Shannon-Weiner diversity index.

evenness(x)

Arguments

x

A character vector of species names. Each element represents an individual of a species.

Value

A numeric value representing the evenness index. Returns NA if the input vector is empty or contains fewer than two unique species.

Note

Evenness is undefined for empty vectors or vectors with fewer than two unique species. The function will return NA in such cases with a warning.

See also

shannon_weiner for the Shannon-Weiner diversity index.

Examples

# Example 1: Calculate evenness for a dataset
x <- c("jonesi","gambiensis","hispida","hispida","thebaica","helvum","helvum","gambianus","gambianus","pusillus","monstrosus","aegyptiacus")
evenness(x)
#> [1] 0.9731973

# Example 2: Handle edge cases
evenness(c("thebaica")) # Returns NA with a warning
#> Warning: Evenness is undefined for fewer than 2 species. Returning NA.
#> [1] NA
evenness(character(0)) # Returns NA with a warning
#> Warning: Input vector is empty. Returning NA.
#> [1] NA