[R] function to compute entropy

Kosenkov Kirill Kosenkov.Kirill at nac.spb.ru
Thu May 8 18:01:25 CEST 2003


Maybe its slightly off-topic, but can anybody
help with computing entropy on matrix of probabilities?

Guess we have a matrix of probabilites, A, 2x2, something
like this:
    z
x   0     1     2     3     4
   0 0.063 0.018 0.019 0.016 0.000
   1 0.011 0.162 0.040 0.042 0.003
   2 0.015 0.030 0.164 0.033 0.002
   3 0.012 0.035 0.036 0.159 0.002
   4 0.004 0.021 0.018 0.013 0.082

sum(A)=1

Can i compute entropy like this:
entropy<-sum(A*log2(A)) ?

is there a function for computing entropy in R?

Thanx.




More information about the R-help mailing list