distancew0 {lazy.tools} | R Documentation |
Calculation of Weighted Distance Matrix
distancew0(X, W = diag(ncol(X)))
X |
n x r matrix |
W |
r x r diagonal maatrix |
This function calculates the weighted distance among the rows of
X
matrix by applying the a-th diagonal element of W
matrix
as the dimensional weights as:
d_ij =sqrt( sum_{a=1}^r w[a,a] (x[i,a]-x[j,a])^2 )
or
d_ij =sqrt( (x[i,]-x[j,])' W (x[i,]-x[j,]) )
Note that W
matrix will NOT be squared when calculating distance.
A matrices of size n x n
X <- matrix( c(0,0, 3,0, 0,4), 3,2, byrow=1 )
distancew0( X )
W <- diag(c(2,1))
distancew0( X,W )