R/entropy.R

Defines functions entropy

Documented in entropy

entropy <- function(V) {
# calculates the Shannon entropy, following Tatsle & Wierman (2007)
  V <- V/sum(V)    # normalizing the vector
  a <- log2(V)     # log2 separately, so I can filter out the -Inf
  # this is how Tatsle & Wierman handle it!
  a[a==-Inf] <- 0  # if log(0), then 0
  e <- -1 * sum(V * a)
  return(e)
}

Try the agrmt package in your browser

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

agrmt documentation built on Nov. 23, 2023, 1:07 a.m.