Description Usage Arguments Examples
Computes the information entropy (also called Shannon entropy) of a set of discrete values, or a tabulated such set.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
x |
a vector, table, data.frame or matrix. In the case of table, data.frame and matrix each row is treated as a separate set of counts or proportions, with columns representing species, types, categories etc. |
... |
further arguments passed to methods |
base |
the log base to be used. |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | entropy(c(5, 5, 4, 4, 2, 3, 5)) # default is unit bits
entropy(c(5, 5, 4, 4, 2, 3, 5), base=exp(1)) # unit nats
entropy(rep(1:4, 1:4), 4)
entropy(rep(1:4, 1), 4)
entropy(as.factor(c(1, 1, 2, 3, 4, 4)))
entropy(as.character(c(1, 1, 2, 3, 4, 4)))
mtctab <- table(mtcars$cyl, mtcars$carb)
entropy(mtctab, 6)
xx <- data.frame(bee=c(0, 0, 1, 2, 3, 2, 0, 3),
wasp=c(1, 3, 2, 0, 1, 1, 2, 1),
fly=c(1, 2, 4, 2, 1, 0, 1, 0),
beetle=c(1, 0, 0, 1, 2, 2, 0, 2),
butterfly=c(0, 0, 0, 0, 3, 1, 0, 1))
entropy(xx)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.