Skip to content

Latest commit

 

History

History

Mean

Chi distribution expected value.

The expected value for a chi random variable is

$$\mathbb{E}\left[ X \right] = \sqrt{2}\,\frac{\Gamma((k+1)/2)}{\Gamma(k/2)}$$

where k is the degrees of freedom.

Usage

var mean = require( '@stdlib/stats/base/dists/chi/mean' );

mean( k )

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

Examples

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 ) );
}

C APIs

Usage

#include "stdlib/stats/base/dists/chi/mean.h"

stdlib_base_dists_chi_mean( k )

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 );

Examples

#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 );
    }
}