@stdlib/stats-base-dists-gamma-logcdf
v0.3.1
Published
Gamma distribution logarithm of cumulative distribution function (CDF).
Readme
Logarithm of Cumulative Distribution Function
Gamma distribution logarithm of cumulative distribution function (CDF).
The cumulative distribution function for a gamma random variable is
where alpha is the shape parameter and beta is the rate parameter of the distribution. gamma is the lower incomplete gamma function.
Installation
npm install @stdlib/stats-base-dists-gamma-logcdfUsage
var logcdf = require( '@stdlib/stats-base-dists-gamma-logcdf' );logcdf( x, alpha, beta )
Evaluates the natural logarithm of the cumulative distribution function (CDF) for a gamma distribution with parameters alpha (shape parameter) and beta (rate parameter).
var y = logcdf( 2.0, 0.5, 1.0 );
// returns ~-0.047
y = logcdf( 0.1, 1.0, 1.0 );
// returns ~-2.352
y = logcdf( -1.0, 4.0, 2.0 );
// returns -InfinityIf provided NaN as any argument, the function returns NaN.
var y = logcdf( NaN, 1.0, 1.0 );
// returns NaN
y = logcdf( 0.0, NaN, 1.0 );
// returns NaN
y = logcdf( 0.0, 1.0, NaN );
// returns NaNIf provided alpha < 0, the function returns NaN.
var y = logcdf( 2.0, -0.5, 1.0 );
// returns NaNIf provided alpha = 0, the function evaluates the logarithm of the CDF for a degenerate distribution centered at 0.
var y = logcdf( 2.0, 0.0, 2.0 );
// returns 0.0
y = logcdf( -2.0, 0.0, 2.0 );
// returns -Infinity
y = logcdf( 0.0, 0.0, 2.0 );
// returns 0.0If provided beta <= 0, the function returns NaN.
var y = logcdf( 2.0, 1.0, 0.0 );
// returns NaN
y = logcdf( 2.0, 1.0, -1.0 );
// returns NaNlogcdf.factory( alpha, beta )
Returns a function for evaluating the natural logarithm of the CDF for a gamma distribution with parameters alpha (shape parameter) and beta (rate parameter).
var mylogcdf = logcdf.factory( 3.0, 1.5 );
var y = mylogcdf( 1.0 );
// returns ~-1.655
y = mylogcdf( 4.0 );
// returns ~-0.064C APIs
Usage
#include "stdlib/stats/base/dists/gamma/logcdf.h"stdlib_base_dists_gamma_logcdf( x, alpha, beta )
Evaluates the natural logarithm of the cumulative distribution function (CDF) for a gamma distribution with shape parameter alpha and rate parameter beta.
double out = stdlib_base_dists_gamma_logcdf( 2.0, 0.5, 1.0 );
// returns ~-0.047
out = stdlib_base_dists_gamma_logcdf( 0.1, 1.0, 1.0 );
// returns ~-2.352The function accepts the following arguments:
- x:
[in] doubleinput value. - alpha:
[in] doubleshape parameter. - beta:
[in] doublerate parameter.
double stdlib_base_dists_gamma_logcdf( const double x, const double alpha, const double beta );Examples
#include "stdlib/stats/base/dists/gamma/logcdf.h"
#include <stdlib.h>
#include <stdio.h>
static double random_uniform( double a, double b ) {
double r = ( (double)rand() / ( (double)RAND_MAX + 1.0 ) );
return a + ( r * ( b - a ) );
}
int main( void ) {
double alpha;
double beta;
double x;
double y;
int i;
for ( i = 0; i < 25; i++ ) {
x = random_uniform( 0.0, 2.0 );
alpha = random_uniform( 1.0, 10.0 );
beta = random_uniform( 1.0, 10.0 );
y = stdlib_base_dists_gamma_logcdf( x, alpha, beta );
printf( "x: %lf, α: %lf, β: %lf, ln(F(x;α,β)): %lf\n", x, alpha, beta, y );
}
}Examples
var uniform = require( '@stdlib/random-array-uniform' );
var logEachMap = require( '@stdlib/console-log-each-map' );
var logcdf = require( '@stdlib/stats-base-dists-gamma-logcdf' );
var opts = {
'dtype': 'float64'
};
var x = uniform( 10, 0.0, 3.0, opts );
var alpha = uniform( 10, 0.0, 5.0, opts );
var beta = uniform( 10, 0.0, 5.0, opts );
logEachMap( 'x: %0.4f, α: %0.4f, β: %0.4f, ln(f(x;α,β)): %0.4f', x, alpha, beta, logcdf );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.
