Skip to content

compute variance

kgryte edited this page May 12, 2015 · 1 revision

Computes the variance of an array.

var data = [ 2, 4, 2, 7, 3 ];

var s2 = compute.variance( data );
// returns 4.3

For object arrays, provide an accessor function for accessing array values

var data = [
	[1,2],
	[2,4],
	[3,2],
	[4,7],
	[5,3]
];

function getValue( d ) {
	return d[ 1 ];
}

var s2 = compute.variance( data, {
	'accessor': getValue
});
// returns 4.3

To compute the population variance (or a biased sample variance), set the bias option to true

var data = [ 2, 4, 2, 7, 3 ];

var value = compute.variance( data, {
	'bias': true
});
// returns 3.44
Clone this wiki locally