Programmer Guide/Command Reference/EVAL/dist: Difference between revisions

From STX Wiki
Jump to navigationJump to search
No edit summary
No edit summary
 
(6 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{DISPLAYTITLE:{{SUBPAGENAME}}}}
{{DISPLAYTITLE:{{SUBPAGENAME}}}}
Compute the variance, covariance or covariance-matrix.
Compute the distance or distance-matrix.
----
----
;Usage 1:  
;Usage 1:  
:'''<code>dist(''x''<sub>scalar</sub>, ''y''<sub>scalar</sub>)</code>'''
:<code>dist(''x''<sub>scalar</sub>, ''y''<sub>scalar</sub>)</code>
:'''<code>dist(''x''<sub>vector</sub>, ''y''<sub>vector</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>vector</sub>)</code>
:'''<code>dist(''x''<sub>matrix</sub>)</code>'''
:<code>dist(''x''<sub>matrix</sub>)</code>
;Result 2: The distance 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> ||-> ''d''[i,j] = dist(''x''[i], ''x''[j])
|''x''<sub>vector</sub> ||&rarr; ''d''[i,j] = dist(''x''[i], ''x''[j])
|-
|-
|''x''<sub>matrix</sub> ||-> ''d''<sub>i,j</sub> = dist(''x''[i,*], ''x''[j,*])
|''x''<sub>matrix</sub> ||&rarr; ''d''[i,j] = dist(''x''[i,*], ''x''[j,*])
|-
| || with: i,j = 0 .. <code>ncol(''x'')</code>
|}
|}
----
----
;Usage 2: '''<code>dist(''x'')</code>'''
;Usage 3:  
;Result 2:
:<code>dist(''x''<sub>vector</sub>, ''y''<sub>scalar</sub>)</code>
The covariance ''v'' of the vectors ''x'' and ''y''.
:<code>dist(''x''<sub>matrix</sub>, ''y''<sub>vector</sub>)</code>
:<code>''v'' = sum( (''x''-avr(''x'') ?* (''y''-avr(''y'')) ) / (nrow(''x'')-1)</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.
:<code>''v'' = ((''x''-avr(''x'') * (''y''-avr(''y''))) / (nrow(''x'')-1)</code>
:{|class="keinrahmen"
----
|''x''<sub>vector</sub>,''y''<sub>scalar</sub> ||&rarr; ''d''[i] = dist(''x''[i], ''y'')
;Usage 3: '''<code>var(''x''<sub>matrix</sub>)</code>'''
:'''<code>var(''x''<sub>matrix</sub>, ''y''<sub>scalar</sub>)</code>'''
:'''<code>var(''x''<sub>matrix</sub>, ''y''<sub>vector</sub>)</code>'''
;Result 3: The covariance matrix ''v'' of the column vectors of ''x''.
:<code>''v''[i,j] = sum( (''x''[*,i]-a[i]) ?* (''x''[*,j]-a[j]) ) / (nrow(''x'')-1) , with: i,j = 0..ncol(''x'')-1</code>
:The column averages a[i] are computed as follows:
::{|class="einrahmen"
|''y'' not supplied || a[i] = avr(''x''[*,i])
|-
|-
|''y''<sub>scalar</sub> || a[i] = ''y''
|''x''<sub>matrix</sub>,''y''<sub>vector</sub> ||&rarr; ''d''[i,j] = dist(''x''[i,*], ''y'')  (<code>ncol(''x'')</code> must be equal to <code>nrow(''y'')</code>!)
|-
|-
|''y''<sub>vector</sub> || a[i] = ''y''[i]
| || with: i = 0 .. <code>ncol(''x'')</code>
|}
----
;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''.
:{|class="keinrahmen"
|''flag''=0 ||&rarr; ''d''[i,j] = dist(''x''[i,*], ''x[j,*]'') ||, with: i,j = 0 .. <code>nrow(''x'')</code>
|-
|-
|''flag''=1 ||&rarr; ''d''[i,j] = dist(''x''[*,i], ''x[*,j]'') ||, with: i,j = 0 .. <code>ncol(''x'')</code>
|}
|}
----
;See also: [[../var|var]], [[../corr|corr]], [[../haclust|haclust]]


;See also: [[Programmer_Guide/Command_Reference/EVAL/avr|avr]], [[Programmer_Guide/Command_Reference/EVAL/dev|dev]], [[Programmer_Guide/Command_Reference/EVAL/corr|corr]], [[Programmer_Guide/Command_Reference/EVAL/dist|dist]]
[[../#Functions|<function list>]]
 
[[Programmer_Guide/Command_Reference/EVAL#Functions|<function list>]]
 
 
 
{{DISPLAYTITLE:{{SUBPAGENAME}}}}
=====dist=====
 
Calculate the distance matrix for all elements in the vector <var>x</var> or for all row vectors in the matrix <var>x</var>. I.e. d(i,j) = distance (<var>x</var>[i,*], <var>x</var>[j,*]). This is a subcommand of the <code>[[Programmer Guide/Command Reference/EVAL/EVAL|EVAL]]</code> command.
 
=====Usage:=====
 
<code>dist(<var>x</var>)</code>
 
=====Return Type:=====
 
matrix
 
Calculate the Euclidean distance from <var>x</var> to <var>y</var>. Both arguments must be either scalars or vectors.
 
=====Usage:=====
 
<code>dist(<var>x</var>, <var>y</var>)</code>
 
=====Return Type:=====
 
scalar
 
Calculate the Euclidean distances between all elements of <var>x</var>v or all row vectors of <var>x</var>m to the value <var>y</var>s or the vector <var>y</var>v. The result is a vector with x[!nrow] elements.
 
=====Usage:=====
 
<code>dist(<var>xv,ys</var>)</code>
 
<code>dist(<var>x</var>m, <var>y</var>v)</code>
 
=====Return Type:=====
 
vector

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 to nrow(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)

See also
var, corr, haclust

<function list>

Navigation menu

Personal tools