R/shannon.R

Defines functions shannon

Documented in shannon

#' @title Shannon diversity index
#'
#' @description Computes Shannon's diversity index
#'
#' @param x Vector of dimension S (number of species) with the number of individuals observed in each species, or the distribution frequencies of species. NA values are allowed.
#'
#' @return Shannon's diversity index (Entropy).
#'
#' @seealso \link{dec_shannon}, \link{equitability}
#'
#' @references
#' Arnaud Barat, Andreu Sansó, Maite Arilla-Osuna, Ruth Blasco, Iñaki Pérez-Fernández, Gabriel Cifuentes-Alcobenda, Rubén Llorente, Daniel Vivar-Ríos, Ella Assaf, Ran Barkai, Avi Gopher, & Jordi Rosell-Ardèvol (2026) <doi:10.1007/s10816-026-09802-3>.
#'
#' @examples
#' data(Qesem_s)
#' shannon(Qesem_s$HU)
#'
#' @export
shannon <- function(x){
  x <- check_x(x)
  p <- x/sum(x)
  return(sum(-p*log(p)))
}

Try the diversityArch package in your browser

Any scripts or data that you put into this service are public.

diversityArch documentation built on June 13, 2026, 5:07 p.m.