@stdlib/stats-base-dists-bernoulli-quantile
v0.3.1
Published
Bernoulli distribution quantile function.
Downloads
412
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-quantileUsage
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 0If 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 NaNIf provided NaN as any argument, the function returns NaN.
var y = quantile( NaN, 1.0 );
// returns NaN
y = quantile( 0.0, NaN );
// returns NaNIf 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 NaNquantile.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 1Examples
var uniform = require( '@stdlib/random-array-uniform' );
var logEachMap = require( '@stdlib/console-log-each-map' );
var quantile = require( '@stdlib/stats-base-dists-bernoulli-quantile' );
var opts = {
'dtype': 'float64'
};
var r = uniform( 25, 0.0, 1.0, opts );
var p = uniform( r.length, 0.0, 1.0, opts );
logEachMap( 'r: %0.4f, p: %0.4f, Q(r;p): %0.4f', r, p, quantile );C APIs
Usage
#include "stdlib/stats/base/dists/bernoulli/quantile.h"stdlib_base_dists_bernoulli_quantile( r, p )
Evaluates the quantile of a Bernoulli distribution with input value r and success probability p.
double out = stdlib_base_dists_bernoulli_quantile( 0.8, 0.4 );
// returns 1The function accepts the following arguments:
- r:
[in] doubleinput value. - p:
[in] doublesuccess probability.
double stdlib_base_dists_bernoulli_quantile( const double r, const double p );Examples
#include "stdlib/stats/base/dists/bernoulli/quantile.h"
#include <stdlib.h>
#include <stdio.h>
static double random_uniform( const double min, const double max ) {
double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
return min + ( v * ( max - min ) );
}
int main( void ) {
double r;
double p;
double y;
int i;
for ( i = 0; i < 10; i++ ) {
r = random_uniform( 0.0, 1.0 );
p = random_uniform( 0.0, 1.0 );
y = stdlib_base_dists_bernoulli_quantile( r, p );
printf( "r: %lf, p: %lf, Q(r;p): %lf\n", r, p, y );
}
}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-2026. The Stdlib Authors.
