shannonEntr | R Documentation |
Compute Shannon Entropy of probability vector p.
shannonEntr(p, logbase = 2)
p |
A probability vector, sum(p) = 1. |
logbase |
A positive number: the base with respect to which logarithms |
By definition, if p_i = 0 for some i, then the entropy is 0. In
addition, since Shannon entropy is only defined for 0 <= p <= 1
,
the function will return 0 for any values of p out of the definition
range of values.
Robersy Sanchez (https://github.com/genomaths).
counts = sample.int(10)
prob = counts/sum(counts)
shannonEntr(prob)
## Out of the definition range of values for p, 'shannonEntr' will return 0
shannonEntr(c(0.5, 1.2, -0.3))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.