diff --git a/lib/node_modules/@stdlib/stats/base/dists/negative-binomial/pmf/README.md b/lib/node_modules/@stdlib/stats/base/dists/negative-binomial/pmf/README.md index ab5f10daeeca..1daf95f47cd2 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/negative-binomial/pmf/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/negative-binomial/pmf/README.md @@ -39,7 +39,7 @@ f(x; r, p) = P(X = x; r,p) = \binom{k+r-1}{x} p^r(1-p)^x \quad\text{for }x = 0, -where `r > 0` is the number of successes until experiment is stopped and `0 < p <= 1` is the success probability. The random variable `X` denotes the number of failures until the `r` success is reached. +where `r > 0` is the number of successes until experiment is stopped and `0 < p <= 1` is the success probability. The random variable `X` denotes the number of failures until the `r` success is reached. @@ -161,6 +161,102 @@ for ( i = 0; i < 10; i++ ) { + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/stats/base/dists/negative-binomial/pmf.h" +``` + +#### stdlib_base_dists_negative_binomial_mode( x, r, p ) + +Evaluates the probability mass function (PMF) for a negative binomial distribution with number of successes until experiment is stopped `r` and success probability `p`. + +```c + double y = stdlib_base_dists_negative_binomial_mode( 5.0, 20.0, 0.8 ); +// returns ~0.157 +``` + +The function accepts the following arguments: + +- **x**: `[in] double` input value. +- **r**: `[in] double` number of failures until experiment is stopped . +- **p**: `[in] double` success probability . + +```c +double stdlib_base_dists_negative_binomial_mode( const double x, const double r, const double p ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/stats/base/dists/negative-binomial/pmf.h" +#include "stdlib/math/base/special/round.h" +#include "stdlib/constants/float64/eps" +#include +#include + +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 x; + double r; + double p; + double y; + int i; + + for ( i = 0; i < 10; i++ ) { + x = stdlib_base_round( random_uniform( 0.0, 30.0 ) ); + r = random_uniform( 0.0, 50.0 ); + p = random_uniform( 0.0, 1.0 ); + y = stdlib_base_dists_negative_binomial_pmf( x, r, p ); + printf("x: %f, r: %f, p: %.4f, P(X=x;r,p): %.4f\n", x, r, p, y); + } +} +``` + +
+ + +