Skip to content

Latest commit

 

History

History
262 lines (168 loc) · 6.22 KB

File metadata and controls

262 lines (168 loc) · 6.22 KB

Probability Density Function

F distribution probability density function (PDF).

The probability density function (PDF) for a F random variable is

$$f(x; d_1,d_2) = \frac{\sqrt{\frac{(d_1\,x)^{d_1}\,\,d_2^{d_2}} {(d_1\,x+d_2)^{d_1+d_2}}}} {x\,\mathrm{B}\!\left(\frac{d_1}{2},\frac{d_2}{2}\right)}$$

where d1 is the numerator degrees of freedom and d2 is the denominator degrees of freedom and B is the Beta function.

Usage

var pdf = require( '@stdlib/stats/base/dists/f/pdf' );

pdf( x, d1, d2 )

Evaluates the probability density function (PDF) for a F distribution with parameters d1 (numerator degrees of freedom) and d2 (denominator degrees of freedom).

var y = pdf( 2.0, 0.5, 1.0 );
// returns ~0.057

y = pdf( 0.1, 1.0, 1.0 );
// returns ~0.915

y = pdf( -1.0, 4.0, 2.0 );
// returns 0.0

If provided NaN as any argument, the function returns NaN.

var y = pdf( NaN, 1.0, 1.0 );
// returns NaN

y = pdf( 0.0, NaN, 1.0 );
// returns NaN

y = pdf( 0.0, 1.0, NaN );
// returns NaN

If provided d1 <= 0, the function returns NaN.

var y = pdf( 2.0, 0.0, 1.0 );
// returns NaN

y = pdf( 2.0, -1.0, 1.0 );
// returns NaN

If provided d2 <= 0, the function returns NaN.

var y = pdf( 2.0, 1.0, 0.0 );
// returns NaN

y = pdf( 2.0, 1.0, -1.0 );
// returns NaN

pdf.factory( d1, d2 )

Returns a function for evaluating the PDF of an F distribution with parameters d1 (numerator degrees of freedom) and d2 (denominator degrees of freedom).

var mypdf = pdf.factory( 6.0, 7.0 );
var y = mypdf( 7.0 );
// returns ~0.004

y = mypdf( 2.0 );
// returns ~0.166

Examples

var uniform = require( '@stdlib/random/array/uniform' );
var logEachMap = require( '@stdlib/console/log-each-map' );
var pdf = require( '@stdlib/stats/base/dists/f/pdf' );

var opts = {
    'dtype': 'float64'
};
var x = uniform( 10, 0.0, 4.0, opts );
var d1 = uniform( 10, 0.0, 10.0, opts );
var d2 = uniform( 10, 0.0, 10.0, opts );

logEachMap( 'x: %0.4f, d1: %0.4f, d2: %0.4f, f(x;d1,d2): %0.4f', x, d1, d2, pdf );

C APIs

Usage

#include "stdlib/stats/base/dists/f/pdf.h"

stdlib_base_dists_f_pdf( x, d1, d2 )

Evaluates the probability density function (PDF) for an F distribution with numerator degrees of freedom d1 and denominator degrees of freedom d2.

double out = stdlib_base_dists_f_pdf( 2.0, 1.0, 1.0 );
// returns ~0.127

The function accepts the following arguments:

  • x: [in] double input value.
  • d1: [in] double numerator degrees of freedom.
  • d2: [in] double denominator degrees of freedom.
double stdlib_base_dists_f_pdf( const double x, const double d1, const double d2 );

Examples

#include "stdlib/stats/base/dists/f/pdf.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 d1;
    double d2;
    double x;
    double y;
    int i;

    for ( i = 0; i < 10; i++ ) {
        x = random_uniform( 0.0, 10.0 );
        d1 = random_uniform( 1.0, 10.0 );
        d2 = random_uniform( 1.0, 10.0 );
        y = stdlib_base_dists_f_pdf( x, d1, d2 );
        printf( "x: %.4f, d1: %.4f, d2: %.4f, f(x;d1,d2): %.4f\n", x, d1, d2, y );
    }
}