Scilab Home page | Wiki | Bug tracker | Forge | Mailing list archives | ATOMS | File exchange
Change language to: Français - Português - 日本語 - Русский

Please note that the recommended version of Scilab is 6.1.1. This page might be outdated.
See the recommended documentation of this function

Scilab help >> Statistics > Descriptive Statistics > variance

# variance

variance of the values of a vector or matrix (or hypermatrix) real or complex

### Calling Sequence

```s = variance(x [,orien [,w]])
s = variance(x,'r') or s = variance(x,1)
s = variance(x,'c') or s = variance(x,2)
s = variance(x,'*',1)
s = variance(x,'r',1)
s = variance(x,'c',1)```

### Arguments

x

real or complex vector or matrix. An hypermatrix is accepted only for undirectional computations `variance(x)` or `variance(x,"*",1)`

orien

the orientation of the computation. Valid values are

• 1 or "r" : result is a row, after a column-wise computation.
• 2 or "c" : result is a column, after a row-wise computation.
• "*" : full undirectional computation (default); useful explicitly when `w` is used.

w

w : type of normalization to use. Valid values are

• 0 : provides the best unbiased estimator of the variance when the mean is not known a priori. This is the default. The sum is normalized by 1/(nE-1), where nE is the number of summed elements (the number of rows nR if "r" is used; of columns nC if "c" is used; or by default nC*nR)
• 1 : provides the second moment around the mean. The sum is normalized by 1/nE. This estimation is unbiased only if the mean is known a priori.

### Description

This function computes the variance of the real or complex numbers stored into a vector or matrix `x`. If `x` is complex, `variance(x,..) = variance(real(x),..) + variance(imag(x),..)` is returned.

For a vector, a matrix, or an hypermatrix `x`, `s = variance(x)` or `s = variance(x, "*", 1)` returns in the scalar `s` the variance of all the entries of `x`.

`s = variance(x,'c')` (or, equivalently, `s = variance(x,2)`) is the columnwise variance: s is a column vector, with `s(j) = variance(x(j,:))`.

`s = variance(x,'r')` (or, equivalently, `s = variance(x,1)`) is the rowwise variance: s is a row vector, with s(i) the variance of `s(i) = variance(x(:,i))`.

### Examples

```x = [ 0.2113249 0.0002211 0.6653811;0.7560439 0.4453586 0.6283918 ]
s = variance(x)
s = variance(x, "r")
s = variance(x, "c")

// with complex numbers
x = rand(4,3) + rand(4,3)*%i
s = variance(x)
s = variance(x, "*", 1)    // should be smaller than the previous one
s = variance(x, "r")
s = variance(x, "r", 1)
s = variance(x, "c")

// with an hypermatrix
x = rand(3,2,2)
s = variance(x)
s = variance(x, "*", 1)    // should be smaller than the previous one
// s = variance(x, "r")  // is not supported for an hypermatrix
// s = variance(x, "c")  // is not supported for an hypermatrix```

• mtlb_var — Matlab var emulation function

### Bibliography

Wonacott, T.H. & Wonacott, R.J.; Introductory Statistics, fifth edition, J.Wiley & Sons, 1990.

### History

 Version Description 5.4.1 variance(complexes) fixed. variance(x,"*",1) introduced. Vectorization of the code for directional usages variance(x,"r"|"c"). Full revision of the help page