Chi distribution expected value.
The expected value for a chi random variable is
where k
is the degrees of freedom.
var mean = require( '@stdlib/stats/base/dists/chi/mean' );
Returns the expected value of a chi distribution with degrees of freedom k
.
var v = mean( 9.0 );
// returns ~2.918
v = mean( 0.5 );
// returns ~0.478
If provided k < 0
, the function returns NaN
.
var v = mean( -1.0 );
// returns NaN
var randu = require( '@stdlib/random/base/randu' );
var round = require( '@stdlib/math/base/special/round' );
var mean = require( '@stdlib/stats/base/dists/chi/mean' );
var k;
var v;
var i;
for ( i = 0; i < 10; i++ ) {
k = randu() * 20.0;
v = mean( k );
console.log( 'k: %d, E(X,k): %d', k.toFixed( 4 ), v.toFixed( 4 ) );
}
#include "stdlib/stats/base/dists/chi/mean.h"
Returns the expected value of a chi distribution with degrees of freedom k
.
double out = stdlib_base_dists_chi_mean( 2.0 );
// returns ~1.253
The function accepts the following arguments:
- k:
[in] double
degrees of freedom.
double stdlib_base_dists_chi_mean( const double k );
#include "stdlib/stats/base/dists/chi/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 k;
double y;
int i;
for ( i = 0; i < 25; i++ ) {
k = random_uniform( 1.0, 10.0 );
y = stdlib_base_dists_chi_mean( k );
printf( "k: %lf, E(X,k): %lf\n", k, y );
}
}