Learn R Programming

HardyWeinberg (version 1.7.8)

shannon: Shannon index

Description

Function shannon calculates the Shannon index and its variance for a vector of counts.

Usage

shannon(x)

Value

Hp

the sample Shannon index

VHp

the sample variance of the Shannon index

Arguments

x

a vector of counts

Author

Jan Graffelman (jan.graffelman@upc.edu)

Examples

Run this code
#
# Shannon index for allele frequencies of a biallelic MN blood group polymorphism
#
x <- c(MM=298,MN=489,NN=213)
p <- af(x)
shannon(c(p,1-p))$Hp
#
# Shannon index for the allele frequencies of an STR
#
data("NistSTRs")
AlleleTable <- table(c(NistSTRs[,1],NistSTRs[,2]))
AlleleFreq  <- AlleleTable/sum(AlleleTable)
shannon(AlleleFreq)$Hp

Run the code above in your browser using DataLab