The function may be called by the names: g03eac or nag_mv_distance_mat.
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 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 g03eac:
(a)Euclidean distance: and .
(b)Euclidean squared distance: and .
(c)Absolute distance (city block metric): and .
Three standardizations are available:
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 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.
g03eac returns the strictly lower triangle of the distance matrix.
Everitt B S (1974) Cluster Analysis Heinemann
Krzanowski W J (1990) Principles of Multivariate Analysis Oxford University Press
1: – 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 .
2: – Nag_DistanceTypeInput
On entry: indicates which type of distances are computed.
Euclidean squared distances.
, or .
3: – Nag_VarScaleTypeInput
On entry: indicates the standardization of the variables to be used.
Standardizations given in array .
, , or .
4: – IntegerInput
On entry: , the number of observations.
5: – IntegerInput
On entry: the total number of variables in array x.
6: – const doubleInput
On entry: must contain the value of the th variable for the th object, for and .
7: – IntegerInput
On entry: the stride separating matrix column elements in the array x.
8: – const IntegerInput
On entry: indicates whether or not the th variable in x is to be included in the distance computations.
If the th variable is included, for ; otherwise it is not referenced.
for at least one , for .
9: – doubleInput/Output
On entry: if and then must contain the scaling for variable , for .
if and ,
, for .
On exit: if and then contains the standard deviation of the variable in the th column of x.
If and then contains the range of the variable in the th column of x.
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.
On entry, .
Constraint: , for , when .
On entry, .
Constraint: , for , when and .
The computations are believed to be stable.
8Parallelism and Performance
g03eac makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
Please consult the X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this function. Please also consult the Users' Note for your implementation for any additional implementation-specific information.
g03ecc can be used to perform cluster analysis on the computed distance matrix.
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.