Learn R Programming

OmicFlow (version 1.5.0)

jsd: Compute Jensen-Shannon Divergence from a Dense or Sparse Matrix.

Description

Calculates the Jensen-Shannon divergence of a Matrix pairwise for each column.

Usage

jsd(x, weighted = TRUE, threads = 1)

Value

A column x column dist object.

Arguments

x

A matrix, sparseMatrix or Matrix.

weighted

A boolean value, to use abundances (weighted = TRUE) or absence/presence (weighted=FALSE) (default: TRUE).

threads

A wholenumber, the number of threads to use in setThreadOptions (default: 1).

Details

The Jensen-Shannon divergence between two probability distributions \(A\) and \(B\), each of length \(n\), is defined as:

\( d(A, B) = \frac{1}{2} D_{KL}(A \parallel M) + \frac{1}{2} D_{KL}(B \parallel M) \)

where \(M = \frac{1}{2} (A + B)\) is the mixture distribution, and \(D_{KL}\) is the Kullback-Leibler divergence. When weighted is set to FALSE, counts are replaced by presence/absence data.

References

Lin, J. (1991). Divergence measures based on the Shannon entropy. IEEE Transactions on Information Theory, 37(1), 145-151.

Examples

Run this code
library("OmicFlow")

metadata_file <- system.file("extdata", "metadata.tsv", package = "OmicFlow")
counts_file <- system.file("extdata", "counts.tsv", package = "OmicFlow")
features_file <- system.file("extdata", "features.tsv", package = "OmicFlow")
tree_file <- system.file("extdata", "tree.newick", package = "OmicFlow")

taxa <- metagenomics$new(
    metaData = metadata_file,
    countData = counts_file,
    featureData = features_file,
    treeData = tree_file
)

taxa$feature_subset(Kingdom == "Bacteria")
taxa$normalize()

jsd(taxa$countData)

Run the code above in your browser using DataLab