checkdist: Check for Distance Matrix

View source: R/checkdist.R

checkdistR Documentation

Check for Distance Matrix

Description

This function checks whether the distance matrix D:=d_{ij} = d(x_i, x_j) satisfies three axioms to make itself a semimetric, which are (1) d_{ii} = 0, (2) d_{ij} > 0 for i\neq j, and (3) d_{ij} = d_{ji}.

Usage

checkdist(d)

Arguments

d

"dist" object or (N\times N) matrix of pairwise distances.

Value

a logical; TRUE if it satisfies metric property, FALSE otherwise.

See Also

checkmetric

Examples

## Let's use L2 distance matrix of iris dataset
data(iris)
dx = as.matrix(stats::dist(iris[,1:4]))

# perturb d(i,j) 
dy = dx  
dy[1,2] <- dy[2,1] <- 10

# run the algorithm
checkdist(dx)
checkdist(dy)


maotai documentation built on March 31, 2023, 6:48 p.m.