Calculate the variance of a one-dimensional single-precision floating-point ndarray.
The population variance of a finite size population of size N is given by
where the population mean is given by
Often in the analysis of data, the true population variance is not known a priori and must be estimated from a sample drawn from the population distribution. If one attempts to use the formula for the population variance, the result is biased and yields an uncorrected sample variance. To compute a corrected sample variance for a sample of size n,
where the sample mean is given by
The use of the term n-1 is commonly referred to as Bessel's correction. Note, however, that applying Bessel's correction can increase the mean squared error between the sample variance and population variance. Depending on the characteristics of the population distribution, other correction factors (e.g., n-1.5, n+1, etc) can yield better estimators.
var svariance = require( '@stdlib/stats/base/ndarray/svariance' );Computes the variance of a one-dimensional single-precision floating-point ndarray.
var Float32Array = require( '@stdlib/array/float32' );
var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );
var ndarray = require( '@stdlib/ndarray/base/ctor' );
var opts = {
'dtype': 'float32'
};
var xbuf = new Float32Array( [ 1.0, -2.0, 2.0 ] );
var x = new ndarray( opts.dtype, xbuf, [ 3 ], [ 1 ], 0, 'row-major' );
var correction = scalar2ndarray( 1.0, opts );
var v = svariance( [ x, correction ] );
// returns ~4.333333The function accepts the following arguments:
- arrays: array-like object containing a one-dimensional input ndarray and a zero-dimensional ndarray specifying a degrees of freedom adjustment.
The function assumes that the input ndarray has a single-precision floating-point data type float32.
var Float32Array = require( '@stdlib/array/float32' );
var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );
var ndarray = require( '@stdlib/ndarray/base/ctor' );
var svariance = require( '@stdlib/stats/base/ndarray/svariance' );
var opts = {
'dtype': 'float32'
};
var xbuf = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] );
var x = new ndarray( opts.dtype, xbuf, [ 4 ], [ 2 ], 1, 'row-major' );
var correction = scalar2ndarray( 1.0, opts );
var v = svariance( [ x, correction ] );
// returns 6.25