
Compute Euclidean Dissimilarity from a from a Dense or Sparse Matrix.
Source:R/euclidean.R
euclidean.RdCalculates the Euclidean dissimilarity of a Matrix pairwise for each column.
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).
Value
A column x column dist object.
Details
The Euclidean dissimilarity between two samples \(A\) and \(B\), each of length \(n\), is defined as:
\(d(A,B) = \sqrt{\sum_{i=1}^n (A_i - B_i)^2}\)
where \(A_i\) and \(B_i\) are the abundances of the \(i\)-th feature in sample \(A\) and \(B\), respectively. When weighted is set to FALSE, counts are replaced by presence/absence data.
Examples
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
)
#> ✔ metaData template passed the JSON validation.
#> ℹ Checking for duplicated identifiers ..
#> ✔ featureData is loaded.
#> ✔ countData is loaded.
#> ✔ treeData is loaded.
#> ℹ Final steps .. cleaning & creating back-up
#>
#> ── <metagenomics> object
#> metaData: 9 variables × 4 samples
#> countData: 4 samples × 242 features
#> featureData: 7 attributes × 242 features
#> treeData: 242 tips × 241 nodes
taxa$feature_subset(Kingdom == "Bacteria")
#>
#> ── <metagenomics> object
#> metaData: 9 variables × 4 samples
#> countData: 4 samples × 185 features
#> featureData: 7 attributes × 185 features
#> treeData: 185 tips × 184 nodes
taxa$scale(method = "tss")
euclidean(taxa$countData)
#> S100 S103 S115
#> S103 0.3117207
#> S115 0.2703239 0.3142404
#> S120 0.3056553 0.2969925 0.3082246