Programmer Guide/Command Reference/EVAL/dist: Difference between revisions
From STX Wiki
< Programmer Guide | Command Reference | EVAL
Jump to navigationJump to search
No edit summary |
No edit summary |
||
(One intermediate revision by one other user not shown) | |||
Line 3: | Line 3: | ||
---- | ---- | ||
;Usage 1: | ;Usage 1: | ||
: | :<code>dist(''x''<sub>scalar</sub>, ''y''<sub>scalar</sub>)</code> | ||
: | :<code>dist(''x''<sub>vector</sub>, ''y''<sub>vector</sub>)</code> | ||
;Result 1: The euclidan distance ''d''<sub>scalar</sub> of ''x'' and ''y''. The two arguments must be scalars or vectors with the same length. | ;Result 1: The euclidan distance ''d''<sub>scalar</sub> of ''x'' and ''y''. The two arguments must be scalars or vectors with the same length. | ||
---- | ---- | ||
;Usage 2: | ;Usage 2: | ||
: | :<code>dist(''x''<sub>vector</sub>)</code> | ||
: | :<code>dist(''x''<sub>matrix</sub>)</code> | ||
;Result 2: The matrix ''d'' with the euclidian distances of all elements or row vectors of ''x''. The result is a matrix with <code>nrow(''x'')</code> rows and columns. | ;Result 2: The matrix ''d'' with the euclidian distances of all elements or row vectors of ''x''. The result is a matrix with <code>nrow(''x'')</code> rows and columns. | ||
:{|class="keinrahmen" | :{|class="keinrahmen" | ||
|''x''<sub>vector</sub> || | |''x''<sub>vector</sub> ||→ ''d''[i,j] = dist(''x''[i], ''x''[j]) | ||
|- | |- | ||
|''x''<sub>matrix</sub> || | |''x''<sub>matrix</sub> ||→ ''d''[i,j] = dist(''x''[i,*], ''x''[j,*]) | ||
|- | |- | ||
| || with: i,j = 0 .. <code>ncol(''x'')</code> | | || with: i,j = 0 .. <code>ncol(''x'')</code> | ||
Line 20: | Line 20: | ||
---- | ---- | ||
;Usage 3: | ;Usage 3: | ||
: | :<code>dist(''x''<sub>vector</sub>, ''y''<sub>scalar</sub>)</code> | ||
: | :<code>dist(''x''<sub>matrix</sub>, ''y''<sub>vector</sub>)</code> | ||
;Result 3: The vector ''d'' with the euclidian distances of all elements or row vectors of ''x'' to ''y''. The result is a vector with <code>nrow(''x'')</code> rows and columns. | ;Result 3: The vector ''d'' with the euclidian distances of all elements or row vectors of ''x'' to ''y''. The result is a vector with <code>nrow(''x'')</code> rows and columns. | ||
:{|class="keinrahmen" | :{|class="keinrahmen" | ||
|''x''<sub>vector</sub>,''y''<sub>scalar</sub> || | |''x''<sub>vector</sub>,''y''<sub>scalar</sub> ||→ ''d''[i] = dist(''x''[i], ''y'') | ||
|- | |- | ||
|''x''<sub>matrix</sub>,''y''<sub>vector</sub> || | |''x''<sub>matrix</sub>,''y''<sub>vector</sub> ||→ ''d''[i,j] = dist(''x''[i,*], ''y'') (<code>ncol(''x'')</code> must be equal to <code>nrow(''y'')</code>!) | ||
|- | |- | ||
| || with: i = 0 .. <code>ncol(''x'')</code> | | || with: i = 0 .. <code>ncol(''x'')</code> | ||
Line 32: | Line 32: | ||
---- | ---- | ||
;Usage 4: | ;Usage 4: | ||
: | :<code>dist(''x''<sub>matrix</sub>, ''flag'')</code> | ||
;Result 4: The matrix ''d'' with the euclidian distances of the row vectors (''flag''='''0''') or column vectors (''flag''='''1''') or ''x''. | ;Result 4: The matrix ''d'' with the euclidian distances of the row vectors (''flag''='''0''') or column vectors (''flag''='''1''') or ''x''. | ||
:{|class="keinrahmen" | :{|class="keinrahmen" | ||
|''flag''=0 || | |''flag''=0 ||→ ''d''[i,j] = dist(''x''[i,*], ''x[j,*]'') ||, with: i,j = 0 .. <code>nrow(''x'')</code> | ||
|- | |- | ||
|''flag''=1 || | |''flag''=1 ||→ ''d''[i,j] = dist(''x''[*,i], ''x[*,j]'') ||, with: i,j = 0 .. <code>ncol(''x'')</code> | ||
|} | |} | ||
---- | ---- | ||
;See also: [[ | ;See also: [[../var|var]], [[../corr|corr]], [[../haclust|haclust]] | ||
[[ | [[../#Functions|<function list>]] |
Latest revision as of 19:23, 21 April 2011
Compute the distance or distance-matrix.
- Usage 1
dist(xscalar, yscalar)
dist(xvector, yvector)
- Result 1
- The euclidan distance dscalar of x and y. The two arguments must be scalars or vectors with the same length.
- Usage 2
dist(xvector)
dist(xmatrix)
- Result 2
- The matrix d with the euclidian distances of all elements or row vectors of x. The result is a matrix with
nrow(x)
rows and columns.
xvector → d[i,j] = dist(x[i], x[j]) xmatrix → d[i,j] = dist(x[i,*], x[j,*]) with: i,j = 0 .. ncol(x)
- Usage 3
dist(xvector, yscalar)
dist(xmatrix, yvector)
- Result 3
- The vector d with the euclidian distances of all elements or row vectors of x to y. The result is a vector with
nrow(x)
rows and columns.
xvector,yscalar → d[i] = dist(x[i], y) xmatrix,yvector → d[i,j] = dist(x[i,*], y) ( ncol(x)
must be equal tonrow(y)
!)with: i = 0 .. ncol(x)
- Usage 4
dist(xmatrix, flag)
- Result 4
- The matrix d with the euclidian distances of the row vectors (flag=0) or column vectors (flag=1) or x.
flag=0 → d[i,j] = dist(x[i,*], x[j,*]) , with: i,j = 0 .. nrow(x)
flag=1 → d[i,j] = dist(x[*,i], x[*,j]) , with: i,j = 0 .. ncol(x)