|
MATRIX DISTANCEName:
Given an nxp data matrix X, we compute a distance matrix D. For row distances, the Dij element of the distance matrix is the distance between row i and row j, which results in a nxn D matrix. For column distances, the Dij element of the distance matrix is the distance between column i and column j, which results in a pxp D matrix. Five distance metrics are available (the 2018/10 version of Dataplot added several additional distances).
Many multivariate techniques are based on distance matrices.
where <mat1> is a matrix for which the matrix distance is to be computed; <type> is EUCLIDEAN, MAHALANOBIS, MINKOWSKY, BLOCK, CHEBYCHEV, CANBERRA, JACCARD, PEARSON, COSINE, ANGULAR COSINE, or HAMMING and defines the type of distance to compute; and where <mat2> is a matrix where the resulting distance matrix is saved. This syntax computes row distances.
where <mat1> is a matrix for which the matrix distance is to be computed; <type> is EUCLIDEAN, MAHALANOBIS, MINKOWSKY, BLOCK, CHEBYCHEV, CANBERRA, JACCARD, PEARSON, COSINE, ANGULAR COSINE, or HAMMING and defines the type of distance to compute; and where <mat2> is a matrix where the resulting distance matrix is saved. This syntax computes column distances.
where <mat1> is a matrix for which the matrix similarity is to be computed; <type> is JACCARD, PEARSON, COSINE, or ANGULAR COSINE and defines the type of similarity to compute; and where <mat2> is a matrix where the resulting similarity matrix is saved. This syntax computes row similarities.
<type> is JACCARD, PEARSON, COSINE, or ANGULAR COSINE and defines the type of similarity to compute; and where <mat2> is a matrix where the resulting similarity matrix is saved. This syntax computes column similarities.
LET D = EUCLIDEAN COLUMN DISTANCE M
LET D = BLOCK ROW DISTANCE M
LET D = MAHALANOBIS ROW DISTANCE M
LET P = 1.5
LET D = COSINE ROW DISTANCE M
LET D = COSINE ROW SIMILARITY M
LET D = JACCARD ROW DISTANCE M
LET D = JACCARD ROW SIMILARITY M
LET D = PEARSON ROW DISTANCE M
LET D = PEARSON ROW SIMILARITY M
"Applied Multivariate Statistical Analysis", Third Edition, Johnson and Wichern, Prentice-Hall, 1992.
2018/10: Added ANGULAR COSINE DISTANCE 2018/10: Added ANGULAR COSINE SIMILARITY 2018/10: Added JACCARD DISTANCE 2018/10: Added JACCARD SIMILARITY 2018/10: Added PEARSON DISTANCE 2018/10: Added PEARSON SIMILARITY 2018/10: Added CANBERRA DISTANCE 2018/10: Added HAMMING DISTANCE
dimension 100 columns
set write decimals 4
set read missing value -999
.
let iflag1 = 1
. let iflag1 = 2
. let iflag1 = 3
. let iflag1 = 4
. let iflag1 = 5
. let iflag1 = 6
. let iflag1 = 7
. let iflag1 = 8
. let iflag1 = 9
. let iflag1 = 10
. let iflag1 = 11
let iflag2 = 1
. let iflag2 = 2
.
skip 25
read matrix iris.dat x
.
if iflag1 = 1
if iflag2 = 1
let v = euclidean column distance x
else if iflag2 = 2
let v = euclidean row distance x
end of if
else if iflag1 = 2
if iflag2 = 1
let v = block column distance x
else if iflag2 = 2
let v = block row distance x
end of if
else if iflag1 = 3
let p = 1.5
if iflag2 = 1
let v = minkowski column distance x
else if iflag2 = 2
let v = minkowski row distance x
end of if
else if iflag1 = 4
if iflag2 = 1
let v = chebychev column distance x
else if iflag2 = 2
let v = chebychev row distance x
end of if
else if iflag1 = 5
if iflag2 = 1
let v = jaccard column distance x
else if iflag2 = 2
let v = jaccard row distance x
end of if
else if iflag1 = 6
if iflag2 = 1
let v = jaccard column similarity x
else if iflag2 = 2
let v = jaccard row similarity x
end of if
else if iflag1 = 7
if iflag2 = 1
set isubro cdis
let v = cosine column distance x
set isubro
else if iflag2 = 2
let v = cosine row distance x
end of if
else if iflag1 = 8
if iflag2 = 1
let v = cosine column similarity x
else if iflag2 = 2
let v = cosine row similarity x
end of if
else if iflag1 = 9
if iflag2 = 1
let v = hamming column distance x
else if iflag2 = 2
let v = hamming row distance x
end of if
else if iflag1 = 10
if iflag2 = 1
let v = canberra column distance x
else if iflag2 = 2
let v = canberra row distance x
end of if
else if iflag1 = 11
if iflag2 = 1
let v = pearson column distance x
else if iflag2 = 2
let v = pearson row distance x
end of if
end of if
.
print v
The following output is returned
MATRIX V -- 5 ROWS
-- 5 COLUMNS
VARIABLES--V1 V2 V3 V4 V5
0.0000 36.1578 35.2624 61.4890 47.5358
36.1578 0.0000 30.1846 29.3828 18.4770
35.2624 30.1846 0.0000 37.6646 24.9542
61.4890 29.3828 37.6646 0.0000 14.9040
47.5358 18.4770 24.9542 14.9040 0.0000
|
Privacy
Policy/Security Notice
NIST is an agency of the U.S.
Commerce Department.
Date created: 06/05/2001 | |||||||||||||||||||