npm install compute.ioCompute.io
==========
[![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Coverage][coveralls-image]][coveralls-url] [![Dependencies][dependencies-image]][dependencies-url]
> Computation library.
1. Installation
1. Usage
- Utilities
* polyval( coef, x, opts )
* find( arr, opts, clbk )
* dims( arr, max )
* issorted( arr, clbk )
* flatten( arr, opts )
- Array Creation
* linspace( start, stop, length )
* incrspace( start, stop, increment )
* indexspace( str, len )
* logspace( a, b, length )
* datespace( start, stop, length, opts )
* incrdatespace( start, stop, increment, opts )
* zip( arr1, arr2,..., opts )
* unzip( arr, idx )
- Sorting and Reshaping Arrays
* reverse( arr, opts )
* shuffle( arr )
* circshift( x, k )
- Special Functions
* abs( arr )
* sqrt( arr )
* signum( x, opts )
* erf( x )
* erfc( x )
* erfinv( x )
* erfcinv( x )
- Arithmetic
* add( arr, x )
* subtract( arr, x )
* multiply( arr, x )
* divide( arr, x )
* roundn( x, n )
* diff( arr )
- Relational Operations
* eq( arr, x, opts)
* neq( arr, x, opts)
* gt( arr, x, opts )
* geq( arr, x, opts )
* lt( arr, x, opts )
* leq( arr, x, opts )
- Logical Operations
* isnumeric( arr )
* isnan( arr )
* isfinite( arr )
* isinteger( arr )
* isinf( arr )
- Trigonometry
* deg2rad( x )
* rad2deg( x )
- Geometry
* hypot( a, b )
- Sets
* unique( arr, sorted )
- Discrete Mathematics
* gcd( arr, clbk )
* lcm( arr, clbk )
- Linear Algebra
* l1norm( arr )
* l2norm( arr, clbk )
* linfnorm( arr )
* lpnorm( arr )
* dot( x, y, clbk )
* cross( x, y )
- Statistics
* Min
* min( arr )
* argmin( arr )
* nanmin( arr )
* argnanmin( arr )
* incrmin()
* mmin( arr, window )
* cmin( arr )
* Max
* max( arr )
* argmax( arr )
* nanmax( arr )
* argnanmax( arr )
* incrmax()
* mmax( arr, window )
* cmax( arr )
* Range
* range( arr, clbk )
* nanrange( arr, clbk )
* Sum
* sum( arr, clbk )
* nansum( arr, clbk )
* incrsum()
* msum( arr, window, opts )
* incrmsum( window )
* csum( arr )
* Product
* prod( arr, clbk )
* nanprod( arr, clbk )
* mprod( arr, window, clbk )
* cprod( arr, opts )
* Arithmetic Mean
* mean( arr )
* nanmean( arr )
* incrmean()
* mmean( arr, window, opts )
* incrmmean( window )
* Weighted Mean
* wmean( arr, weights )
* Geometric Mean
* gmean( arr, clbk )
* nangmean( arr )
* Harmonic Mean
* hmean( arr )
* nanhmean( arr )
* Quadratic Mean
* qmean( arr )
* nanqmean( arr )
* Variance
* variance( arr, opts )
* nanvariance( arr )
* incrvariance()
* mvariance( arr, window )
* incrmvariance( window )
* Standard Deviation
* stdev( arr )
* nanstdev( arr )
* incrstdev()
* mstdev( arr, window )
* incrmstdev( arr )
* Mode
* mode( arr )
* Rank Statistics
* median( arr, opts )
* nanmedian( arr, opts )
* quantile( arr, p, opts )
* quantiles( arr, num, opts )
* nanquantiles( arr, num, opts )
* iqr( arr, opts )
* idr( arr, opts )
* midrange( arr, sorted )
* midhinge( arr, opts )
* midsummary( arr, n, opts )
* midmean( arr, sorted )
* lmidmean( arr, sorted )
* umidmean( arr, sorted )
* truncmean( arr, discard, opts )
* trimean( arr, opts )
* Skewness
* skewness( arr )
* Kurtosis
* kurtosis( arr )
* Multivariate
* covariance( arr1, arr2,..., opts )
* pcorr( arr1, arr2,... )
- Information Theory
* hamdist( a, b, clbk )
* tversky( a, b, opts)
1. Fluent Interface
1. Tests
- Unit
- Coverage
1. Contributing
1. License
`` bash`
$ npm install compute.io
To use compute,
` javascript`
var compute = require( 'compute.io' );
The compute module is comprised of several smaller modules. If you want to roll your own compute, follow the links and import the individual modules.
The compute module has the following methods...
#### [compute.polyval( coef, x[, opts] )](https://github.com/compute-io/polynomial)
Evaluates a polynomial whose coefficients are defined by coef. x may be either a single numeric value or an array of values at which to evaluate to the polynomial.
` javascript
var coef = [ 4, 2, 6, -17 ];
var vals = compute.polyval( coef, [ 10, -3] );
// returns [ 4243, -125 ]
`
For object arrays, provide an accessor function for accessing array values.
` javascript
var coefs = [ 4, 2, 6, -17 ];
var data = [
['beep', 10],
['boop', -3]
];
function getValue( d, i ) {
return d[ 1 ];
}
var vals = compute.polyval( coefs, data, {
'accessor': getValue
});
// returns [ 4243, -125 ]
`
For additional options, see compute-polynomial.
#### [compute.find( arr, [opts,] clbk )](https://github.com/compute-io/find)
Finds array elements which satisfy a test condition.
` javascript
var arr = [ 2, 1, 3, 4 ];
var opts = {
'k': -2,
'returns': '*'
};
function condition( val ) {
return val < 4;
}
var results = compute.find( arr, opts, condition );
// returns [ [2,3], [1,1] ]
`
For further documentation, see the compute-find module.
#### [compute.dims( arr[, max] )](https://github.com/compute-io/dims)
Computes array dimensions, including nested arrays.
` javascript
var data, d;
data = [ 1, 2 ];
d = compute.dims( data );
// returns [2]
data = [ [1,2], [1,2] ];
d = compute.dims( data );
// returns [2,2]
`
To limit the number of dimensions returned, set the max option.
#### [compute.issorted( arr[, comparator] )](https://github.com/compute-io/issorted)
Returns a boolean indicating if an input array is sorted.
` javascript`
var bool = compute.issorted( [ 2, 3, 5, 4 ] );
// returns false
By default, the method assumes __ascending__ order. To impose an arbitrary sort order, provide a comparator function.
` javascript
function descending( a, b ) {
return b - a;
}
var bool = compute.issorted( [ 5, 4, 3, 2 ], descending );
// returns true
`
#### [compute.flatten( arr[, options] )](https://github.com/compute-io/flatten)
Flattens an array.
` javascript
var arr = [ 1, [2, [3, [4, [ 5 ], 6], 7], 8], 9 ];
var out = compute.flatten( arr );
// returns [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
`
For method options, such as limiting depth, deep copying, and function generation, see compute-flatten.
#### [compute.linspace( start, stop[, length] )](https://github.com/compute-io/linspace)
Generates a linearly spaced numeric array. If a length is not provided, the default output array length is 100.
` javascript`
var arr = compute.linspace( 0, 100, 6 );
// returns [ 0, 20, 40, 60, 80, 100 ]
#### [compute.incrspace( start, stop[, increment] )](https://github.com/compute-io/incrspace)
Generates a linearly spaced numeric array. If an increment is not provided, the default increment is 1.
` javascript`
var arr = compute.incrspace( 0, 11, 2 );
// returns [ 0, 2, 4, 6, 8, 10 ]
#### compute.indexspace( str, len )
Generates a linearly spaced index array from a subsequence string. len specifies the output index array length.
` javascript
var arr = compute.indexspace( ':', 5 );
// returns [ 0, 1, 2, 3, 4 ]
arr = compute.indexspace( '2:', 5 );
// returns [ 2, 3, 4 ]
arr = compute.indexspace( '1:4:2', 5 );
// returns [ 1, 3 ]
arr = compute.indexspace( '-3:', 5 );
// returns [ 2, 3, 4 ];
arr = compute.indexspace( ':-2', 5 );
// returns [ 0, 1, 2 ]
arr = compute.indexspace( ':', 0 );
// returns []
`
The subsequence string syntax is similar to Python's slice notation.
` javascript`
var str = '
The method also recognizes the end keyword, which refers to the last index; i.e., len-1. If specified as the stop index, end is __inclusive__ and equivalent to .
` javascript
arr = compute.indexspace( 'end::-1', 5 );
// returns [ 4, 3, 2, 1, 0 ]
arr = compute.indexspace( ':end', 5 );
// returns [ 0, 1, 2, 3, 4 ]
`
Basic arithmetic (subtraction and division) may be performed on the end keyword. The result from division is __rounded up__ to the next integer.
` javascript
arr = compute.indexspace( 'end-2::-1', 5 );
// returns [ 2, 1, 0 ];
arr = compute.indexspace( ':end/2', 5 );
// returns [ 0, 1 ]
`
For further details about syntax and additional examples, see compute-indexspace.
#### [compute.logspace( a, b[, length] )](https://github.com/compute-io/logspace)
Generates a logarithmically spaced numeric array. If a length is not provided, the default output array length is 10.
` javascript`
var arr = compute.logspace( 0, 2, 6 );
// returns [ 1, ~2.5, ~6.31, ~15.85, ~39.81, 100 ]
#### [compute.datespace( start, stop[, length, opts] )](https://github.com/compute-io/datespace)
Generates an array of linearly spaced Date objects. If a length is not provided, the default output array length is 100.
` javascript
var stop = '2014-12-02T07:00:54.973Z',
start = new Date( stop ) - 60000;
var arr = compute.datespace( start, stop, 6 );
/* returns [
'Mon Dec 01 2014 22:59:54 GMT-0800 (PST)',
'Mon Dec 01 2014 23:00:06 GMT-0800 (PST)',
'Mon Dec 01 2014 23:00:18 GMT-0800 (PST)',
'Mon Dec 01 2014 23:00:30 GMT-0800 (PST)',
'Mon Dec 01 2014 23:00:42 GMT-0800 (PST)',
'Mon Dec 01 2014 23:00:54 GMT-0800 (PST)'
]
*/
`
For function options, see the compute-datespace module.
#### [compute.incrdatespace( start, stop[, increment, opts] )](https://github.com/compute-io/incrdatespace)
Generates an array of linearly spaced Date objects. If an increment is not provided, the default increment is day.
` javascript
var stop = '2014-12-02T07:00:54.973Z',
start = new Date( stop ) - 60000;
var arr = compute.incrdatespace( start, stop, '8sec' );
/* returns [
'Mon Dec 01 2014 22:59:54 GMT-0800 (PST)',
'Mon Dec 01 2014 23:00:06 GMT-0800 (PST)',
'Mon Dec 01 2014 23:00:18 GMT-0800 (PST)',
'Mon Dec 01 2014 23:00:30 GMT-0800 (PST)',
'Mon Dec 01 2014 23:00:42 GMT-0800 (PST)'
]
*/
`
For function options, see the compute-incrdatespace module.
#### [compute.zip( arr1, arr2,...[, opts] )](https://github.com/compute-io/zip)
Returns an array of arrays, where the ith element (tuple) in the returned array contains the ith elements of the input arrays.
` javascript`
var zipped = compute.zip( [1,2], ['a','b'] );
// returns [ [1,'a'], [2,'b'] ]
For function options, see the compute-zip module.
#### [compute.unzip( arr[, idx] )](https://github.com/compute-io/unzip)
Unzips a zipped array (i.e., a nested array of tuples).
` javascript
var arr = [ [1,'a',3], [2,'b',4] ];
var out = compute.unzip( arr );
// returns [ [1,2], ['a','b'], [3,4] ];
`
To unzip specific tuple elements, you can provide an array of indices as an optional second argument.
` javascript
var arr = [ [1,'a',3], [2,'b',4] ];
var out = compute.unzip( arr, [0,2] );
// returns [ [1,2], [3,4] ];
`
#### [compute.reverse( arr[, opts] )](https://github.com/compute-io/reverse)
Reverses an array.
` javascript
var arr = [ 1, 2, 3, 4 ];
var out = compute.reverse( arr );
// returns [ 4, 3, 2, 1 ]
`
By default, the input array is __mutated__. To return a new array, set the copy option to true.
` javascript
var arr = [ 1, 2, 3, 4 ];
var out = compute.reverse( arr, {
'copy': true
});
// returns [ 4, 3, 2, 1 ];
console.log( arr === out );
// returns false
`
Generates a random permutation of (shuffles) an array in place.
` javascript
var arr = [ 1, 2, 3, 4 ];
compute.shuffle( arr );
`
Note: the array is mutated.
#### compute.circshift( x, k )
Circularly shifts elements/characters. x may be an array or a string. k is an integer specifying the number of positions to shift. The sign of k specifies the shift direction.
` javascript
compute.circshift( [1,2,3,4,5], 2 );
// returns [4,5,1,2,3]
var str = compute.circshift( 'beepboop', -3 );
// returns 'pboopbee'
`
Note: if provided an array, the array, is mutated.
#### compute.abs( arr )
Computes an element-wise absolute value for each element of a numeric array.
` javascript
var data = [ 2, -4, 2, -7, 3 ];
compute.abs( data );
`
Note: mutates the input array.
#### compute.sqrt( arr )
Computes an element-wise principal square root for each element of a numeric array.
` javascript
var data = [ 2, 4, 2, 7, 3 ];
compute.sqrt( data );
`
Note: mutates the input array.
#### [compute.signum( x[, opts] )](https://github.com/compute-io/signum)
Evaluates the signum function, where x may be a single numeric value or a numeric array.
` javascript
var sgn = compute.signum( -10 );
// returns -1
var sgns = compute.signum( [ -10, -1, -0, 0, 1, 10 ] );
// returns [ -1, -1, -0, 0, 1, 1 ]
`
For object arrays, provide an accessor function for accessing numeric values.
` javascript
var data = [
[1,-10],
[2,-1],
[3,-0],
[4,0],
[5,1],
[6,10]
];
function getValue( d, i ) {
return d[ 1 ];
}
var sgns = compute.signum( data, {
'accessor': getValue
});
// returns [ -1, -1, -0, 0, 1, 1 ]
`
For additional options, see compute-signum.
#### compute.erf( x )
Evaluates the error function, where x may be a single numeric value or a numeric array.
` javascript
var data = [ -10, -1, 0, 1, 10 ];
var x = compute.erf( data );
`
#### compute.erfc( x )
Evaluates the complementary error function, where x may be a single numeric value or a numeric array.
` javascript
var data = [ -10, -1, 0, 1, 10 ];
var x = compute.erfc( data );
`
#### compute.erfinv( x )
Evaluates the inverse error function, where x may be a single numeric value or a numeric array.
` javascript
var data = [ -1, -0.5, 0, 0.5, 1 ];
var x = compute.erfinv( data );
`
#### compute.erfcinv( x )
Evaluates the inverse complementary error function, where x may be a single numeric value or a numeric array.
` javascript
var data = [ 0, 0.5, 1, 1.5, 2 ];
var x = compute.erfcinv( data );
`
Computes an element-wise addition of a numeric array, where x may be an array of equal length or a numeric value.
` javascript
var data = [ 2, 4, 2, 7, 3 ];
compute.add( data, 5.5 );
`
Note: mutates the input array.
#### compute.subtract( arr, x )
Computes an element-wise subtraction of a numeric array, where x may be an array of equal length or a numeric value.
` javascript
var data = [ 2, 4, 2, 7, 3 ];
compute.subtract( data, 5.5 );
`
Note: mutates the input array.
#### compute.multiply( arr, x )
Computes an element-wise multiplication of a numeric array, where x may be an array of equal length or a numeric value.
` javascript
var data = [ 2, 4, 2, 7, 3 ];
compute.multiply( data, 5.5 );
`
Note: mutates the input array.
Computes an element-wise division of a numeric array, where x may be an array of equal length or a numeric value.
` javascript
var data = [ 2, 4, 2, 7, 3 ];
compute.divide( data, 5.5 );
`
Note: mutates the input array.
Rounds values to the nearest multiple of 10^n. x may be either a single numeric value or an array of values. n must be an integer.
` javascript
compute.roundn( Math.PI, -2 );
// returns 3.14
var x = compute.roundn( 111, 2 );
// returns 100
var data = [ 2.342, 4.943, 2.234, 7.992, 3.142 ];
compute.roundn( data, -2 );
// returns [...] where each value is rounded to nearest hundredth
`
Note: if provided an array, the array is mutated.
#### compute.diff( arr )
Calculates the differences between adjacent elements in an array.
` javascript
var arr = [ 2, 1, 3, 4 ];
var diff = compute.diff( arr );
// returns [ 1, -2, -1 ]
`
Note: the length of the returned array is one less than the length of the original array.
#### [compute.eq( arr, x[, opts] )](https://github.com/compute-io/eq)
Computes an element-wise comparison (equality) of an array, where x may either be an array of equal length or a single value (of any type).
The function returns an array with length equal to that of the input array. Each output array element is either 0 or 1. A value of 1 means that an element is equal to a compared value and 0 means that an element is __not__ equal to a compared value.
` javascript
var data = [ 2, 4, 2, 7, 3 ],
out;
out = compute.eq( data, 3 );
// returns [ 0, 0, 0, 0, 1 ]
out = compute.eq( data, [ 3, 4, 1, 7, 4 ] );
// returns [ 0, 1, 0, 1, 0 ]
`
For function options, see compute-eq.
#### [compute.neq( arr, x[, opts] )](https://github.com/compute-io/neq)
Computes an element-wise comparison (not equal) of an array, where x may either be an array of equal length or a single value (of any type).
The function returns an array with length equal to that of the input array. Each output array element is either 0 or 1. A value of 1 means that an element is __not__ equal to a compared value and 0 means that an element is equal to a compared value.
` javascript
var data = [ 2, 4, 2, 7, 3 ],
out;
out = compute.neq( data, 3 );
// returns [ 1, 1, 1, 1, 0 ]
out = compute.neq( data, [ 3, 4, 1, 7, 4 ] );
// returns [ 1, 0, 1, 0, 1 ]
`
For function options, see compute-neq.
#### [compute.gt( arr, x[, opts] )](https://github.com/compute-io/gt)
Computes an element-wise comparison (greater than) for each input array element. x may either be an array of equal length or a single value (number or string).
The function returns an array with a length equal to that of the input array. Each output array element is either 0 or 1. A value of 1 means that an element is greater than a compared value and 0 means that an element is __not__ greater than a compared value.
` javascript
var data = [ 2, 4, 2, 7, 3 ],
out;
out = compute.gt( data, 3.14 );
// returns [ 0, 1, 0, 1, 0 ]
out = compute.gt( data, [3, 5, 1, 4, 4 ] );
// returns [ 0, 0, 1, 1, 0 ]
`
For object arrays, provide an accessor function for accessing array values.
` javascript
var data = [
['beep', 5],
['boop', 3],
['bip', 8],
['bap', 3],
['baz', 2]
];
function getValue( d, i ) {
return d[ 1 ];
}
var out = compute.gt( data, 4, {
'accessor': getValue
});
// returns [ 1, 0, 1, 0, 0 ]
`
When comparing values between two object arrays, provide an accessor function which accepts 3 arguments.
` javascript
var data = [
['beep', 5],
['boop', 3],
['bip', 8],
['bap', 3],
['baz', 2]
];
var arr = [
{'x': 4},
{'x': 5},
{'x': 6},
{'x': 5},
{'x': 3}
];
function getValue( d, i, j ) {
if ( j === 0 ) {
return d[ 1 ];
}
return d.x;
}
var out = compute.gt( data, arr, {
'accessor': getValue
});
// returns [ 1, 0, 1, 0, 0 ]
`
For additional options, see compute-gt.
#### [compute.geq( arr, x[, opts] )](https://github.com/compute-io/geq)
Computes an element-wise comparison (greater than or equal to) for each input array element. x may either be an array of equal length or a single value (number or string).
The function returns an array with a length equal to that of the input array. Each output array element is either 0 or 1. A value of 1 means that an element is greater than or equal to a compared value and 0 means that an element is __not__ greater than or equal to a compared value.
` javascript
var data = [ 2, 4, 2, 7, 3 ],
out;
out = compute.geq( data, 3.14 );
// returns [ 0, 1, 0, 1, 0 ]
out = compute.geq( data, [3, 5, 1, 7, 4 ] );
// returns [ 0, 0, 1, 1, 0 ]
`
For object arrays, provide an accessor function for accessing array values.
` javascript
var data = [
['beep', 5],
['boop', 3],
['bip', 8],
['bap', 3],
['baz', 2]
];
function getValue( d, i ) {
return d[ 1 ];
}
var out = compute.geq( data, 3, {
'accessor': getValue
});
// returns [ 1, 1, 1, 1, 0 ]
`
When comparing values between two object arrays, provide an accessor function which accepts 3 arguments.
` javascript
var data = [
['beep', 5],
['boop', 3],
['bip', 8],
['bap', 3],
['baz', 2]
];
var arr = [
{'x': 4},
{'x': 3},
{'x': 6},
{'x': 5},
{'x': 3}
];
function getValue( d, i, j ) {
if ( j === 0 ) {
return d[ 1 ];
}
return d.x;
}
var out = compute.geq( data, arr, {
'accessor': getValue
});
// returns [ 1, 1, 1, 0, 0 ]
`
For additional options, see compute-geq.
#### [compute.lt( arr, x[, opts] )](https://github.com/compute-io/lt)
Computes an element-wise comparison (less than) for each input array element. x may either be an array of equal length or a single value (number or string).
The function returns an array with a length equal to that of the input array. Each output array element is either 0 or 1. A value of 1 means that an element is less than a compared value and 0 means that an element is __not__ less than a compared value.
` javascript
var data = [ 2, 4, 2, 7, 3 ],
out;
out = compute.lt( data, 3.14 );
// returns [ 1, 0, 1, 0, 1 ]
out = compute.lt( data, [3, 5, 1, 4, 4 ] );
// returns [ 1, 1, 0, 0, 1 ]
`
For object arrays, provide an accessor function for accessing array values.
` javascript
var data = [
['beep', 2],
['boop', 4],
['bip', 2],
['bap', 7],
['baz', 3]
];
function getValue( d, i ) {
return d[ 1 ];
}
var out = compute.lt( data, 3.14, {
'accessor': getValue
});
// returns [ 1, 0, 1, 0, 1 ]
`
When comparing values between two object arrays, provide an accessor function which accepts 3 arguments.
` javascript
var data = [
['beep', 5],
['boop', 3],
['bip', 8],
['bap', 3],
['baz', 2]
];
var arr = [
{'x': 4},
{'x': 5},
{'x': 6},
{'x': 5},
{'x': 3}
];
function getValue( d, i, j ) {
if ( j === 0 ) {
return d[ 1 ];
}
return d.x;
}
var out = compute.lt( data, arr, {
'accessor': getValue
});
// returns [ 0, 1, 0, 1, 1 ]
`
For additional options, see compute-lt.
#### [compute.leq( arr, x[, opts] )](https://github.com/compute-io/leq)
Computes an element-wise comparison (less than or equal to) for each input array element. x may either be an array of equal length or a single value (number or string).
The function returns an array with a length equal to that of the input array. Each output array element is either 0 or 1. A value of 1 means that an element is less than or equal to a compared value and 0 means that an element is __not__ less than or equal to a compared value.
` javascript
var data = [ 2, 4, 2, 7, 3 ],
out;
out = compute.leq( data, 3.14 );
// returns [ 1, 0, 1, 0, 1 ]
out = compute.leq( data, [3, 5, 1, 7, 4 ] );
// returns [ 1, 1, 0, 1, 1 ]
`
For object arrays, provide an accessor function for accessing array values.
` javascript
var data = [
['beep', 5],
['boop', 3],
['bip', 8],
['bap', 3],
['baz', 2]
];
function getValue( d, i ) {
return d[ 1 ];
}
var out = compute.leq( data, 3, {
'accessor': getValue
});
// returns [ 0, 1, 0, 1, 1 ]
`
When comparing values between two object arrays, provide an accessor function which accepts 3 arguments.
` javascript
var data = [
['beep', 5],
['boop', 3],
['bip', 8],
['bap', 3],
['baz', 2]
];
var arr = [
{'x': 4},
{'x': 3},
{'x': 6},
{'x': 5},
{'x': 3}
];
function getValue( d, i, j ) {
if ( j === 0 ) {
return d[ 1 ];
}
return d.x;
}
var out = compute.leq( data, arr, {
'accessor': getValue
});
// returns [ 0, 1, 0, 1, 1 ]
`
For additional options, see compute-leq.
Computes for each array element whether an element is numeric. The function returns an array with length equal to that of the input array. Each output array element is either 0 or 1. A value of 1 means that an element is numeric and 0 means that an element is __not__ numeric.
` javascript`
var out = compute.isnumeric( [ 2, '3', 5, 4, null, NaN ] );
// returns [ 1, 0, 1, 1, 0, 0 ]
#### compute.isnan( arr )
Computes for each array element whether an element is NaN. The function returns an array with length equal to that of the input array. Each output array element is either 0 or 1. A value of 1 means that an element is NaN and 0 means that an element is __not__ NaN.
` javascript`
var out = compute.isnan( [ 2, '3', 5, 4, null ] );
// returns [ 0, 1, 0, 0, 1 ]
Computes for each array element whether an element is a finite number. The function returns an array with length equal to that of the input array. Each output array element is either 0 or 1. A value of 1 means that an element is a finite number and 0 means that an element is __not__ a finite number.
` javascript`
var out = compute.isfinite( [ 2, 1/0, 'beep', 5, 4, -1/0, null, NaN ] );
// returns [ 1, 0, 0, 1, 1, 0, 0, 0 ]
Computes for each array element whether an element is an integer. The function returns an array with length equal to that of the input array. Each output array element is either 0 or 1. A value of 1 means that an element is an integer and 0 means that an element is __not__ an integer.
` javascript`
var out = compute.isinteger( [ 2, 1/0, 'beep', 0, -4, 3.14, null, NaN ] );
// returns [ 1, 0, 0, 1, 1, 0, 0, 0 ]
#### compute.isinf( arr )
Computes for each array element whether an element is infinite. The function returns an array with length equal to that of the input array. Each output array element is either 0 or 1. A value of 1 means that an element is infinite and 0 means that an element is __not__ infinite.
` javascript`
var out = compute.isinf( [ 2, 1/0, 'beep', 5, 4, -1/0 ] );
// returns [ 0, 1, 0, 0, 0, 1 ]
#### compute.deg2rad( x )
Converts degrees to radians, where x may be a single numeric value or a numeric array.
` javascript
var val = compute.deg2rad( 90 );
// returns pi/2
var data = [ 0, 45, 90, 135, 180 ];
compute.deg2rad( data );
// returns [ 0, pi/4, pi/2, 3pi/4, pi ]
`
Note: mutates the input array.
#### compute.rad2deg( x )
Converts radians to degrees, where x may be a single numeric value or a numeric array.
` javascript
var val = compute.rad2deg( Math.PI/2 );
// returns 90
var data = [ 0, Math.PI/4, Math.PI/2, 3*Math.PI/4, Math.PI ];
compute.rad2deg( data );
// returns [ 0, 45, 90, 135, 180 ]
`
Note: mutates the input array.
Computes the hypotenuse of a right triangle.
` javascript
var a = 10,
b = 12;
var c = compute.hypot( a, b );
`
#### [compute.unique( arr[, sorted] )](https://github.com/compute-io/unique)
Removes duplicate values to determine the subset containing all unique values of a numeric array.
` javascript
var data = [ 2, 4, 2, 7, 3 ];
compute.unique( data );
`
If the input array is already sorted in __ascending__ order, set the sorted flag to true.
Note: mutates the input array.
#### [compute.gcd( arr[, accessor] )](https://github.com/compute-io/gcd)
Computes the greatest common divisor (gcd) of two or more integers.
` javascript`
var val = compute.gcd( [48, 18] );
// returns 6
For object arrays, provide an accessor function for accessing array values
` javascript
var data = [
{'x':48},
{'x':18},
{'x':30}
];
function getValue( d, i ) {
return d.x;
}
var val = compute.gcd( data, getValue );
// returns 6
`
If provided an array with a length less than 2, the method returns null.
__Note__: the method also provides a variadic interface. See compute-gcd for additional details.
#### [compute.lcm( arr[, accessor] )](https://github.com/compute-io/lcm)
Computes the least common multiple (lcm) of two or more integers.
` javascript`
var val = compute.lcm( [21, 6] );
// returns 42
For object arrays, provide an accessor function for accessing array values
` javascript
var data = [
{'x':8},
{'x':12},
{'x':16}
];
function getValue( d, i ) {
return d.x;
}
var val = compute.lcm( data, getValue );
// returns 48
`
If provided an array with a length less than 2, the method returns null.
__Note__: the method also provides a variadic interface. See compute-lcm for additional details.
Computes the _L1_ norm (Manhattan/Taxicab norm) of an array of values.
` javascript
var data = [ 2, 4, 2, 7, 3 ];
var norm = compute.l1norm( data );
`
#### [compute.l2norm( arr[, accessor] )](https://github.com/compute-io/l2norm)
Computes the _L2_ norm (Euclidean norm) of an array.
` javascript
var data = [ 2, 4, 2, 7, 3 ];
var norm = compute.l2norm( data );
// returns ~9.06
`
For object arrays, provide an accessor function for accessing numeric values.
` javascript
var data = [
{'x':2},
{'x':4},
{'x':2},
{'x':7},
{'x':3}
];
function getValue( d, i ) {
return d.x;
}
var norm = compute.l2norm( data, getValue );
// returns ~9.06
`
If provided an empty array, the method returns null.
Computes the infinity norm (Chebyshev/maximum/supremum/uniform norm) of an array of values.
` javascript
var data = [ 2, 4, 2, -7, 3 ];
var norm = compute.linfnorm( data );
`
#### [compute.lpnorm( arr[, p] )](https://github.com/compute-io/lpnorm)
Computes the _Lp_ norm of an array of values.
` javascript
var data = [ 2, 4, 2, 7, 3 ];
// Compute the L5 norm:
var norm = compute.lpnorm( data, 5 );
`
#### [compute.dot( x, y[, accessor] )](https://github.com/compute-io/dot)
Computes the dot product between two arrays of equal length.
` javascript`
var val = compute.dot( [1,2,3], [4,5,6] );
// returns 32
For object arrays, provide an accessor function for accessing numeric values.
` javascript
function getValue( d, i, j ) {
if ( j === 0 ) {
return d.x;
}
return d;
}
var x = [
{'x':1},
{'x':2},
{'x':3}
];
var y = [ 4, 5, 6 ];
var val = compute.dot( x, y, getValue );
// returns 32
`
If provided empty arrays, the method returns null.
Computes the cross product between two arrays of length 3.
` javascript`
var val = compute.cross( [1,2,3], [4,5,6] );
#### compute.min( arr )
Computes the minimum value of a numeric array.
` javascript
var data = [ 2, 4, 2, 7, 3 ];
var min = compute.min( data );
// returns 2
`
Computes the minimum value of a numeric array and returns the corresponding array indices.
` javascript
var data = [ 2, 4, 2, 7, 3 ];
var idx = compute.argmin( data );
// returns [0,2]
`
Computes the minimum value of an array ignoring non-numeric values.
` javascript
var data = [ null, 2, 4, 2, null, 7, 3 ];
var min = compute.nanmin( data );
// returns 2
`
Computes the minimum value of an array ignoring non-numeric values and returns the corresponding array indices.
` javascript
var data = [ null, 2, 4, 2, null, 7, 3 ];
var idx = compute.argnanmin( data );
// returns [1,3]
`
#### compute.incrmin()
Returns a method to compute a minimum value incrementally.
` javascript
var data = [ 2, 4, 2, 7, 3 ];
var min = compute.incrmin(),
m;
for ( var i = 0; i < data.length; i++ ) {
m = min( data[ i ] );
console.log( m );
}
console.log( min() );
`
#### compute.mmin( arr, window )
Computes a moving minimum over a numeric array.
` javascript
var data = [ 2, 4, 2, 7, 3 ];
var arr = compute.mmin( data, 2 );
`
#### compute.cmin( arr )
Computes the cumulative minimum of a numeric array.
` javascript
var data = [ 7, 4, 2, 4, 3 ];
var arr = compute.cmin( data );
`
#### compute.max( arr )
Computes the maximum value of a numeric array.
` javascript
var data = [ 2, 4, 2, 7, 3 ];
var max = compute.max( data );
// returns 7
`
Computes the maximum value of a numeric array and returns the corresponding array indices.
` javascript
var data = [ 2, 4, 2, 7, 7, 3 ];
var idx = compute.argmax( data );
// returns [3,4]
`
Computes the maximum value of a numeric array ignoring non-numeric values.
` javascript
var data = [ -2, -4, null, -2, null, -7, -3 ];
var max = compute.nanmax( data );
// returns -2
`
Computes the maximum value of an array ignoring non-numeric values and returns the corresponding array indices.
` javascript
var data = [ null, -2, -4, -2, null, -7, -3 ];
var idx = compute.argnanmax( data );
// returns [1,3]
`
#### compute.incrmax()
Returns a method to compute a maximum value incrementally.
` javascript
var data = [ 2, 4, 2, 7, 3 ];
var max = compute.incrmax(),
m;
for ( var i = 0; i < data.length; i++ ) {
m = max( data[ i ] );
console.log( m );
}
console.log( max() );
`
#### compute.mmax( arr, window )
Computes a moving maximum over a numeric array.
` javascript
var data = [ 2, 4, 2, 7, 3 ];
var arr = compute.mmax( data, 2 );
`
#### compute.cmax( arr )
Computes the cumulative maximum of a numeric array.
` javascript
var data = [ 2, 4, 2, 7, 3 ];
var arr = compute.cmax( data );
`
#### [compute.range( arr[, accessor] )](https://github.com/compute-io/range)
Computes the arithmetic range of an array.
` javascript
var data = [ 2, 4, 2, 7, 3 ];
var range = compute.range( data );
// returns [2,7]
`
For object arrays, provide an accessor function for accessing array values
` javascript
var data = [
[1,2],
[2,4],
[3,2],
[4,7],
[5,3]
];
function getValue( d ) {
return d[ 1 ];
}
var range = compute.range( data, getValue );
// returns [2,7]
`
#### [compute.nanrange( arr[, accessor] )](https://github.com/compute-io/nanrange)
Computes the arithmetic range of an array ignoring non-numeric values.
` javascript
var data = [ 2, null, 4, 2, NaN, 7, 3 ];
var range = compute.nanrange( data );
// returns [2,7]
`
For object arrays, provide an accessor function for accessing array values
` javascript
var data = [
[1,2],
[2,null],
[3,4],
[5,2],
[6,NaN],
[7,7],
[8,3]
];
function getValue( d ) {
return d[ 1 ];
}
var range = compute.nanrange( data, getValue );
// returns [2,7]
`
#### [compute.sum( arr[, accessor] )](https://github.com/compute-io/sum)
Computes the sum of an array.
` javascript
var data = [ 2, 4, 2, 7, 3 ];
var sum = compute.sum( data );
// returns 18
`
For object arrays, provide an accessor function for accessing array values
` javascript
var data = [
[1,2],
[2,4],
[3,2],
[4,7],
[5,3]
];
function getValue( d ) {
return d[ 1 ];
}
var sum = compute.sum( data, getValue );
// returns 18
`
Computes the sum of an array ignoring non-numeric values.
` javascript
var data = [ 2, NaN, 4, 2, 7, NaN, 3 ];
var sum = compute.nansum( data );
// returns 18
`
For object arrays, provide an accessor function for accessing array values
` javascript
var data = [
[1,2],
[2,NaN],
[3,4],
[4,2],
[5,7],
[6,NaN],
[7,3]
];
function getValue( d ) {
return d[ 1 ];
}
var sum = compute.nansum( data, getValue );
// returns 18
`
#### compute.incrsum()
Returns a method to compute a sum incrementally.
` javascript
var data = [ 2, 4, 2, 7, 3 ];
var sum = compute.incrsum(),
s;
for ( var i = 0; i < data.length; i++ ) {
s = sum( data[ i ] );
console.log( s );
}
console.log( sum() );
`
#### [compute.msum( arr, window[, opts] )](https://github.com/compute-io/msum)
Computes a moving sum over an array.
` javascript
var data = [ 2, 4, 2, 7, 3 ];
var values = compute.msum( data, 2 );
// returns [ 6, 6, 9, 10 ]
`
For object arrays, provide an accessor function for accessing array values.
` javascript
var data = [
{'x':2},
{'x':4},
{'x':2},
{'x':7},
{'x':3}
];
function getValue( d ) {
return d.x;
}
var values = compute.msum( data, 2, {
'accessor': getValue
});
// returns [ 6, 6, 9, 10 ]
`
By default, a new array is returned. To compute the sums in place, i.e., mutate the input array, set the copy option to false.
` javascript
var data = [
{'x':2},
{'x':4},
{'x':2},
{'x':7},
{'x':3}
];
function getValue( d ) {
return d.x;
}
var values = compute.msum( data, 2, {
'accessor': getValue,
'copy': false
});
// returns [ 6, 6, 9, 10 ]
console.log( values === copy );
// returns true
`
#### compute.incrmsum( window )
Returns a method to compute a moving sum incrementally. window sets the window size, i.e., the number of values over which to compute a moving sum.
` javascript
var data = [ 2, 4, 2, 7, 3 ];
var msum = compute.incrmsum( 3 ),
sum;
for ( var i = 0; i < data.length; i++ ) {
sum = msum( data[ i ] );
console.log( sum );
}
console.log( msum() );
`
#### compute.csum( arr )
Computes the cumulative sum of a numeric array.
` javascript
var data = [ 2, 4, 2, 7, 3 ];
var arr = compute.csum( data );
`
#### [compute.prod( arr[, accessor] )](https://github.com/compute-io/prod)
Computes the product of an array.
` javascript
var data = [ 2, 4, 2, 7, 3 ];
var prod = compute.prod( data );
// returns 336
`
For object arrays, provide an accessor function for accessing array values
` javascript
var data = [
{'x':2},
{'x':1},
{'x':3}
];
function getValue( d ) {
return d.x;
}
var prod = compute.prod( data, getValue );
// returns 6
`
#### [compute.nanprod( arr[, accessor] )](https://github.com/compute-io/nanprod)
Computes the product of an array ignoring any non-numeric values.
` javascript
var data = [ 2, NaN, 4, 2, 7, NaN, 3 ];
var prod = compute.nanprod( data );
// returns 336
`
For object arrays, provide an accessor function for accessing array values
` javascript
var data = [
{'x':2},
{'x':NaN},
{'x':'beep'},
{'x':1},
{'x':3}
];
function getValue( d ) {
return d.x;
}
var prod = compute.nanprod( data, getValue );
// returns 6
`
#### [compute.mprod( arr, window[, accessor] )](https://github.com/compute-io/mprod)
Computes a moving product over an array.
` javascript
var data = [ 2, 4, 2, 7, 3 ];
var arr = compute.mprod( data, 2 );
// returns [ 8, 8, 14, 21 ]
`
For object arrays, provide an accessor function for accessing array values
` javascript
var data = [
[2],
[1],
[3]
];
function getValue( d ) {
return d[ 0 ];
}
var arr = compute.mprod( data, 2, getValue );
// returns [ 2, 3 ]
`
#### [compute.cprod( arr[, opts] )](https://github.com/compute-io/cprod)
Computes the cumulative product of an array.
` javascript
var data = [ 2, 4, 2, 7, 3 ];
var arr = compute.cprod( data );
// returns [ 2, 8, 16, 112, 336 ]
`
For object arrays, provide an accessor function for accessing numeric array values
` javascript
var data = [
[1,2],
[2,1],
[3,3]
];
function getValue( d, i ) {
return d[ 1 ];
}
var arr = compute.cprod( data, {
'accessor': getValue
});
// returns [ 2, 2, 6 ]
`
By default, the method returns a new array. To calculate the cumulative product in-place, set the copy option to false to mutate the input array.
` javascript
var data = [ 2, 4, 2, 7, 3 ];
var arr = compute.cprod( data, {
'copy': false
});
// returns [ 2, 8, 16, 112, 336 ]
console.log( data === arr );
// returns true
`
#### compute.mean( arr )
Computes the arithmetic mean of a numeric array.
` javascript
var data = [ 2, 4, 2, 7, 3 ];
var mean = compute.mean( data );
`
Computes the arithmetic mean over an array of values ignoring any non-numeric values.
` javascript
var data = [ 2, 4, NaN, 2, 7, NaN, 3 ];
var mean = compute.nanmean( data );
`
#### compute.incrmean()
Returns a method to compute an arithmetic mean incrementally.
` javascript
var data = [ 2, 4, 2, 7, 3 ];
var mean = compute.incrmean(),
mu;
for ( var i = 0; i < data.length; i++ ) {
mu = mean( data[ i ] );
console.log( mu );
}
console.log( mean() );
`
#### [compute.mmean( arr, window[, opts] )](https://github.com/compute-io/mmean)
Computes a moving arithmetic mean (sliding window average) over an array.
` javascript
var data = [ 2, 4, 2, 7, 3 ];
var arr = compute.mmean( data, 2 );
// returns [ 3, 3, 4.5, 5 ]
`
For object arrays, provide an accessor function for accessing array values.
` javascript
var data = [
{'x':2},
{'x':4},
{'x':2},
{'x':7},
{'x':3}
];
function getValue( d ) {
return d.x;
}
var values = compute.mmean( data, 2, {
'accessor': getValue
});
// returns [ 3, 3, 4.5, 5 ]
`
By default, a new array is returned. To compute the means in place, i.e., mutate the input array, set the copy option to false.
` javascript
var data = [
{'x':2},
{'x':4},
{'x':2},
{'x':7},
{'x':3}
];
function getValue( d ) {
return d.x;
}
var values = compute.mmean( data, 2, {
'accessor': getValue,
'copy': false
});
// returns [ 3, 3, 4.5, 5 ]
console.log( values === copy );
// returns true
`
#### compute.incrmmean( window )
Returns a method to compute a moving arithmetic mean incrementally. window sets the window size, i.e., the number of values over which to compute a moving mean.
` javascript
var data = [ 2, 4, 2, 7, 3 ];
var mmean = compute.incrmmean( 3 ),
mu;
for ( var i = 0; i < data.length; i++ ) {
mu = mmean( data[ i ] );
console.log( mu );
}
console.log( mmean() );
`
#### compute.wmean( arr, weights )
Computes a weighted mean of a numeric array.
` javascript
var data = [ 2, 4, 2, 7, 3 ],
weights = [ 1, 2, 1, 4, 0 ];
var wmean = compute.wmean( data, weights );
`
#### [compute.gmean( arr[, accessor] )](https://github.com/compute-io/gmean)
Computes the geometric mean of an array. For numeric arrays,
` javascript
var data = [ 2, 4, 2, 7, 3 ];
var gmean = compute.gmean( data );
// returns ~3.2
`
For non-numeric arrays, provide an accessor function for accessing array values
` javascript
var data = [
[1,2],
[2,4],
[3,2],
[4,7],
[5,3]
];
function getValue( d ) {
return d[ 1 ];
}
var gmean = compute.gmean( data, getValue );
// returns ~3.2
`
Computes the geometric mean over an array of values ignoring any non-numeric values.
` javascript
var data = [ 2, 4, NaN, 2, 7, NaN, 3 ];
var gmean = compute.nangmean( data );
`
#### compute.hmean( arr )
Computes the harmonic mean of a numeric array.
` javascript
var data = [ 2, 4, 2, 7, 3 ];
var hmean = compute.hmean( data );
`
Computes the harmonic mean over an array of values ignoring any non-numeric values.
` javascript
var data = [ 2, 4, NaN, 2, 7, NaN, 3 ];
var hmean = compute.nanhmean( data );
`
#### compute.qmean( arr )
Computes the quadratic mean (root mean square) of a numeric array.
` javascript
var data = [ 2, 4, 2, 7, 3 ];
var qmean = compute.qmean( data );
`
Computes the quadratic mean (root mean square) over an array of values ignoring any non-numeric values.
` javascript
var data = [ 2, 4, NaN, 2, 7, NaN, 3 ];
var qmean = compute.nanqmean( data );
`
#### [compute.variance( arr[, opts] )](https://github.com/compute-io/variance)
Computes the variance of an array.
` javascript
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
` javascript
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
` javascript
var data = [ 2, 4, 2, 7, 3 ];
var value = compute.variance( data, {
'bias': true
});
// returns 3.44
`
#### compute.nanvariance( arr )
Computes the sample variance over an array of values ignoring any non-numeric values.
` javascript
var data = [ 2, 4, NaN, 2, 7, NaN, 3 ];
var s2 = compute.nanvariance( data );
`
Returns a method to compute a sample variance incrementally.
` javascript
var data = [ 2, 4, 2, 7, 3 ];
var variance = compute.incrvariance(),
s2;
for ( var i = 0; i < data.length; i++ ) {
s2 = variance( data[ i ] );
console.log( s2 );
}
console.log( variance() );
`
#### compute.mvariance( arr, window )
Computes a moving (sliding window) sample variance over a numeric array.
` javascript
var data = [ 1, 5, 0, 10, 2 ];
var arr = compute.mvariance( data, 3 );
// returns [ 7, 25, 28 ]
`
#### compute.incrmvariance( window )
Returns a method to compute a moving sample variance incrementally. window sets the window size, i.e., the number of values over which to compute a moving sample variance.
` javascript
var data = [ 2, 4, 2, 7, 3 ];
var mvariance = compute.incrmvariance( 3 ),
s2;
for ( var i = 0; i < data.length; i++ ) {
s2 = mvariance( data[ i ] );
console.log( s2 );
}
console.log( mvariance() );
`
#### compute.stdev( arr )
Computes the sample standard deviation of a numeric array.
` javascript
var data = [ 2, 4, 2, 7, 3 ];
var stdev = compute.stdev( data );
`
Computes the sample standard deviation over an array of values ignoring any non-numeric values.
` javascript
var data = [ 2, 4, NaN, 2, 7, NaN, 3 ];
var stdev = compute.nanstdev( data );
`
#### compute.incrstdev()
Returns a method to compute a sample standard deviation incrementally.
` javascript
var data = [ 2, 4, 2, 7, 3 ];
var stdev = compute.incrstdev(),
sigma;
for ( var i = 0; i < data.length; i++ ) {
sigma = stdev( data[ i ] );
console.log( sigma );
}
console.log( stdev() );
`
#### compute.mstdev( arr, window )
Computes a moving (sliding window) sample standard deviation over a numeric array.
` javascript
var data = [ 1, 5, 0, 10, 2 ];
var arr = compute.mstdev( data, 3 );
// returns [ ~2.6, 5, ~5.3 ]
`
#### compute.incrmstdev( window )
Returns a method to compute a moving sample standard deviation incrementally. window sets the window size, i.e., the number of values over which to compute a moving sample standard deviation.
` javascript
var data = [ 2, 4, 2, 7, 3 ];
var mstdev = compute.incrmstdev( 3 ),
sigma;
for ( var i = 0; i < data.length; i++ ) {
sigma = mstdev( data[ i ] );
console.log( sigma );
}
console.log( mstdev() );
`
#### compute.mode( arr )
Computes the mode of an array.
` javascript
var data = [ 2, 4, 2, 7, 3 ];
var mode = compute.mode( data );
`
#### [compute.median( arr[, opts] )](https://github.com/compute-io/median)
Computes the median of an array.
` javascript
var data = [ 2, 4, 2, 7, 3 ];
var median = compute.median( data );
// returns 3
`
If the input array is already sorted in __ascending__ order, set the sorted option to true.
` javascript
var data = [ 2, 2, 3, 4, 7 ];
var median = compute.median( data, {
'sorted': true
});
// returns 3
`
For object arrays, provide an accessor function for accessing numeric array values
` javascript
var data = [
[1,2],
[2,4],
[3,2],
[4,7],
[5,3]
];
function getValue( d ) {
return d[ 1 ];
}
var median = compute.median( data, {
'accessor': getValue
});
// returns 3
`
#### [compute.nanmedian( arr[, opts] )](https://github.com/compute-io/nanmedian)
Computes the median of an array ignoring non-numeric values.
` javascript
var data = [ 2, null, 4, 2, NaN, 7, 3 ];
var median = compute.nanmedian( data );
// returns 3
`
If the input array is already sorted in __ascending__ order, set the sorted option to true.
` javascript
var data = [ 2, null, 2, 3, NaN, 4, 7 ];
var median = compute.nanmedian( data, {
'sorted': true
});
// returns 3
`
For object arrays, provide an accessor function for accessing array values
` javascript
var data = [
[1,2],
[2,null],
[3,4],
[4,2],
[5,NaN],
[6,7],
[7,3]
];
function getValue( d ) {
return d[ 1 ];
}
var median = compute.nanmedian( data, {
'accessor': getValue
});
// returns 3
`
#### [compute.quantile( arr, p[, opts] )](https://github.com/compute-io/quantile)
Computes a quantile for a numeric array.
` javascript
var data = [ 2, 4, 2, 7, 3 ];
var q = compute.quantile( data, 0.25 );
`
If the input array is already sorted in __ascending__ order, set the sorted option to true.
` javascript
var opts = {
'sorted': true
};
var data = [ 2, 2, 3, 4, 7 ];
var q = compute.quantile( data, 0.25, opts );
`
#### [compute.quantiles( arr, num[, opts] )](https://github.com/compute-io/quantiles)
Computes quantiles for a numeric array.
` javascript
var data = [ 2, 4, 2, 7, 3 ];
var arr = compute.quantiles( data, 3 );
`
If the input array is already sorted in __ascending__ order, set the sorted option to true.
` javascript
var opts = {
'sorted': true
};
var data = [ 2, 2, 3, 4, 7 ];
var arr = compute.quantiles( data, 2, opts );
`
#### [compute.nanquantiles( arr, num[, opts] )](https://github.com/compute-io/nanquantiles)
Computes quantiles for an array ignoring non-numeric values. num specifies the number of quantiles to compute.
` javascript
var data = [ 2, 4, null, 2, 7, NaN, 3 ];
var arr = compute.nanquantiles( data, 3 );
`
If the input array is already sorted in __ascending__ order, set the sorted option to true.
` javascript
var opts = {
'sorted': true
};
var data = [ 2, 2, null, 3, 4, NaN, 7 ];
var arr = compute.nanquantiles( data, 2, opts );
// returns [ 2, 3, 7 ]
`
For object arrays, provide an accessor function for accessing array values
` javascript
var data = [
[1,2],
[2,2],
[3,null],
[4,3],
[5,4],
[6,NaN],
[7,7]
];
function getValue( d ) {
return d[ 1 ];
}
var opts = {
'sorted': true,
'accessor': getValue
};
var arr = compute.nanquantiles( data, 2, opts );
// returns [2, 3, 7 ]
`
#### [compute.iqr( arr[, opts] )](https://github.com/compute-io/iqr)
Computes the interquartile range of a numeric array.
` javascript
var data = [ 2, 4, 2, 7, 3 ];
var iqr = compute.iqr( data );
`
If the input array is already sorted in __ascending__ order, set the sorted options flag to true.
#### [compute.idr( arr[, opts] )](https://github.com/compute-io/idr)
Computes the interdecile range of a numeric array.
` javascript
var data = [ 2, 4, 2, 7, 3 ];
var idr = compute.idr( data );
`
If the input array is already sorted in __ascending__ order, set the sorted options flag to true.
#### [compute.midrange( arr[, sorted] )](https://github.com/compute-io/midrange)
Computes the mid-range (mid-extreme) of a numeric array.
` javascript
var data = [ 2, 4, 2, 7, 3 ];
var mr = compute.midrange( data );
`
If the input array is already sorted in __ascending__ order, set the sorted flag to true.
#### [compute.midhinge( arr[, opts] )](https://github.com/compute-io/midhinge)
Computes the midhinge of a numeric array.
` javascript
var data = [ 2, 4, 2, 7, 3 ];
var mh = compute.midhinge( data );
`
If the input array is already sorted in __ascending__ order, set the sorted options flag to true.
#### [compute.midsummary( arr, n[, opts] )](https://github.com/compute-io/midsummary)
Computes the n% midsummary of a numeric array. n exists on the interval [0.0, 0.50] and specifies the proportion of values to discard in the distribution tails.
` javascript
var data = [ 2, 4, 2, 7, 3 ];
var ms = compute.midsummary( data, 0.25 );
`
If the input array is already sorted in __ascending__ order, set the sorted options flag to true.
#### [compute.midmean( arr[, sorted] )](https://github.com/compute-io/midmean)
Computes the midmean of a numeric array.
` javascript
var data = [ 2, 4, 2, 7, 3 ];
var mm = compute.midmean( data );
`
If the input array is already sorted in __ascending__ order, set the sorted flag to true.
#### [compute.lmidmean( arr[, sorted] )](https://github.com/compute-io/lmidmean)
Computes the lower midmean of a numeric array.
` javascript
var data = [ 2, 4, 2, 7, 3, 7, 5 ];
var lmm = compute.lmidmean( data );
`
If the input array is already sorted in __ascending__ order, set the sorted flag to true.
#### [compute.umidmean( arr[, sorted] )](https://github.com/compute-io/umidmean)
Computes the upper midmean of a numeric array.
` javascript
var data = [ 2, 4, 2, 7, 3, 7, 5 ];
var umm = compute.umidmean( data );
`
If the input array is already sorted in __ascending__ order, set the sorted flag to true.
#### [compute.truncmean( arr, discard[, opts] )](https://github.com/compute-io/truncmean)
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.
` javascript
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.
` javascript
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.
` javascript
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.
#### [compute.trimean( arr[, opts] )](https://github.com/compute-io/trimean)
Computes the trimean of a numeric array.
` javascript
var data = [ 2, 4, 2, 7, 3 ];
var trimean = compute.trimean( data );
`
If the input array is already sorted in __ascending__ order, set the sorted options flag to true.
Computes the sample skewness of an array of values.
` javascript
var data = [ 2, 4, 2, 7, 3 ];
var skew = compute.skewness( data );
`
Computes the sample excess kurtosis of an array of values.
` javascript
var data = [ 2, 4, 2, 7, 3 ];
var kur = compute.kurtosis( data );
`
#### [compute.covariance( arr1[, arr2,...,opts] )](https://github.com/compute-io/covariance)
Computes the covariance between one or more numeric arrays.
` javascript
var x = [ 1, 2, 3, 4, 5 ],
y = [ 5, 4, 3, 2, 1 ];
var mat = compute.covariance( x, y );
// returns [[2.5,-2.5],[-2.5,2.5]]
`
For method options, see compute-covariance.
#### [compute.pcorr( arr1[, arr2,...] )](https://github.com/compute-io/pcorr)
Computes a correlation matrix for one or more numeric arrays.
` javascript
var x = [ 1, 2, 3, 4, 5 ],
y = [ 5, 4, 3, 2, 1 ];
var mat = compute.pcorr( x, y );
// returns [[1,-1],[-1,1]]
`
#### [compute.hamdist( a, b[, accessor] )](https://github.com/compute-io/hamming)
Computes the Hamming distance between two sequences of equal length.
` javascript
var a = 'beep',
b = 'boop';
var dist = compute.hamdist( a, b );
// returns 2
var c = [ 4, 2, 3, 4 ],
d = [ 2, 4, 3, 1 ];
var dist = compute.hamdist( c, d );
// returns 3
`
To compute the Hamming distance between nested array values, provide an accessor function for accessing array values.
`` javascript
var a = [
{'x':4},
{'x':2},
{'x':3},
{'x':4}
];
var b = [
[1,2],
[2,4],
[3,3],
[4,1]
];
fun