R/diversity_functions3.R

Defines functions species_richness3 simpson_diversity3 shannon_entropy3 berger_parker3

Documented in berger_parker3 shannon_entropy3 simpson_diversity3 species_richness3

#' Species Richness 3
#'
#' This package will calculate the species richness for a population. It accepts a population vector, then
#' calls on the universal_diversity3 function, and passes the population vector and a q value (q=0) to
#' it. universal_diversity3 will return a universal diversity, which species_richness3 will return as
#' a single numeric value of the species richness for the population argument.
#'
#' @param population a set of population counts, containing the number of individuals of each species within the population
#'
#' @return species.richness - the species richness for the population
#' @export
#'
#' @examples
species_richness3 <- function(population) {
  species.richness <- universal_diversity3(population = population,
                                           q = 0)
  return(species.richness)
}


#' Simpson Diversity 3
#'
#' This package will calculate the Simpson Diversity for a population. It accepts a population vector, then
#' calls on the universal_diversity3 function, and passes the population vector and a q value (q=2) to
#' it. universal_diversity3 will return a universal diversity value. simpson_diversity3 will then divide 1
#' by the returned diversity measure to obtain a value for Simpson Diversity, and return this value as a
#' single numeric value of Simpson DIversity for the population.
#'
#' @param population a set of population counts, containing the number of individuals of each species within the population
#'
#' @return simpson.diversity - the Simpson Diversity for the population
#' @export
#'
#' @examples
simpson_diversity3 <- function(population) {
  diversity <- universal_diversity3(population = population,
                                    q = 2)
  simpson.diversity <- (1/diversity)
  return(simpson.diversity)
}




#' Shannon Entropy 3
#'
#' This package will calculate the Shannon Entropy for a population. It accepts a population vector, then
#' calls on the universal_diversity3 function, and passes the population vector and a q value (q=1) to
#' it. universal_diversity3 will return a universal diversity value. shannon_entropy3 will then calculate the
#' log of the returned diversity measure to obtain a value for Shannon Entropy, and return this value as a
#' single numeric value of Shannon Entropy for the population.
#'
#' @param population a set of population counts, containing the number of individuals of each species within the population
#'
#' @return shannon.entropy - the Shannon Entropy for the population
#' @export
#'
#' @examples
shannon_entropy3 <- function(population) {
  diversity <- universal_diversity3(population = population,
                                    q = 1)
  shannon.entropy <- log(diversity)
  return(shannon.entropy)
}


#' Berger-Parker 3
#'
#' This package will calculate the Berger-Parker f Indexor a population. It accepts a population vector, then
#' calls on the universal_diversity3 function, and passes the population vector and a q value (q=Infinity) to
#' it. universal_diversity3 will return a universal diversity value. shannon_entropy3 will divide 1 by
#' the returned diversity measure to obtain a value for the Berger-Parker Index, and return this value as a
#' single numeric value of Berger-Parker Index for the population.
#'
#' @param population a set of population counts, containing the number of individuals of each species within the population
#'
#' @return berger.parker - the Berger-Parker Index for the population
#' @export
#'
#' @examples
berger_parker3 <- function(population) {
  diversity <- universal_diversity3(population = population,
                                    q = Inf)
  berger.parker <- 1/diversity
  return(berger.parker)
}
EdieBishop/ProgInRBCIfunc documentation built on Dec. 23, 2019, 10:16 p.m.