Please note that the recommended version of Scilab is 2026.0.0. This page might be outdated.
See the recommended documentation of this function
variance
variance (and mean) of a vector or matrix (or hypermatrix) of real or complex numbers
Syntax
[s [,mc]] = variance(x [,orien [,m]]) [s, mc] = variance(x) [s, mc] = variance(x, "r"|1 ) [s, mc] = variance(x, "c"|2 ) [s, mc] = variance(x, "*" , %nan) [s, mc] = variance(x, "r"|1, %nan) [s, mc] = variance(x, "c"|2, %nan) s = variance(x, "*", m) s = variance(x, "r"|1, m) s = variance(x, "c"|2, m)
Arguments
- x
- real or complex vector or matrix. A hypermatrix is accepted only for undirectional computations - variance(x)or- variance(x,"*",m)
- 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); explicitly required when mis used.
 
- m
- The known mean of the underlying statistical distribution law (assuming that it is known). - "*" mode (default): mmust be scalar
- "r" or 1 mode: mis a row of lengthsize(x,2). The variance along the column #j is computed usingm(j)as the mean for the considered column. Ifm(j)is the same for all columns, it can be provided as a scalarm.
- "c" or 2 mode: mis a column of lengthsize(x,1). The variance along the row #i is computed usingm(i)as the mean for the considered row. Ifm(i)is the same for all rows, it can be provided as a scalarm.
 - When - mis not provided, the- varianceis built dividing the quadratic distance of- nvalues to- mean(x)(or- mean(x,"c")or- mean(x,"r")) by- n-1(- nbeing- length(x)or- size(x,1)or- size(x,2)). If the elements of- xare mutually independent, the result is then statistically unbiased.- Else, the - varianceis built dividing the quadratic distance of values to- mby the number n of considered values (n being length(x) or size(x,1) or size(x,2)).- If a true value - mindependent from x elements is used,- xand- mvalues are mutually independent, and the result is then unbiased.- When the special value - m = %nanis provided, the variance is still normalized by n (not n-1) but is computed using- m=mean(x)instead (or- m = mean(x,"c")or- m = mean(x,"r")). This- mdoes not bring independent information, and yields a statistically biased result.
- "*" mode (default): 
- s
- The variance of unweighted values of xelements. It is a scalar or a column vector or a row vector according toorien.
- mc
- Scalar or orien-wise mean ofxelements (unweighted) (= mean(x,..)), as computed before and used as reference in the variance.
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 a hypermatrix x, s = variance(x)
            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) = variance(x(:,i)).
The second output argument m is the mean of the input, with respect to the orien parameter.
|  | The  variance(x, "*"|"c"|"r", 1)synopsis used only in Scilab 5.4.1 must be replaced withvariance(x, "*"|"c"|"r", %nan).variance(x, "*"|"c"|"r", 1)will warn
                the user until Scilab 6.0. Indeed,1will be now considered asm=1.
                If1is the true value provided asm, the warning may be avoided entering1+%epsinstead
                of1. | 
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") // The underlying statistical distribution and its mean are known: x = grand(100, 5, "unf", 0, 7); // Uniform distribution on [0, 7] // => the true asymptotic mean is (0+7)/2 = 3.5 and variance = (7-0)^2/12 (7-0)^2/12 // True asymptotic variance s = variance(x) // Unbiased (division by n-1). s = variance(x, "*", 3.5) // Unbiased (division by n). Always >= variance(x) s = variance(x, "*", %nan) // Biased (division by n). Always <= variance(x) // Across columns: s = variance(x, "c") s = variance(x, "c", 3.5) s = variance(x, "c", %nan) // With complex numbers uniformly distributed on [0,1] + [0,1].i: x = rand(4, 3) + rand(4, 3)*%i s = variance(x) s = variance(x, "*", 0.5 + 0.5*%i) s = variance(x, "*", %nan) s = variance(x, "r") s = variance(x, "c") // With a hypermatrix x = rand(3, 2, 2) // Uniform distribution on [0, 1] s = variance(x) s = variance(x, "*", 0.5) s = variance(x, "*", %nan) // s = variance(x, "r") // Is not supported for a hypermatrix // s = variance(x, "c") // Is not supported for a hypermatrix
See also
Bibliography
Wonacott, T.H. & Wonacott, R.J.; Introductory Statistics, fifth edition, J.Wiley & Sons, 1990.
History
| Version | Description | 
| 5.5.0 | 
 | 
| 5.4.1 | 
 | 
| Report an issue | ||
| << strange | Dispersion widths | variancef >> |