R/universal_diversity2.R

Defines functions universal_diversity2

Documented in universal_diversity2

#' Calculate Diversity Index
#'
#' A function which calculates a diversity measure, dependent on the population and the value for
#' q passed to it. This function can be used to calculate the Diversity value for species richness and
#' Simpson diversity. It can be called by other functions which pass a population and a value of q to
#' it.
#'
#' @param population - a set of population counts, containing the number of individuals of each species within the population
#' @param q - a diversity measure
#'
#' @return diversity - a diversity index which is dependent on the value of q which has been supplied
#' @export
#'
#' @examples
universal_diversity2 <- function(population, q) {
  species.proportions <- population / sum(population)
  non.zero.prop <- species.proportions[species.proportions > 0]
  qd.proportions <- non.zero.prop ^ q
  diversity <- sum(qd.proportions) ^ (1/(1-q))
  diversity
}
EdieBishop/ProgInRBCIfunc documentation built on Dec. 23, 2019, 10:16 p.m.