distancew {lazy.tools}R Documentation

Calculation of Weighted Distance Matrices

Description

Calculation of Weighted Distance Matrices

Usage

distancew(X, W = matrix(1, 1, ncol(X)), array = 1)

Arguments

X

n x r matrix

W

nG x r maatrix

array

= 0 to make the result a list

Details

This function calculates the weighted distance among the rows of X matrix by applying the k-th row of W matrix as a set of dimensional weights as:

d_ijk =sqrt( sum_{a=1}^r w[k,a] (x[i,a]-x[j,a])^2 )

or

d_ijk =sqrt( (x[i,]-x[j,])' diag(W[k,]) (x[i,]-x[j,]) )


Note that W matrix will NOT be squared when calculating distance.

Value

An array or a list of nG matrices of size n x n

Examples

X <- matrix( c(0,0,  3,0,  0,4), 3,2,  byrow=1 )
distancew( X )
W <- matrix( c(2,1, 1,2, 1,1), 3,2, byrow=1 )
distancew( X, W )


[Package lazy.tools version 0.1.4 ]