@stdlib/stats-base-dists-normal-quantile
v0.3.1
Published
Normal distribution quantile function.
Readme
Quantile Function
Normal distribution quantile function.
The quantile function for a normal random variable is
for 0 <= p <= 1, where µ is the mean and σ is the standard deviation.
Installation
npm install @stdlib/stats-base-dists-normal-quantileUsage
var quantile = require( '@stdlib/stats-base-dists-normal-quantile' );quantile( p, mu, sigma )
Evaluates the quantile function for a normal distribution with parameters mu (mean) and sigma (standard deviation).
var y = quantile( 0.5, 0.0, 1.0 );
// returns 0.0
y = quantile( 0.2, 4.0, 2.0 );
// returns ~2.317If provided a probability p outside the interval [0,1], the function returns NaN.
var y = quantile( 1.9, 0.0, 1.0 );
// returns NaN
y = quantile( -0.1, 0.0, 1.0 );
// returns NaNIf provided NaN as any argument, the function returns NaN.
var y = quantile( NaN, 0.0, 1.0 );
// returns NaN
y = quantile( 0.0, NaN, 1.0 );
// returns NaN
y = quantile( 0.0, 0.0, NaN );
// returns NaNIf provided sigma < 0, the function returns NaN.
var y = quantile( 0.4, 0.0, -1.0 );
// returns NaNIf provided sigma = 0, the function evaluates the quantile function of a degenerate distribution centered at mu.
var y = quantile( 0.3, 8.0, 0.0 );
// returns 8.0
y = quantile( 0.9, 8.0, 0.0 );
// returns 8.0quantile.factory( mu, sigma )
Returns a function for evaluating the quantile function of a normal distribution with parameters mu and sigma.
var myquantile = quantile.factory( 10.0, 2.0 );
var y = myquantile( 0.2 );
// returns ~8.317
y = myquantile( 0.8 );
// returns ~11.683Examples
var uniform = require( '@stdlib/random-array-uniform' );
var logEachMap = require( '@stdlib/console-log-each-map' );
var quantile = require( '@stdlib/stats-base-dists-normal-quantile' );
var opts = {
'dtype': 'float64'
};
var sigma = uniform( 10, 0.0, 20.0, opts );
var mu = uniform( 10, -5.0, 5.0, opts );
var p = uniform( 10, 0.0, 1.0, opts );
logEachMap( 'p: %0.4f, µ: %0.4f, σ: %0.4f, Q(p;µ,σ): %0.4f', p, mu, sigma, quantile );C APIs
Usage
#include "stdlib/stats/base/dists/normal/quantile.h"stdlib_base_dists_normal_quantile( p, mu, sigma )
Evaluates the quantile function for a normal distribution with parameters mu (mean) and sigma (standard deviation).
double y = stdlib_base_dists_normal_quantile( 0.8, 0.0, 1.0 );
// returns ~0.842The function accepts the following arguments:
- p:
[in] doubleprobability. - mu:
[in] doublemean. - sigma:
[in] doublestandard deviation.
double stdlib_base_dists_normal_quantile( const double p, const double mu, const double sigma );Examples
#include "stdlib/stats/base/dists/normal/quantile.h"
#include "stdlib/constants/float64/eps.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 sigma;
double mu;
double p;
double y;
int i;
for ( i = 0; i < 10; i++ ) {
p = random_uniform( 0.0, 1.0 );
mu = random_uniform( -5.0, 5.0 );
sigma = random_uniform( STDLIB_CONSTANT_FLOAT64_EPS, 20.0 );
y = stdlib_base_dists_normal_quantile( p, mu, sigma );
printf( "p:%.4f, µ: %.4f, σ: %.4f, Q(p;µ,σ): %.4f\n", p, mu, sigma, 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.
