diversity {sprex} | R Documentation |
Diversity Indices
Description
Calculate common diversity and entropy indices.
Usage
diversity(
x,
type = c("effective.number", "richness", "shannon", "simpson", "gini.simpson",
"unb.gini", "eveness.simpson", "eveness.pielou", "inv.simpson", "renyi", "hill"),
q = NULL
)
Arguments
x |
vector or matrix of values (character, factor) representing a class, from which proportions will be computed. If numeric, values will be converted to proportions. If a matrix, indices will be computed for all columns. |
type |
type of index to compute. See Details for descriptions.
If |
q |
order of Hill number (must be >= 0). |
Value
if a vector is supplied for x
, a single value for the chosen
type of index. If a matrix, a vector values for each column.
Note
Available indices for type
are:
- richness
the number of observed classes (non-
NA
and frequency > 0)- effective.number
exponent of Hill number of order 1
- shannon
Shannon entropy
- simpson
Simpson concentration
- gini.simpson
Gini-Simpson index (= 1 - Simpson concentration)
- inv.simpson
Inverse Simpson concentration
- unb.gini
unbiased Gini-Simpson index with correction for small sample sizes
- eveness.simpson
Simpson eveness
- eveness.pielou
Pielou eveness
- renyi
Renyi entropy
- hill
Hill number
Author(s)
Eric Archer eric.archer@noaa.gov
Examples
x <- sample(letters[1:4], 100, replace = TRUE, p = c(1, 2, 3, 4))
types <- c("richness", "effective.number", "shannon",
"simpson", "inv.simpson", "gini.simpson", "unb.gini",
"eveness.simpson", "eveness.pielou"
)
sapply(types, function(tp) diversity(x, type = tp))
# hill numbers with increasing order
order <- 0:5
hill.num <- sapply(order, function(q) diversity(x, type = "hill", q = q))
hill.num
plot(order, hill.num, type = "b")
# a matrix of frequencies
spp.freq <- cbind(
sample(letters[1:4], 100, replace = TRUE, p = c(1, 1, 1, 4)),
sample(letters[1:4], 100, replace = TRUE, p = c(4, 1, 1, 1)),
sample(letters[1:4], 100, replace = TRUE, p = c(1, 1, 1, 1))
)
diversity(spp.freq, type = "eff")