@stdlib/stats-base-dists-chisquare-mgf
v0.2.3
Published
Chi-squared distribution moment-generating function (MGF).
Downloads
26,704
Readme
Moment-Generating Function
Chi-squared distribution moment-generating function (MGF).
The moment-generating function for a chi-squared random variable is
where k is the degrees of freedom.
Installation
npm install @stdlib/stats-base-dists-chisquare-mgfUsage
var mgf = require( '@stdlib/stats-base-dists-chisquare-mgf' );mgf( t, k )
Evaluates the moment-generating function (MGF) for a chi-squared distribution with degrees of freedom k.
var y = mgf( 0.4, 2 );
// returns ~5.0
y = mgf( -1.0, 5.0 );
// returns ~0.0642
y = mgf( 0.0, 10.0 );
// returns 1.0If provided NaN as any argument, the function returns NaN.
var y = mgf( NaN, 1.0 );
// returns NaN
y = mgf( 0.0, NaN );
// returns NaNIf provided t >= 0.5, the function returns NaN.
var y = mgf( 0.8, 1.0 );
// returns NaNIf provided k < 0, the function returns NaN.
var y = mgf( 2.0, -2.0 );
// returns NaNmgf.factory( k )
Returns a function for evaluating the moment-generating function (MGF) for a chi-squared distribution with degrees of freedom k.
var mymgf = mgf.factory( 1.0 );
var y = mymgf( 0.2 );
// returns ~1.291
y = mymgf( 0.4 );
// returns ~2.236Examples
var uniform = require( '@stdlib/random-array-uniform' );
var logEachMap = require( '@stdlib/console-log-each-map' );
var mgf = require( '@stdlib/stats-base-dists-chisquare-mgf' );
var opts = {
'dtype': 'float64'
};
var t = uniform( 10, 0.0, 0.5, opts );
var k = uniform( 10, 0.0, 10.0, opts );
logEachMap( 'x: %0.4f, k: %0.4f, M_X(t;k): %0.4f', t, k, mgf );C APIs
Usage
#include "stdlib/stats/base/dists/chisquare/mgf.h"stdlib_base_dists_chisquare_mgf( t, k )
Evaluates the moment-generating function (MGF) for a chi-squared distribution with degrees of freedom k at a value t.
double out = stdlib_base_dists_chisquare_mgf( 0.4, 2.0 );
// returns ~5.0The function accepts the following arguments:
- t:
[in] doubleinput value. - k:
[in] doubledegrees of freedom (must be nonnegative).
double stdlib_base_dists_chisquare_mgf( const double t, const double k );Examples
#include "stdlib/stats/base/dists/chisquare/mgf.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 result;
double t;
double k;
int i;
for ( i = 0; i < 10; i++ ) {
t = random_uniform( -0.5, 0.4 );
k = random_uniform( 0.1, 10.0 );
result = stdlib_base_dists_chisquare_mgf( t, k );
printf( "t: %lf, k: %lf, M_X(t;k): %lf \n", t, k, result );
}
}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.
