Basic functions for marker informativeness
Humberto Reyes Valdés
Copy and paste the following script in an R console.
#Polymorfism information content
#x is a vector of allele frequencies
pic<-function(x){1-sum(x^2)-sum(x^2)^2+sum(x^4)}
#Maximum PIC for a alleles
mPIC<-function(a){(a-1)^2*(a+1)/a^3}
#Heterozygosity
#x is a vector of allele frequencies
het<-function(x){1-sum(x^2)}
#Unbiased estimation of heterozygosity
#x is a vector of allele frequencies and n is the number of sampled alleles
het.unbiased<-function(x,n){het(x)*n/(n-1)}
###############################
#Functions to calculate entropy
MyLog2p<-function(x){if(x==0) 0 else x*log(x,2)} #Defining x logx
entropy<-function(x){-sum(sapply(x,MyLog2p))} #x is a vector of probabilities