@stdlib/stats-base-dists-wald-mean
v0.1.1
Published
Wald distribution expected value.
Downloads
11
Readme
Mean
Wald distribution expected value.
The expected value for a Wald random variable with mean μ and shape parameter λ > 0 is
Installation
npm install @stdlib/stats-base-dists-wald-meanUsage
var mean = require( '@stdlib/stats-base-dists-wald-mean' );mean( mu, lambda )
Returns the expected value for a Wald distribution with parameters mu (mean) and lambda (shape parameter).
var y = mean( 2.0, 1.0 );
// returns 2.0
y = mean( 0.0, 1.0 );
// returns NaN
y = mean( -1.0, 4.0 );
// returns NaNIf provided NaN as any argument, the function returns NaN.
var y = mean( NaN, 1.0 );
// returns NaN
y = mean( 0.0, NaN );
// returns NaNIf provided mu <= 0 or lambda <= 0, the function returns NaN.
var y = mean( 0.0, 0.0 );
// returns NaN
y = mean( 0.0, -1.0 );
// returns NaN
y = mean( -1.0, 0.0 );
// returns NaNExamples
var uniform = require( '@stdlib/random-array-uniform' );
var logEachMap = require( '@stdlib/console-log-each-map' );
var EPS = require( '@stdlib/constants-float64-eps' );
var mean = require( '@stdlib/stats-base-dists-wald-mean' );
var opts = {
'dtype': 'float64'
};
var mu = uniform( 10, EPS, 10.0, opts );
var lambda = uniform( 10, EPS, 20.0, opts );
logEachMap( 'µ: %0.4f, λ: %0.4f, E(X;µ,λ): %0.4f', mu, lambda, mean );C APIs
Usage
#include "stdlib/stats/base/dists/wald/mean.h"stdlib_base_dists_wald_mean( mu, lambda )
Returns the expected value for a Wald distribution with mean mu and shape parameter lambda.
double out = stdlib_base_dists_wald_mean( 2.0, 1.0 );
// returns 2.0The function accepts the following arguments:
- mu:
[in] doublemean. - lambda:
[in] doubleshape parameter.
double stdlib_base_dists_wald_mean( const double mu, const double lambda );Examples
#include "stdlib/stats/base/dists/wald/mean.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 lambda;
double mu;
double y;
int i;
for ( i = 0; i < 10; i++ ) {
mu = random_uniform( 0.1, 5.0 );
lambda = random_uniform( 0.1, 20.0 );
y = stdlib_base_dists_wald_mean( mu, lambda );
printf( "µ: %.4f, λ: %.4f, Mean(X;µ,λ): %.4f\n", mu, lambda, 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.
