Given objects, a distance or dissimilarity matrix, is a symmetric matrix with zero diagonal elements such that the th element represents how far apart or how dissimilar the th and th objects are.
Let be an by data matrix of observations of variables on objects, then the distance between object and object , , can be defined as:
where and are the th and th elements of , is a standardization for the th variable and is a suitable function. Three functions are provided in nag_mv_distance_mat (g03eac):
(a)
Euclidean distance: and .
(b)
Euclidean squared distance: and .
(c)
Absolute distance (city block metric): and .
Three standardizations are available:
1.
Standard deviation:
2.
Range:
3.
User-supplied values of .
In addition to the above distances there are a large number of other dissimilarity measures, particularly for dichotomous variables (see Krzanowski (1990) and Everitt (1974)). For the dichotomous case these measures are simple to compute and can, if suitable scaling is used, be combined with the distances computed by nag_mv_distance_mat (g03eac) using the updating option.
Dissimilarity measures for variables can be based on the correlation coefficient for continuous variables and contingency table statistics for dichotomous data, see the g02 Chapter Introduction and the g11 Chapter Introduction respectively.
nag_mv_distance_mat (g03eac) returns the strictly lower triangle of the distance matrix.
4 References
Everitt B S (1974) Cluster Analysis Heinemann
Krzanowski W J (1990) Principles of Multivariate Analysis Oxford University Press
5 Arguments
1:
update – Nag_MatUpdateInput
On entry: indicates whether or not an existing matrix is to be updated.
The matrix is updated and distances are added to .
The matrix is initialized to zero before the distances are added to .
Constraint:
or .
2:
dist – Nag_DistanceTypeInput
On entry: indicates which type of distances are computed.
Absolute distances.
Euclidean distances.
Euclidean squared distances.
Constraint:
, or .
3:
scale – Nag_VarScaleTypeInput
On entry: indicates the standardization of the variables to be used.
Standard deviation.
Range.
Standardizations given in array .
Unscaled.
Constraint:
, , or .
4:
n – IntegerInput
On entry: the number of observations, .
Constraint:
.
5:
m – IntegerInput
On entry: the total number of variables in array x.
Constraint:
.
6:
x[] – const doubleInput
On entry: must contain the value of the th variable for the th object, for and .
7:
tdx – IntegerInput
On entry: the stride separating matrix column elements in the array x.
On entry: if then d must contain the strictly lower triangle of the distance matrix to be updated. must be stored packed by rows, i.e., , must contain .
Constraint:
if , , for .
On exit: the strictly lower triangle of the distance matrix stored packed by rows, i.e., is contained in , .
11:
fail – NagError *Input/Output
The NAG error argument (see Section 3.6 in the Essential Introduction).
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
A data matrix of five observations and three variables is read in and a distance matrix is calculated from variables 2 and 3 using squared Euclidean distance with no scaling. This matrix is then printed.