@stdlib/stats-base-dists-gamma-pdf
v0.3.1
Published
Gamma distribution probability density function (PDF).
Readme
Probability Density Function
Gamma distribution probability density function (PDF).
The probability density function (PDF) for a gamma random variable is
where α > 0 is the shape parameter and β > 0 is the rate parameter.
Installation
npm install @stdlib/stats-base-dists-gamma-pdfUsage
var pdf = require( '@stdlib/stats-base-dists-gamma-pdf' );pdf( x, alpha, beta )
Evaluates the probability density function (PDF) for a gamma distribution with parameters alpha (shape parameter) and beta (rate parameter).
var y = pdf( 2.0, 0.5, 1.0 );
// returns ~0.054
y = pdf( 0.1, 1.0, 1.0 );
// returns ~0.905
y = pdf( -1.0, 4.0, 2.0 );
// returns 0.0If provided NaN as any argument, the function returns NaN.
var y = pdf( NaN, 1.0, 1.0 );
// returns NaN
y = pdf( 0.0, NaN, 1.0 );
// returns NaN
y = pdf( 0.0, 1.0, NaN );
// returns NaNIf provided alpha < 0, the function returns NaN.
var y = pdf( 2.0, -0.5, 1.0 );
// returns NaNIf provided alpha = 0, the function evaluates the PDF of a degenerate distribution centered at 0.
var y = pdf( 2.0, 0.0, 2.0 );
// returns 0.0
y = pdf( 0.0, 0.0, 2.0 );
// returns InfinityIf provided beta <= 0, the function returns NaN.
var y = pdf( 2.0, 1.0, 0.0 );
// returns NaN
y = pdf( 2.0, 1.0, -1.0 );
// returns NaNpdf.factory( alpha, beta )
Returns a function for evaluating the PDF of a gamma distribution with parameters alpha (shape parameter) and beta (rate parameter).
var mypdf = pdf.factory( 3.0, 1.5 );
var y = mypdf( 1.0 );
// returns ~0.377
y = mypdf( 4.0 );
// returns ~0.067Examples
var uniform = require( '@stdlib/random-array-uniform' );
var logEachMap = require( '@stdlib/console-log-each-map' );
var EPS = require( '@stdlib/constants-float64-eps' );
var pdf = require( '@stdlib/stats-base-dists-gamma-pdf' );
var opts = {
'dtype': 'float64'
};
var x = uniform( 10, 0.0, 3.0, opts );
var alpha = uniform( 10, EPS, 5.0, opts );
var beta = uniform( 10, EPS, 5.0, opts );
logEachMap( 'x: %0.4f, α: %0.4f, β: %0.4f, f(x;α,β): %0.4f', x, alpha, beta, pdf );C APIs
Usage
#include "stdlib/stats/base/dists/gamma/pdf.h"stdlib_base_dists_gamma_pdf( x, alpha, beta )
Evaluates the probability density function (PDF) for a gamma distribution with parameters alpha (shape parameter) and beta (rate parameter).
double y = stdlib_base_dists_gamma_pdf( 2.0, 0.5, 1.0 );
// returns ~0.054The function accepts the following arguments:
- x:
[in] doubleinput value. - alpha:
[in] doubleshape parameter. - beta:
[in] doublerate parameter.
double stdlib_base_dists_gamma_pdf( const double x, const double alpha, const double beta );Examples
#include "stdlib/stats/base/dists/gamma/pdf.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 alpha;
double beta;
double x;
double y;
int i;
for ( i = 0; i < 10; i++ ) {
x = random_uniform( 0.0, 3.0 );
alpha = random_uniform( STDLIB_CONSTANT_FLOAT64_EPS, 5.0 );
beta = random_uniform( STDLIB_CONSTANT_FLOAT64_EPS, 5.0 );
y = stdlib_base_dists_gamma_pdf( x, alpha, beta );
printf( "x: %lf, α: %lf, β: %lf, f(x;α,β): %lf\n", x, alpha, beta, 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
Copyright
Copyright © 2016-2026. The Stdlib Authors.
