NAG Library Function Document
nag_mv_distance_mat (g03eac)
1
Purpose
nag_mv_distance_mat (g03eac) computes a distance (dissimilarity) matrix.
2
Specification
#include <nag.h> |
#include <nagg03.h> |
void |
nag_mv_distance_mat (Nag_MatUpdate update,
Nag_DistanceType dist,
Nag_VarScaleType scale,
Integer n,
Integer m,
const double x[],
Integer tdx,
const Integer isx[],
double s[],
double d[],
NagError *fail) |
|
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
nag_mv_distance_mat (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
nag_mv_distance_mat (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.
nag_mv_distance_mat (g03eac) 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:
– 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.
If
and
then
and if
then
s is unchanged.
- 10:
– doubleInput/Output
-
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 3.7 in How to Use the NAG Library and its Documentation).
6
Error Indicators and Warnings
- NE_2_INT_ARG_LT
-
On entry, while . These arguments must satisfy .
- NE_BAD_PARAM
-
On entry, argument
dist had an illegal value.
On entry, argument
scale had an illegal value.
On entry, argument
update had an illegal value.
- NE_IDEN_ELEM_COND
-
On entry, or , and , for , for some with .
- NE_INT_ARG_LE
-
On entry, .
Constraint: .
- NE_INT_ARG_LT
-
On entry, .
Constraint: .
- NE_INTARR
-
On entry, .
Constraint: , for at least one .
- 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.
- NE_REALARR
-
On entry, .
Constraint: , for , when .
On entry, .
Constraint: , for , when and .
7
Accuracy
The computations are believed to be stable.
8
Parallelism and Performance
nag_mv_distance_mat (g03eac) is not threaded in any implementation.
nag_mv_hierar_cluster_analysis (g03ecc) 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 2 and 3 using squared Euclidean distance with no scaling. This matrix is then printed.
10.1
Program Text
Program Text (g03eace.c)
10.2
Program Data
Program Data (g03eace.d)
10.3
Program Results
Program Results (g03eace.r)