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.
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 ) );
}