entropy | R Documentation |
Returns the entropy of the distribution defined by
group
.
entropy(data, group, weight = NULL, base = exp(1))
data |
A data frame. |
group |
A categorical variable or a vector of variables
contained in |
weight |
Numeric. (Default |
base |
Base of the logarithm that is used in the entropy calculation. Defaults to the natural logarithm. |
A single number, the entropy.
d <- data.frame(cat = c("A", "B"), n = c(25, 75))
entropy(d, "cat", weight = "n") # => .56
# this is equivalent to -.25*log(.25)-.75*log(.75)
d <- data.frame(cat = c("A", "B"), n = c(50, 50))
# use base 2 for the logarithm, then entropy is maximized at 1
entropy(d, "cat", weight = "n", base = 2) # => 1
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.