Distance Matrix {energy} | R Documentation |
Distance Matrices
Description
Utilities for working with distance matrices.
is.dmatrix
is a utility that checks whether the argument is a distance or dissimilarity matrix; is it square symmetric, non-negative, with zero diagonal? calc_dist
computes a distance matrix directly from a data matrix.
Usage
is.dmatrix(x, tol = 100 * .Machine$double.eps)
calc_dist(x)
Arguments
x |
numeric matrix |
tol |
tolerance for checking required conditions |
Details
Energy functions work with the distance matrices of samples. The is.dmatrix
function is used internally when converting arguments to distance matrices. The default tol
is the same as default tolerance of isSymmetric
.
calc_dist
is an exported Rcpp function that returns a Euclidean distance matrix from the input data matrix.
Value
is.dmatrix
returns TRUE if (within tolerance) x
is a distance/dissimilarity matrix; otherwise FALSE. It will return FALSE if x
is a class dist
object.
calc_dist
returns the Euclidean distance matrix for the data matrix x
, which has observations in rows.
Note
In practice, if dist(x)
is not yet computed, calc_dist(x)
will be faster than as.matrix(dist(x))
.
On working with non-Euclidean dissimilarities, see the references.
Author(s)
Maria L. Rizzo mrizzo@bgsu.edu
References
Szekely, G.J. and Rizzo, M.L. (2014), Partial Distance Correlation with Methods for Dissimilarities. Annals of Statistics, Vol. 42 No. 6, 2382-2412.
Examples
x <- matrix(rnorm(20), 10, 2)
D <- calc_dist(x)
is.dmatrix(D)
is.dmatrix(cov(x))