calculate_distance: Calculate (column-wise) distances/similarity between two...

Description Usage Arguments Examples

View source: R/calculate_distance.R

Description

These matrices can be dense or sparse.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
calculate_distance(
  x,
  y = NULL,
  method = c("pearson", "spearman", "cosine", "euclidean", "chisquared", "hamming",
    "kullback", "manhattan", "maximum", "canberra", "minkowski"),
  margin = 1
)

list_distance_methods()

calculate_similarity(
  x,
  y = NULL,
  margin = 1,
  method = c("spearman", "pearson", "cosine")
)

list_similarity_methods()

Arguments

x

A numeric matrix, dense or sparse.

y

(Optional) a numeric matrix, dense or sparse, with nrow(x) == nrow(y).

method

Which distance method to use. Options are: "cosine", "pearson", "spearman", "euclidean", and "manhattan".

margin

Which margin to use for the pairwise comparison. 1 => rowwise, 2 => columnwise.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
## Generate two matrices with 50 and 100 samples
library(Matrix)
x <- Matrix::rsparsematrix(50, 1000, .01)
y <- Matrix::rsparsematrix(100, 1000, .01)

dist_euclidean <- calculate_distance(x, y, method = "euclidean")
dist_manhattan <- calculate_distance(x, y, method = "manhattan")
dist_spearman <- calculate_distance(x, y, method = "spearman")
dist_pearson <- calculate_distance(x, y, method = "pearson")
dist_angular <- calculate_distance(x, y, method = "cosine")

dynutils documentation built on March 22, 2021, 5:06 p.m.