diversity | R Documentation |
Calculate common diversity and entropy indices.
diversity(
x,
type = c("effective.number", "richness", "shannon", "simpson", "gini.simpson",
"unb.gini", "eveness.simpson", "eveness.pielou", "inv.simpson", "renyi", "hill"),
q = NULL
)
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). |
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.
Available indices for type
are:
the number of observed classes (non-NA
and frequency > 0)
exponent of Hill number of order 1
Shannon entropy
Simpson concentration
Gini-Simpson index (= 1 - Simpson concentration)
Inverse Simpson concentration
unbiased Gini-Simpson index with correction for small sample sizes
Simpson eveness
Pielou eveness
Renyi entropy
Hill number
Eric Archer eric.archer@noaa.gov
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")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.