@stdlib/stats-base-dists-bernoulli-quantile
v0.2.2
Published
Bernoulli distribution quantile function.
Downloads
255
Readme
Quantile Function
Bernoulli distribution quantile function.
The quantile function for a Bernoulli random variable is
for 0 <= r <= 1
, where p
is the success probability.
Installation
npm install @stdlib/stats-base-dists-bernoulli-quantile
Usage
var quantile = require( '@stdlib/stats-base-dists-bernoulli-quantile' );
quantile( r, p )
Evaluates the quantile function for a Bernoulli distribution with success probability p
at a value r
.
var y = quantile( 0.8, 0.4 );
// returns 1
y = quantile( 0.5, 0.4 );
// returns 0
y = quantile( 0.9, 0.1 );
// returns 0
If provided r <= 0
or r >= 0
, the function returns NaN
.
var y = quantile( 1.9, 0.5 );
// returns NaN
y = quantile( -0.1, 0.5 );
// returns NaN
If provided NaN
as any argument, the function returns NaN
.
var y = quantile( NaN, 1.0 );
// returns NaN
y = quantile( 0.0, NaN );
// returns NaN
If provided a success probability p
outside the interval [0,1]
, the function returns NaN
.
var y = quantile( 0.4, -1.0 );
// returns NaN
y = quantile( 0.4, 1.5 );
// returns NaN
quantile.factory( p )
Returns a function for evaluating the quantile function for a Bernoulli distribution with success probability p
.
var myquantile = quantile.factory( 0.4 );
var y = myquantile( 0.4 );
// returns 0
y = myquantile( 0.8 );
// returns 1
y = myquantile( 1.0 );
// returns 1
Examples
var randu = require( '@stdlib/random-base-randu' );
var quantile = require( '@stdlib/stats-base-dists-bernoulli-quantile' );
var p;
var r;
var y;
var i;
for ( i = 0; i < 10; i++ ) {
r = randu();
p = randu();
y = quantile( r, p );
console.log( 'r: %d, p: %d, Q(r;p): %d', r.toFixed( 4 ), p.toFixed( 4 ), y.toFixed( 4 ) );
}
Notice
This package is part of stdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
For more information on the project, filing bug reports and feature requests, and guidance on how to develop stdlib, see the main project repository.
Community
License
See LICENSE.
Copyright
Copyright © 2016-2024. The Stdlib Authors.