Computes the Jensen-Shannon divergence between two probability distributions.

jsd(p, q, base = c("log", "log2", "log10"), margin = FALSE)

## Arguments

p numeric. probability distributions. numeric. probability distributions. character. log bases. "log", "log2", "log10". default is "log" logical. Choose whether to return individual values or totals. The default value is FALSE, which returns individual values.

## Value

numeric. Jensen-Shannon divergence of probability distributions p and q.

kld.

## Examples

# Sample data for probability distributions p.
event <- c(115, 76, 61, 39, 55, 10, 1)
no_event <- c(3, 3, 7, 10, 28, 44, 117)

p <- event / sum(event)
q <- no_event / sum(no_event)

jsd(p, q)#> [1] 0.0872049861 0.0521977242 0.0255127366 0.0063314207 0.0004227586 0.0386776759
#> [7] 0.1834364603jsd(p, q, base = "log2")#> [1] 0.1258102010 0.0753053979 0.0368070986 0.0091343092 0.0006099118 0.0558000912
#> [7] 0.2646428716jsd(p, q, margin = TRUE)#> [1] 0.3937838