From d62a9e78b1df1e3594182d22f0cd9636eaecc5b3 Mon Sep 17 00:00:00 2001 From: DivyanshuVorrtex Date: Fri, 28 Nov 2025 09:41:02 +0000 Subject: [PATCH] feat/quantile --- .../stats/base/ndarray/quantile/README.md | 113 ++++++++++++++++++ .../ndarray/quantile/benchmark/benchmark.js | 101 ++++++++++++++++ .../stats/base/ndarray/quantile/docs/repl.txt | 34 ++++++ .../ndarray/quantile/docs/types/index.d.ts | 46 +++++++ .../base/ndarray/quantile/docs/types/test.ts | 73 +++++++++++ .../base/ndarray/quantile/examples/index.js | 36 ++++++ .../stats/base/ndarray/quantile/lib/index.js | 44 +++++++ .../stats/base/ndarray/quantile/lib/main.js | 92 ++++++++++++++ .../stats/base/ndarray/quantile/package.json | 68 +++++++++++ .../stats/base/ndarray/quantile/test/test.js | 112 +++++++++++++++++ 10 files changed, 719 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/quantile/README.md create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/quantile/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/quantile/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/quantile/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/quantile/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/quantile/examples/index.js create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/quantile/lib/index.js create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/quantile/lib/main.js create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/quantile/package.json create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/quantile/test/test.js diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/quantile/README.md b/lib/node_modules/@stdlib/stats/base/ndarray/quantile/README.md new file mode 100644 index 000000000000..4b85c80b0d55 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/quantile/README.md @@ -0,0 +1,113 @@ + + +# quantile + +> Compute the p-th quantile of a sorted one-dimensional ndarray. + +
+ +
+ + + +
+ +## Usage + +```javascript +var quantile = require( '@stdlib/stats/base/ndarray/quantile' ); +``` + +#### quantile( arrays , p ) + +Computes the p-th quantile of a sorted one-dimensional ndarray. + +```javascript +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 + + + +```javascript +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 ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/quantile/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/ndarray/quantile/benchmark/benchmark.js new file mode 100644 index 000000000000..64273733b303 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/quantile/benchmark/benchmark.js @@ -0,0 +1,101 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var bench = require( '@stdlib/bench' ); +var linspace = require( '@stdlib/array/linspace' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var pkg = require( './../package.json' ).name; +var quantile = require( './../lib' ); + +var options = { + 'dtype': 'generic' +}; + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var xbuf; + var x; + + xbuf = linspace( 0.0, 100.0, len ); + x = new ndarray( options.dtype, xbuf, [ len ], [ 1 ], 0, 'row-major' ); + + return benchmark; + /** + * Benchmark function. + * + * @private + * @param {Object} b - benchmark instance + * @returns {void} + */ + function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = quantile( [ x ], 0.5 ); + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +* @returns {void} +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^1 + max = 6; // 10^6 + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/quantile/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/ndarray/quantile/docs/repl.txt new file mode 100644 index 000000000000..496ca725bcdf --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/quantile/docs/repl.txt @@ -0,0 +1,34 @@ +{{alias}}( arrays, p ) + Computes the p-th quantile of a sorted one-dimensional ndarray. + + The quantile is the value below which a fraction `p` of the data falls. + The input array must be sorted in ascending order. + + If provided an empty ndarray, the function returns `NaN`. + + Parameters + ---------- + arrays: ArrayLikeObject + Array-like object containing a sorted one-dimensional input ndarray. + p: number + Quantile probability in the interval [0,1]. + + Returns + ------- + out: number + Quantile value. + + Examples + -------- + > var xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + > var dt = 'generic'; + > var sh = [ xbuf.length ]; + > var sx = [ 1 ]; + > var ox = 0; + > var ord = 'row-major'; + > var x = new {{alias:@stdlib/ndarray/ctor}}( dt, xbuf, sh, sx, ox, ord ); + > {{alias}}( [ x ], 0.5 ) + 2.5 + + See Also + -------- diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/quantile/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/ndarray/quantile/docs/types/index.d.ts new file mode 100644 index 000000000000..bde044fe6a73 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/quantile/docs/types/index.d.ts @@ -0,0 +1,46 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/// + +import { ndarray } from '@stdlib/types/ndarray'; + +/** +* Computes the p-th quantile of a sorted one-dimensional ndarray. +* +* @param arrays - array-like object containing a sorted input ndarray +* @param p - quantile probability in the interval [0,1] +* @returns quantile value +* +* @example +* 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 +*/ +declare function quantile( arrays: [ T ], p: number ): number; + + +// EXPORTS // + +export = quantile; diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/quantile/docs/types/test.ts b/lib/node_modules/@stdlib/stats/base/ndarray/quantile/docs/types/test.ts new file mode 100644 index 000000000000..1f55df2e8e0b --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/quantile/docs/types/test.ts @@ -0,0 +1,73 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable space-in-parens */ + +import zeros = require( '@stdlib/ndarray/zeros' ); +import quantile = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + const x = zeros( [ 10 ], { + 'dtype': 'generic' + }); + + quantile( [ x ], 0.5 ); // $ExpectType number +} + +// The compiler throws an error if the first argument is not an array of ndarrays... +{ + quantile( '10', 0.5 ); // $ExpectError + quantile( 10, 0.5 ); // $ExpectError + quantile( true, 0.5 ); // $ExpectError + quantile( false, 0.5 ); // $ExpectError + quantile( null, 0.5 ); // $ExpectError + quantile( undefined, 0.5 ); // $ExpectError + quantile( [], 0.5 ); // $ExpectError + quantile( {}, 0.5 ); // $ExpectError + quantile( (x: number): number => x, 0.5 ); // $ExpectError +} + +// The compiler throws an error if the second argument is not a number... +{ + const x = zeros( [ 10 ], { + 'dtype': 'generic' + }); + + quantile( [ x ], '0.5' ); // $ExpectError + quantile( [ x ], true ); // $ExpectError + quantile( [ x ], false ); // $ExpectError + quantile( [ x ], null ); // $ExpectError + quantile( [ x ], undefined ); // $ExpectError + quantile( [ x ], [] ); // $ExpectError + quantile( [ x ], {} ); // $ExpectError +} + +// The compiler throws an error if the wrong number of arguments is provided... +{ + const x = zeros( [ 10 ], { + 'dtype': 'generic' + }); + + quantile(); // $ExpectError + quantile( [ x ] ); // $ExpectError + quantile( [ x ], 0.5, {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/quantile/examples/index.js b/lib/node_modules/@stdlib/stats/base/ndarray/quantile/examples/index.js new file mode 100644 index 000000000000..2dfe5e27465c --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/quantile/examples/index.js @@ -0,0 +1,36 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var linspace = require( '@stdlib/array/linspace' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var quantile = require( './../lib' ); +var v; + +// 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 ) ); + +// Compute a quantile (0.5 -> median) +v = quantile( [ x ], 0.5 ); +console.log( v ); diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/quantile/lib/index.js b/lib/node_modules/@stdlib/stats/base/ndarray/quantile/lib/index.js new file mode 100644 index 000000000000..f0c54d3505f6 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/quantile/lib/index.js @@ -0,0 +1,44 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Compute the p-th quantile of a sorted one-dimensional ndarray. +* +* @module @stdlib/stats/base/ndarray/quantile +* +* @example +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* var quantile = require( '@stdlib/stats/base/ndarray/quantile' ); +* +* 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 +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/quantile/lib/main.js b/lib/node_modules/@stdlib/stats/base/ndarray/quantile/lib/main.js new file mode 100644 index 000000000000..c7766c9299ae --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/quantile/lib/main.js @@ -0,0 +1,92 @@ +/* eslint-disable no-mixed-operators */ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var numelDimension = require( '@stdlib/ndarray/base/numel-dimension' ); +var getStride = require( '@stdlib/ndarray/base/stride' ); +var getOffset = require( '@stdlib/ndarray/base/offset' ); +var getData = require( '@stdlib/ndarray/base/data-buffer' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var ceil = require( '@stdlib/math/base/special/ceil' ); + +// TODO: replace with final strided implementation once created: + +// var strided = require( '@stdlib/stats/strided/quantile' ).ndarray; + + +// MAIN // + +/** +* Computes the p-th quantile of a sorted one-dimensional ndarray. +* +* @param {ArrayLikeObject} arrays - array-like object containing a sorted input ndarray +* @param {number} p - quantile probability in [0,1] +* @returns {number} quantile value +* +* @example +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* var quantile = require( '@stdlib/stats/base/ndarray/quantile' ); +* +* 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 +*/ +function quantile( arrays, p ) { + var offset; + var stride; + var data; + var idx; + var hi; + var lo; + var v1; + var v2; + var n; + var x; + + x = arrays[ 0 ]; + n = numelDimension( x, 0 ); + stride = getStride( x, 0 ); + offset = getOffset( x ); + data = getData( x ); + + if ( n <= 0 ) { + return NaN; + } + if ( p < 0.0 || p > 1.0 ) { + return NaN; + } + + idx = ( n - 1 ) * p; + hi = ceil( idx ); + lo = floor( idx ); + v1 = data[ offset + lo * stride ]; + v2 = data[ offset + hi * stride ]; + + return ( lo === hi ) ? v1 : v1 + ( idx - lo ) * ( v2 - v1 ); +} + + +// EXPORTS // + +module.exports = quantile; diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/quantile/package.json b/lib/node_modules/@stdlib/stats/base/ndarray/quantile/package.json new file mode 100644 index 000000000000..37f23a91cd38 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/quantile/package.json @@ -0,0 +1,68 @@ +{ + "name": "@stdlib/stats/base/ndarray/quantile", + "version": "0.0.0", + "description": "Compute the p-th quantile of a sorted one-dimensional ndarray.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "statistics", + "stats", + "mathematics", + "math", + "quantile", + "percentile", + "quartile", + "iqr", + "distribution", + "ordered statistics", + "sorted", + "ndarray" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/quantile/test/test.js b/lib/node_modules/@stdlib/stats/base/ndarray/quantile/test/test.js new file mode 100644 index 000000000000..6730d278cda0 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/quantile/test/test.js @@ -0,0 +1,112 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var quantile = require( './../lib' ); + + +// FIRST TEST MUST COME BEFORE ANY OTHER CODE // + +tape( 'main export is a function', mainExport ); +function mainExport( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof quantile, 'function', 'main export is a function' ); + t.end(); +} + + +// FUNCTIONS // + +/** +* Returns a one-dimensional ndarray. +* +* @private +* @param {Collection} buffer - underlying data buffer +* @param {NonNegativeInteger} length - number of indexed elements +* @param {integer} stride - stride length +* @param {NonNegativeInteger} offset - index offset +* @returns {ndarray} one-dimensional ndarray +*/ +function vector( buffer, length, stride, offset ) { + return new ndarray( 'generic', buffer, [ length ], [ stride ], offset, 'row-major' ); +} + + +// TESTS // + +tape( 'the function has an arity of 2', arity ); +function arity( t ) { + t.strictEqual( quantile.length, 2, 'has expected arity' ); + t.end(); +} + +tape( 'the function computes quantiles of a sorted one-dimensional ndarray', computeQuantiles ); +function computeQuantiles( t ) { + var x = [ 1.0, 2.0, 3.0, 4.0 ]; + var v; + + v = quantile( [ vector( x, 4, 1, 0 ) ], 0.5 ); + t.strictEqual( v, 2.5, 'returns expected value for p=0.5 (median)' ); + + v = quantile( [ vector( x, 4, 1, 0 ) ], 0.25 ); + t.strictEqual( v, 1.75, 'returns expected value for p=0.25 (Q1)' ); + + v = quantile( [ vector( x, 4, 1, 0 ) ], 0.75 ); + t.strictEqual( v, 3.25, 'returns expected value for p=0.75 (Q3)' ); + + t.end(); +} + +tape( 'if provided an empty vector, the function returns NaN', emptyVector ); +function emptyVector( t ) { + var v = quantile( [ vector( [], 0, 1, 0 ) ], 0.5 ); + t.strictEqual( isnan( v ), true, 'returns NaN' ); + t.end(); +} + +tape( 'the function supports non-unit strides', nonUnitStrides ); +function nonUnitStrides( t ) { + var x = [ 1.0, 2.0, 3.0, 4.0 ]; + var v = quantile( [ vector( x, 2, 2, 0 ) ], 0.5 ); + t.strictEqual( v, 2.0, 'returns expected value' ); + t.end(); +} + +tape( 'the function supports negative strides', negativeStrides ); +function negativeStrides( t ) { + var x = [ 1.0, 2.0, 3.0, 4.0 ]; + var v = quantile( [ vector( x, 4, -1, 3 ) ], 0.5 ); + t.strictEqual( v, 2.5, 'returns expected value' ); + t.end(); +} + +tape( 'the function returns NaN when p is outside [0,1]', invalidProbability ); +function invalidProbability( t ) { + var x = [ 1.0, 2.0, 3.0 ]; + + t.strictEqual( isnan( quantile( [ vector( x, 3, 1, 0 ) ], -0.1 ) ), true, 'returns NaN for p < 0' ); + t.strictEqual( isnan( quantile( [ vector( x, 3, 1, 0 ) ], 1.1 ) ), true, 'returns NaN for p > 1' ); + + t.end(); +}