ab.dist {MuViCP} | R Documentation |
Distance Functions for nearest neighbours
Description
These functions compute Absolute (ab.dist
), Euclidean
(eu.dist
) or Mahalanobis (mh.dist
) distances between two
points. The variant functions (*.matY
), accomplish the same task,
but between a point on the one hand, and every point specified as rows of a matrix on the other.
Usage
ab.dist(x, y)
eu.dist(x, y)
mh.dist(x, y, A)
ab.dist.matY(x, Y)
eu.dist.matY(x, Y)
mh.dist.matY(x, Y, A)
Arguments
x |
The vector (point) from which distance is sought. |
y |
The vector (point) to which distance is sought. |
Y |
A set of points, specified as rows of a matrix, to which distances are sought. |
A |
The inverse matrix to use for the Mahalanobis distance. |
Details
These functions are used internally to decide how the nearest neighbours shall be calculated; the user need not call any of these functions directly. Rather, the choice of distance is specified as a string ('euclidean' or 'absolute' or 'mahal').
Value
Either a single number for the distance, or a vector of distances,
corresponding to each row of Y
.
Author(s)
Mohit Dayal
See Also
get.NN
Examples
x <- c(1,2)
y <- c(0,3)
mu <- c(1,3)
Sigma <- rbind(c(1,0.2),c(0.2,1))
Y <- MASS::mvrnorm(20, mu = mu, Sigma = Sigma)
ab.dist(x,y)
eu.dist(x,y)
mh.dist(x,y,Sigma)
ab.dist.matY(x,Y)
eu.dist.matY(x,Y)
mh.dist.matY(x,Y,Sigma)