Skip to content

compute truncmean

kgryte edited this page May 12, 2015 · 1 revision

Computes the truncated mean of an array. The discard parameter specifies how many values are excluded from both ends of the input array when computing the statistic. discard may either be expressed as a percentage on the interval [0,0.5] or as an integer less than half the input array length.

var data = [ 2, 4, 5, 3, 8, 2, 4, 4, 100, 0 ];

var mu = compute.truncmean( data, 0.1 );
// returns 4

If the input array is already sorted in ascending order, set the sorted option to true.

var data = [ 0, 2, 2, 3, 4, 4, 4, 5, 8, 100 ];

var mu = compute.truncmean( data, 2, {
	'sorted': true
});
// returns ~3.67

For non-numeric arrays, provide an accessor function for accessing numeric array values.

var data = [
    {'x':2},
    {'x':4},
    {'x':5},
    {'x':3},
    {'x':8},
    {'x':2},
    {'x':4},
    {'x':4},
    {'x':100},
    {'x':0}
];

function getValue( d ) {
	return d.x;
}

var mu = compute.truncmean( data, 0.1, {
	'accessor': getValue
});
// returns 4

For additional options, see compute-truncmean.

Clone this wiki locally