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

From STX Wiki
Jump to navigationJump to search
m (1 revision: Initial import)
No edit summary
Line 1: Line 1:
{{DISPLAYTITLE:{{SUBPAGENAME}}}}
Compute the variance, covariance or covariance-matrix.
----
;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.
----
;Usage 2:
:'''<code>dist(''x''<sub>vector</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.
:{|class="keinrahmen"
| ''x''<sub>vector</sub> |-> ''d''[i,j] = dist(''x''[i], ''x''[j])
|-
| ''x''<sub>matrix</sub> |-> ''d''<sub>i,j</sub> = dist(''x''[i,*], ''x''[j,*])
|}
----
;Usage 2: '''<code>dist(''x'')</code>'''
;Result 2:
The covariance ''v'' of the vectors ''x'' and ''y''.
:<code>''v'' = sum( (''x''-avr(''x'') ?* (''y''-avr(''y'')) ) / (nrow(''x'')-1)</code>
:<code>''v'' = ((''x''-avr(''x'') * (''y''-avr(''y''))) / (nrow(''x'')-1)</code>
----
;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''
|-
|''y''<sub>vector</sub> || a[i] = ''y''[i]
|-
|}
;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]]
[[Programmer_Guide/Command_Reference/EVAL#Functions|<function list>]]
{{DISPLAYTITLE:{{SUBPAGENAME}}}}
{{DISPLAYTITLE:{{SUBPAGENAME}}}}
=====dist=====
=====dist=====

Revision as of 09:33, 11 April 2011

Compute the variance, covariance or covariance-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 distance 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.
-> d[i,j] = dist(x[i], x[j])
-> di,j = dist(x[i,*], x[j,*])

Usage 2
dist(x)
Result 2

The covariance v of the vectors x and y.

v = sum( (x-avr(x) ?* (y-avr(y)) ) / (nrow(x)-1)
v = ((x-avr(x) * (y-avr(y))) / (nrow(x)-1)

Usage 3
var(xmatrix)
var(xmatrix, yscalar)
var(xmatrix, yvector)
Result 3
The covariance matrix v of the column vectors of x.
v[i,j] = sum( (x[*,i]-a[i]) ?* (x[*,j]-a[j]) ) / (nrow(x)-1) , with: i,j = 0..ncol(x)-1
The column averages a[i] are computed as follows:
y not supplied a[i] = avr(x[*,i])
yscalar a[i] = y
yvector a[i] = y[i]
See also
avr, dev, corr, dist

<function list>



dist

Calculate the distance matrix for all elements in the vector x or for all row vectors in the matrix x. I.e. d(i,j) = distance (x[i,*], x[j,*]). This is a subcommand of the EVAL command.

Usage:

dist(x)

Return Type:

matrix

Calculate the Euclidean distance from x to y. Both arguments must be either scalars or vectors.

Usage:

dist(x, y)

Return Type:

scalar

Calculate the Euclidean distances between all elements of xv or all row vectors of xm to the value ys or the vector yv. The result is a vector with x[!nrow] elements.

Usage:

dist(xv,ys)

dist(xm, yv)

Return Type:

vector

Navigation menu

Personal tools