Skip to content

Latest commit

 

History

History
113 lines (67 loc) · 2.43 KB

File metadata and controls

113 lines (67 loc) · 2.43 KB

quantile

Compute the p-th quantile of a sorted one-dimensional ndarray.

Usage

var quantile = require( '@stdlib/stats/base/ndarray/quantile' );

quantile( arrays , p )

Computes the p-th quantile of a sorted one-dimensional ndarray.

var ndarray = require( '@stdlib/ndarray/base/ctor' );

var xbuf = [ 1.0, 2.0, 3.0, 4.0 ];
var x = new ndarray( 'generic', xbuf, [ 4 ], [ 1 ], 0, 'row-major' );

var v = quantile( [x], 0.5 );
// returns 2.5

The function has the following parameters:

  • arrays: array-like object containing a sorted one-dimensional input ndarray.
  • p: quantile probability in the interval 0 and 1.

Notes

  • If provided an empty ndarray, the function returns NaN.

Examples

var linspace = require( '@stdlib/array/linspace' );
var ndarray = require( '@stdlib/ndarray/base/ctor' );
var ndarray2array = require( '@stdlib/ndarray/to-array' );
var quantile = require( '@stdlib/stats/base/ndarray/quantile' );

// Create a linearly spaced sorted array:
var xbuf = linspace( 0.0, 10.0, 11 );

var x = new ndarray( 'generic', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' );
console.log( ndarray2array( x ) );

var v = quantile( [ x ], 0.5 );
console.log( v );