@stdlib/stats-base-dists-erlang-quantile v0.2.2
Quantile Function
Erlang distribution quantile function.
The quantile function for an Erlang random variable is
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.
Installation
npm install @stdlib/stats-base-dists-erlang-quantileUsage
var quantile = require( '@stdlib/stats-base-dists-erlang-quantile' );quantile( p, k, lambda )
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.836If 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 NaNIf 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 NaNIf 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 NaNIf 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.0If provided lambda <= 0, the function returns NaN.
var y = quantile( 0.4, 1, -1.0 );
// returns NaNquantile.factory( k, lambda )
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.688Examples
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 ) );
}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.