Erlang distribution quantile function.
APACHE-2.0 License
Erlang distribution quantile function.
The quantile function for an Erlang random variable is
Q(p;k,\lambda) = \frac{1}{\lambda} P^{-1}\left( p, k \right )
for 0 <= p < 1
, where k
is the shape parameter and lambda
is the rate parameter of the distribution. P^{-1}
is the inverse of the lower regularized incomplete gamma function. The Erlang distribution is a special case of the gamma distribution, as k
is constrained to the natural numbers.
npm install @stdlib/stats-base-dists-erlang-quantile
Alternatively,
script
tag without installation and bundlers, use the ES Module available on the esm
branch (see README).deno
branch (see README for usage intructions).umd
branch (see README).The branches.md file summarizes the available branches and displays a diagram illustrating their relationships.
To view installation and usage instructions specific to each branch build, be sure to explicitly navigate to the respective README files on each branch, as linked to above.
var quantile = require( '@stdlib/stats-base-dists-erlang-quantile' );
Evaluates the quantile function for an Erlang distribution with parameters k
(shape parameter) and lambda
(rate parameter).
var y = quantile( 0.8, 2, 1.0 );
// returns ~2.994
y = quantile( 0.5, 4, 2.0 );
// returns ~1.836
If provided a probability p
outside the interval [0,1]
, the function returns NaN
.
var y = quantile( 1.9, 1, 1.0 );
// returns NaN
y = quantile( -0.1, 1, 1.0 );
// returns NaN
If provided NaN
as any argument, the function returns NaN
.
var y = quantile( NaN, 1, 1.0 );
// returns NaN
y = quantile( 0.0, NaN, 1.0 );
// returns NaN
y = quantile( 0.0, 1, NaN );
// returns NaN
If provided a k
which is not a nonnegative integer, the function returns NaN
.
var y = quantile( 0.4, -1, 1.0 );
// returns NaN
y = quantile( 0.4, 2.5, 1.0 );
// returns NaN
If provided k = 0
, the function evaluates the quantile function of a degenerate distribution centered at 0
.
var y = quantile( 0.3, 0, 2.0 );
// returns 0.0
y = quantile( 0.9, 0, 2.0 );
// returns 0.0
If provided lambda <= 0
, the function returns NaN
.
var y = quantile( 0.4, 1, -1.0 );
// returns NaN
Returns a function for evaluating the quantile function of an Erlang distribution with parameters k
(shape parameter) and lambda
(rate parameter).
var myquantile = quantile.factory( 2, 2.0 );
var y = myquantile( 0.8 );
// returns ~1.497
y = myquantile( 0.4 );
// returns ~0.688
var randu = require( '@stdlib/random-base-randu' );
var round = require( '@stdlib/math-base-special-round' );
var quantile = require( '@stdlib/stats-base-dists-erlang-quantile' );
var lambda;
var k;
var p;
var y;
var i;
for ( i = 0; i < 20; i++ ) {
p = randu();
k = round( randu() * 10.0 );
lambda = randu() * 5.0;
y = quantile( p, k, lambda );
console.log( 'p: %d, k: %d, λ: %d, Q(p;k,λ): %d', p.toFixed( 4 ), k, lambda.toFixed( 4 ), y.toFixed( 4 ) );
}
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.
See LICENSE.
Copyright © 2016-2024. The Stdlib Authors.