# NOT RUN {
# load entropy library
library("entropy")
# probabilities for two random variables
freqs1 = c(1/5, 1/5, 3/5)
freqs2 = c(1/10, 4/10, 1/2)
# KL divergence from X1 to X2
KL.plugin(freqs1, freqs2)
# and corresponding (half) chi-squared statistic
0.5*chi2.plugin(freqs1, freqs2)
# }
Run the code above in your browser using DataLab