NAG Library Routine Document
G03EAF computes a distance (dissimilarity) matrix.
|SUBROUTINE G03EAF (
||UPDATE, DIST, SCAL, N, M, X, LDX, ISX, S, D, IFAIL)
||N, M, LDX, ISX(M), IFAIL
||X(LDX,M), S(M), D(N*(N-1)/2)
||UPDATE, DIST, SCAL|
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.
data matrix of observations of
objects, then the distance between object
, can be defined as:
th elements of
is a standardization for the
th variable and
is a suitable function. Three functions are provided in G03EAF.
||Euclidean distance: and .
||Euclidean squared distance: and .
||Absolute distance (city block metric):
Three standardizations are available.
||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.
Everitt B S (1974) Cluster Analysis Heinemann
Krzanowski W J (1990) Principles of Multivariate Analysis Oxford University Press
- 1: UPDATE – CHARACTER(1)Input
: 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: DIST – CHARACTER(1)Input
: indicates which type of distances are computed.
- Absolute distances.
- Euclidean distances.
- Euclidean squared distances.
, or .
- 3: SCAL – CHARACTER(1)Input
: indicates the standardization of the variables to be used.
- Standard deviation.
- Standardizations given in array S.
, , or .
- 4: N – INTEGERInput
On entry: , the number of observations.
- 5: M – INTEGERInput
: the total number of variables in array X
- 6: X(LDX,M) – REAL (KIND=nag_wp) arrayInput
On entry: must contain the value of the th variable for the th object, for and .
- 7: LDX – INTEGERInput
: the first dimension of the array X
as declared in the (sub)program from which G03EAF is called.
- 8: ISX(M) – INTEGER arrayInput
indicates whether or not the
th variable in X
is to be included in the distance computations.
the th variable is included, for ; otherwise it is not referenced.
for at least one , for .
- 9: S(M) – REAL (KIND=nag_wp) arrayInput/Output
On entry: if and
then must contain the scaling for variable , for .
if and , , for .
contains the standard deviation of the variable in the
th column of X
contains the range of the variable in the
th column of X
If and , .
- 10: D() – REAL (KIND=nag_wp) arrayInput/Output
must contain the strictly lower triangle of the distance matrix
to be updated.
must be stored packed by rows, i.e.,
need not be set.
if , , for .
On exit: the strictly lower triangle of the distance matrix stored packed by rows, i.e., is contained in , .
- 11: IFAIL – INTEGERInput/Output
must be set to
. If you are unfamiliar with this parameter you should refer to Section 3.3
in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value
is recommended. If the output of error messages is undesirable, then the value
is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is
. When the value is used it is essential to test the value of IFAIL on exit.
unless the routine detects an error or a warning has been flagged (see Section 6
6 Error Indicators and Warnings
If on entry
, explanatory error messages are output on the current error message unit (as defined by X04AAF
Errors or warnings detected by the routine:
|or|| or ,|
|or||, or ,|
|or||, , or .|
|On entry,||, for ,|
|or|| and , for some ,|
|or|| or and for , for some with .|
|or|| for some when and .|
The computations are believed to be stable.
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 and using squared Euclidean distance with no scaling. This matrix is then printed.
9.1 Program Text
Program Text (g03eafe.f90)
9.2 Program Data
Program Data (g03eafe.d)
9.3 Program Results
Program Results (g03eafe.r)