@stdlib/stats-base-dists-geometric-mgf
v0.3.1
Published
Geometric distribution moment-generating function (MGF).
Downloads
458
Readme
Moment-Generating Function
Geometric distribution moment-generating function (MGF).
The moment-generating function for a geometric random variable is
where 0 < p <= 1 is the success probability. For t >= -ln(1-p), the MGF is not defined.
Installation
npm install @stdlib/stats-base-dists-geometric-mgfUsage
var mgf = require( '@stdlib/stats-base-dists-geometric-mgf' );mgf( t, p )
Evaluates the moment-generating function (MGF) of a geometric distribution with success probability p.
var y = mgf( 0.2, 0.5 );
// returns ~1.569
y = mgf( 0.4, 0.5 );
// returns ~2.936If provided NaN as any argument, the function returns NaN.
var y = mgf( NaN, 0.0 );
// returns NaN
y = mgf( 0.0, NaN );
// returns NaNIf provided a success probability p outside of the interval [0,1], the function returns NaN.
var y = mgf( -2.0, -1.0 );
// returns NaN
y = mgf( 0.2, 2.0 );
// returns NaNIf t >= -ln(1-p), the function returns NaN.
var y = mgf( 0.8, 0.5 );
// returns NaNmgf.factory( p )
Returns a function for evaluating the moment-generating function of a geometric distribution with parameter p (success probability).
var mymgf = mgf.factory( 0.8 );
var y = mymgf( -0.2 );
// returns ~0.783Examples
var uniform = require( '@stdlib/random-array-uniform' );
var logEachMap = require( '@stdlib/console-log-each-map' );
var mgf = require( '@stdlib/stats-base-dists-geometric-mgf' );
var opts = {
'dtype': 'float64'
};
var t = uniform( 10, 0.0, 1.0, opts );
var p = uniform( 10, 0.0, 1.0, opts );
logEachMap( 't: %0.4f, p: %0.4f, M_X(t;p): %0.4f', t, p, mgf );C APIs
Usage
#include "stdlib/stats/base/dists/geometric/mgf.h"stdlib_base_dists_geometric_mgf( t, p )
Evaluates the moment-generating function of a geometric distribution with parameter p (success probability).
double out = stdlib_base_dists_geometric_mgf( 0.2, 0.5 );
// returns ~1.569The function accepts the following arguments:
- t:
[in] doubleinput value. - p:
[in] doubleprobability of success.
double stdlib_base_dists_geometric_mgf( const double t, const double p );Examples
#include "stdlib/stats/base/dists/geometric/mgf.h"
#include "stdlib/math/base/special/ln.h"
#include <stdlib.h>
#include <stdio.h>
#include <math.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 t;
double p;
double y;
int i;
for ( i = 0; i < 25; i++ ) {
p = random_uniform( 0.0, 1.0 );
t = random_uniform( 0.0, ( -stdlib_base_ln( 1.0 - p ) ) );
y = stdlib_base_dists_geometric_mgf( t, p );
printf( "t: %lf, p: %lf, M_X(t;p): %lf\n", t, p, 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.
