jsd | R Documentation |
Calculates a distance matrix from a matrix of probability distributions using Jensen-Shannon divergence. Adapted from https://enterotype.embl.de/enterotypes.html#dm.
jsd(M, pseudocount = 1e-06, normalizeCounts = FALSE)
M |
a probability distribution matrix, e.g., normalized transcript compatibility counts. |
pseudocount |
a small number to avoid division by zero errors. |
normalizeCounts |
logical, whether to attempt to normalize by dividing by the column sums. Set to |
A Jensen-Shannon divergence-based distance matrix.
set.seed(42)
M <- matrix(rpois(100, lambda=100), ncol=5)
colnames(M) <- paste0("sample", 1:5)
rownames(M) <- paste0("gene", 1:20)
Mnorm <- apply(M, 2, function(x) x/sum(x))
Mjsd <- jsd(Mnorm)
# equivalently
Mjsd <- jsd(M, normalizeCounts=TRUE)
Mjsd
plot(hclust(Mjsd))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.