# NOT RUN {
# load entropy library
library("entropy")
# joint distribution of two discrete variables
freqs2d = rbind( c(0.2, 0.1, 0.15), c(0.1, 0.2, 0.25) )
# corresponding mutual information
mi.plugin(freqs2d)
# MI computed via entropy
H1 = entropy.plugin(rowSums(freqs2d))
H2 = entropy.plugin(colSums(freqs2d))
H12 = entropy.plugin(freqs2d)
H1+H2-H12
# and corresponding (half) chi-squared divergence of independence
0.5*chi2indep.plugin(freqs2d)
# }
Run the code above in your browser using DataLab