NAG Library Routine Document
g03eaf
(distance_mat)
1
Purpose
g03eaf computes a distance (dissimilarity) matrix.
2
Specification
Fortran Interface
Subroutine g03eaf ( |
update,
dist,
scal,
n,
m,
x,
ldx,
isx,
s,
d,
ifail) |
Integer, Intent (In) | :: |
n,
m,
ldx,
isx(m) | Integer, Intent (Inout) | :: |
ifail | Real (Kind=nag_wp), Intent (In) | :: |
x(ldx,m) | Real (Kind=nag_wp), Intent (Inout) | :: |
s(m),
d(n*(n-1)/2) | Character (1), Intent (In) | :: |
update,
dist,
scal |
|
C Header Interface
#include nagmk26.h
void |
g03eaf_ (
const char *update,
const char *dist,
const char *scal,
const Integer *n,
const Integer *m,
const double x[],
const Integer *ldx,
const Integer isx[],
double s[],
double d[],
Integer *ifail,
const Charlen length_update,
const Charlen length_dist,
const Charlen length_scal) |
|
3
Description
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
by
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.
4
References
Everitt B S (1974) Cluster Analysis Heinemann
Krzanowski W J (1990) Principles of Multivariate Analysis Oxford University Press
5
Arguments
- 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.
- Standard deviation.
- Range.
- Standardizations given in array s.
- 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: – Real (Kind=nag_wp) arrayInput
-
On entry: must contain the value of the th variable for the th object, for and .
- 7: – IntegerInput
-
On entry: the first dimension of the array
x as declared in the (sub)program from which
g03eaf is called.
Constraint:
.
- 8: – Integer arrayInput
-
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: – Real (Kind=nag_wp) arrayInput/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.
If and , .
If
,
s is unchanged.
- 10: – Real (Kind=nag_wp) arrayInput/Output
-
On entry: if
,
d must contain the strictly lower triangle of the distance matrix
to be updated.
must be stored packed by rows, i.e.,
,
must contain
.
If
,
d need not be set.
Constraint:
if , , for .
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
,
. If you are unfamiliar with this argument you should refer to
Section 3.4 in How to Use the NAG Library and its Documentation 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 argument, the recommended value is
.
When the value 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).
6
Error 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, | , |
or | , |
or | , |
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 . |
An unexpected error has been triggered by this routine. Please
contact
NAG.
See
Section 3.9 in How to Use the NAG Library and its Documentation for further information.
Your licence key may have expired or may not have been installed correctly.
See
Section 3.8 in How to Use the NAG Library and its Documentation for further information.
Dynamic memory allocation failed.
See
Section 3.7 in How to Use the NAG Library and its Documentation for further information.
7
Accuracy
The computations are believed to be stable.
8
Parallelism and Performance
g03eaf is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
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.
g03ecf can be used to perform cluster analysis on the computed distance matrix.
10
Example
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.
10.1
Program Text
Program Text (g03eafe.f90)
10.2
Program Data
Program Data (g03eafe.d)
10.3
Program Results
Program Results (g03eafe.r)