shannonEntr: Compute Shannon Entropy

View source: R/shannonEntr.R

shannonEntrR Documentation

Compute Shannon Entropy

Description

Compute Shannon Entropy of probability vector p.

Usage

shannonEntr(p, logbase = 2)

Arguments

p

A probability vector, sum(p) = 1.

logbase

A positive number: the base with respect to which logarithms

Details

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.

Author(s)

Robersy Sanchez (https://github.com/genomaths).

Examples

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))

genomaths/MethylIT.utils documentation built on July 4, 2023, 12:05 a.m.