The routine may be called by the names g03eaf or nagf_mv_distance_mat.
3Description
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 g03eaf.
(a)Euclidean distance: and .
(b)Euclidean squared distance: and .
(c)Absolute distance (city block metric):
and .
Three standardizations are available.
(a)Standard deviation:
(b)Range:
(c)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 g03eaf 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 Chapters G02 and G11 respectively.
g03eaf returns the strictly lower triangle of the distance matrix.
4References
Everitt B S (1974) Cluster Analysis Heinemann
Krzanowski W J (1990) Principles of Multivariate Analysis Oxford University Press
5Arguments
1: – Character(1)Input
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: – Character(1)Input
On entry: indicates which type of distances are computed.
Absolute distances.
Euclidean distances.
Euclidean squared distances.
Constraint:
, or .
3: – Character(1)Input
On entry: indicates the standardization of the variables to be used.
On exit: the strictly lower triangle of the distance matrix stored packed by rows, i.e., is contained in , .
11: – IntegerInput/Output
On entry: ifail must be set to , or to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of means that an error message is printed while a value of means that it is not.
If halting is not appropriate, the value or is recommended. If message printing is undesirable, then the value is recommended. Otherwise, the value is recommended. When the value or is used it is essential to test the value of ifail on exit.
On exit: unless the routine detects an error or a warning has been flagged (see Section 6).
6Error Indicators and Warnings
If on entry or , explanatory error messages are output on the current error message unit (as defined by x04aaf).
Errors or warnings detected by the routine:
On entry, .
Constraint: , or
On entry, and .
Constraint: .
On entry, .
Constraint: .
On entry, .
Constraint: .
On entry, .
Constraint: , , or .
On entry, .
Constraint: or .
On entry, at least one element of .
On entry, at least one element of .
On entry, isx does not contain a positive element.
Variable is constant.
An unexpected error has been triggered by this routine. Please
contact NAG.
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.
7Accuracy
The computations are believed to be stable.
8Parallelism and Performance
g03eaf is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
g03eaf 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 routine. Please also consult the Users' Note for your implementation for any additional implementation-specific information.
9Further Comments
g03ecf can be used to perform cluster analysis on the computed distance matrix.
10Example
A data matrix of five observations and three variables is read in and a distance matrix is calculated from variables and using squared Euclidean distance with no scaling. This matrix is then printed.