The function may be called by the names: g03eac or nag_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 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 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.
4References
Everitt B S (1974) Cluster Analysis Heinemann
Krzanowski W J (1990) Principles of Multivariate Analysis Oxford University Press
5Arguments
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 .
Constraint:
or .
2: – Nag_DistanceTypeInput
On entry: indicates which type of distances are computed.
Absolute distances.
Euclidean distances.
Euclidean squared distances.
Constraint:
, or .
3: – Nag_VarScaleTypeInput
On entry: indicates the standardization of the variables to be used.
Standard deviation.
Range.
Standardizations given in array .
Unscaled.
Constraint:
, , or .
4: – IntegerInput
On entry: , the number of observations.
Constraint:
.
5: – IntegerInput
On entry: the total number of variables in array x.
Constraint:
.
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.
Constraint:
.
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.
Constraint:
for at least one , for .
9: – doubleInput/Output
On entry: if and then must contain the scaling for variable , for .
Constraint:
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.
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: – NagError *Input/Output
The NAG error argument (see Section 7 in the Introduction to the NAG Library CL Interface).
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.
NE_REALARR
On entry, .
Constraint: , for , when .
On entry, .
Constraint: , for , when and .
7Accuracy
The computations are believed to be stable.
8Parallelism and Performance
Background information to multithreading can be found in the Multithreading documentation.
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.
9Further Comments
g03ecc 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 2 and 3 using squared Euclidean distance with no scaling. This matrix is then printed.