The function may be called by the names: g03ebc or nag_mv_distance_mat_2.
3Description
Given two sets of observations on variables, a distance matrix is such that the th element represents how far apart or how dissimilar the th observation from the first set and the th observation from the second set are.
Let and be and data matrices of and observations, respectively, on variables. The distance between observation from and observation from , , is most commonly defined in terms of the scaled Minkowski -norm:
where and are the th and th elements of and respectively, is a standardization for the th variable in , is a standardization for the th variable in , and is the order of the Minkowski norm.
Three standardizations (scalings) for the variables are available.
(a)Standard deviation:
(b)Range:
(c)User-supplied values of .
In addition to the Minkowski measure 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 g03ebc 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.
g03ebc returns the full rectangular 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_VarScaleTypeInput
On entry: indicates the standardization of the variables to be used.
Standard deviation.
Range.
Standardizations given in array sx (and posibly sy).
Unscaled.
Constraint:
, , or .
3: – Nag_VarScaleYTypeInput
On entry: indicates how the standardization of the variables treats the two sets of observations.
Amalgamated.
Independent.
Standardization is based purley on observations in x.
Constraint:
, or .
4: – doubleInput
On entry: the order of the Minkowski distance metric.
Constraint:
.
5: – IntegerInput
On entry: , the number of observations in the data array x.
Constraint:
.
6: – IntegerInput
On entry: , the number of observations in the data array y.
Constraint:
.
7: – IntegerInput
On entry: l, the total number of variables in arrays x and y.
Constraint:
.
8: – const doubleInput
Note: the th element of the matrix is stored in .
On entry: must contain the value of the th variable for the th observation in the first set of observations, for and .
9: – IntegerInput
On entry: the stride separating matrix row elements in the array x.
Constraint:
.
10: – const IntegerInput
On entry: indicates whether or not the th variable in x and y is to be included in the distance computations.
If
the th variable is not included., for .
If
the th variable is included, for
Constraint:
for at least one , for .
11: – const doubleInput
Note: the th element of the matrix is stored in .
On entry: must contain the value of the th variable for the th observation in the second set of observations, for and .
12: – IntegerInput
On entry: the stride separating matrix row elements in the array y.
Constraint:
.
13: – 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 , contains the range of the variable in the th column of x.
The NAG error argument (see Section 7 in the Introduction to the NAG Library CL Interface).
6Error Indicators and Warnings
NE_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 3.1.2 in the Introduction to the NAG Library CL Interface for further information.
NE_ARRAY_CONS
On entry, at least one element of .
On entry, at least one element of or .
On entry, isv does not contain a positive element.
NE_BAD_PARAM
On entry, argument had an illegal value.
NE_CONST_COL
Variable is constant.
NE_INT
On entry, .
Constraint: .
On entry, .
Constraint: .
On entry, .
Constraint: .
NE_INT_2
On entry, and .
Constraint: .
On entry, and .
Constraint: .
NE_INTERNAL_ERROR
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.
See Section 7.5 in the Introduction to the NAG Library CL Interface for further information.
NE_NEG_ELEMENT
On entry, at least one element of .
NE_NO_LICENCE
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library CL Interface for further information.
NE_REAL
On entry, .
Constraint: .
7Accuracy
The computations are believed to be stable.
8Parallelism and Performance
Background information to multithreading can be found in the Multithreading documentation.
g03ebc 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
When there is a large number of observations and these do not require scaling factors to be computed internally, then the distance matrix for all observations can be computed in stages by using g03ebc to systematically calculate the distance matrix for pairs of row blocks of observations. When there are a large number of variables, the distance matrix can be updated in stages using observations on blocks of variables at each update.
10Example
Two data matrices of five and three observations on three variables is read in and a distance matrix is calculated from variables and using Euclidean distance with no scaling. This matrix is then printed.