Learn R Programming

TFBSTools (version 1.10.3)

shannon.entropy: Calculate the Shannon entropy

Description

This function calculates the Shannon entropy for a discrete random variable with finite n values sample.

Usage

shannon.entropy(p)

Arguments

p
A numeric object with non-negative values.

Value

A numeric value of entropy is returned.

Details

The entropy is calculated by H(x) = -sum_i^n(P(x_i)log_b(P(x_i))).

Examples

Run this code
  x <- c(1, 1, 1, 1)
  shannon.entropy(x)
  x <- c(1, 0, 0, 0)
  shannon.entropy(x)

Run the code above in your browser using DataLab