Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ function factory( d1, d2 ) {
return 1.0;
}
if ( d1 * x > d2 ) {
return betainc( (d1*x)/(d2+(d1*x)), d1/2.0, d2/2.0, true, false );
return betainc( d2/(d2+(d1*x)), d2/2.0, d1/2.0, true, true );
}
return betainc( d2/(d2+(d1*x)), d2/2.0, d1/2.0, true, true );
return betainc( (d1*x)/(d2+(d1*x)), d1/2.0, d2/2.0, true, false );
}
}

Expand Down
14 changes: 12 additions & 2 deletions lib/node_modules/@stdlib/stats/base/dists/f/cdf/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ var PINF = require( '@stdlib/constants/float64/pinf' );
/**
* Evaluates the cumulative distribution function (CDF) for an F distribution with numerator degrees of freedom `d1` and denominator degrees of freedom `d2` at a value `x`.
*
* ## Method
*
* The CDF is the regularized incomplete beta function evaluated at \\(z = d_1 x / (d_2 + d_1 x)\\):
*
* ```tex
* F(x;d_1,d_2) = I_{z}\left(\tfrac{d_1}{2}, \tfrac{d_2}{2}\right) = 1 - I_{1-z}\left(\tfrac{d_2}{2}, \tfrac{d_1}{2}\right)
* ```
*
* To avoid rounding an argument close to one, the function passes \\(z\\) to the lower tail when \\(z \leq 1/2\\) (i.e., \\(d_1 x \leq d_2\\)), and \\(1-z = d_2/(d_2 + d_1 x)\\) to the upper tail otherwise.
*
* @param {number} x - input value
* @param {PositiveNumber} d1 - numerator degrees of freedom
* @param {PositiveNumber} d2 - denominator degrees of freedom
Expand Down Expand Up @@ -92,9 +102,9 @@ function cdf( x, d1, d2 ) {
return 1.0;
}
if ( d1 * x > d2 ) {
return betainc( (d1*x)/(d2+(d1*x)), d1/2.0, d2 /2.0, true, false );
return betainc( d2/(d2+(d1*x)), d2/2.0, d1/2.0, true, true );
}
return betainc( d2/(d2+(d1*x)), d2/2.0, d1/2.0, true, true );
return betainc( (d1*x)/(d2+(d1*x)), d1/2.0, d2/2.0, true, false );
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,8 @@ x = rand( 1000 ) .* 20.0;
d2 = ( rand( 1000 ) .* 20.0 ) .+ 10.0;
d2 = ( rand( 1000 ) .* 20.0 ) .+ 10.0;
gen( x, d1, d2, "both_large.json" );

x = exp10.( rand( 1000 ) .* -20.0 );
d1 = ( rand( 1000 ) .* 20.0 ) .+ 0.5;
d2 = ( rand( 1000 ) .* 20.0 ) .+ 0.5;
gen( x, d1, d2, "small_x.json" );

Large diffs are not rendered by default.

26 changes: 23 additions & 3 deletions lib/node_modules/@stdlib/stats/base/dists/f/cdf/test/test.cdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ var cdf = require( './../lib' );
var largeD1 = require( './fixtures/julia/large_d1.json' );
var largeD2 = require( './fixtures/julia/large_d2.json' );
var bothLarge = require( './fixtures/julia/both_large.json' );
var smallX = require( './fixtures/julia/small_x.json' );


// TESTS //
Expand Down Expand Up @@ -127,7 +128,7 @@ tape( 'the function evaluates the cdf for `x` given large `d1` and `d2`', functi
d2 = bothLarge.d2;
for ( i = 0; i < x.length; i++ ) {
y = cdf( x[i], d1[i], d2[i] );
t.strictEqual( isAlmostSameValue( y, expected[ i ], 58 ), true, 'returns expected value' );
t.strictEqual( isAlmostSameValue( y, expected[ i ], 10 ), true, 'returns expected value' );
}
t.end();
});
Expand All @@ -146,7 +147,7 @@ tape( 'the function evaluates the cdf for `x` given large parameter `d1`', funct
d2 = largeD1.d2;
for ( i = 0; i < x.length; i++ ) {
y = cdf( x[i], d1[i], d2[i] );
t.strictEqual( isAlmostSameValue( y, expected[ i ], 542 ), true, 'returns expected value' );
t.strictEqual( isAlmostSameValue( y, expected[ i ], 17 ), true, 'returns expected value' );
}
t.end();
});
Expand All @@ -165,7 +166,26 @@ tape( 'the function evaluates the cdf for `x` given large scale parameter `d2`',
d2 = largeD2.d2;
for ( i = 0; i < x.length; i++ ) {
y = cdf( x[i], d1[i], d2[i] );
t.strictEqual( isAlmostSameValue( y, expected[ i ], 171 ), true, 'returns expected value' );
t.strictEqual( isAlmostSameValue( y, expected[ i ], 16 ), true, 'returns expected value' );
}
t.end();
});

tape( 'the function evaluates the cdf for small `x`', function test( t ) {
var expected;
var d1;
var d2;
var x;
var y;
var i;

expected = smallX.expected;
x = smallX.x;
d1 = smallX.d1;
d2 = smallX.d2;
for ( i = 0; i < x.length; i++ ) {
y = cdf( x[i], d1[i], d2[i] );
t.strictEqual( isAlmostSameValue( y, expected[ i ], 520 ), true, 'returns expected value' );
}
t.end();
});
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ var factory = require( './../lib/factory.js' );
var largeD1 = require( './fixtures/julia/large_d1.json' );
var largeD2 = require( './fixtures/julia/large_d2.json' );
var bothLarge = require( './fixtures/julia/both_large.json' );
var smallX = require( './fixtures/julia/small_x.json' );


// TESTS //
Expand Down Expand Up @@ -178,7 +179,7 @@ tape( 'the created function evaluates the cdf for `x` given large `d1` and `d2`'
for ( i = 0; i < x.length; i++ ) {
cdf = factory( d1[i], d2[i] );
y = cdf( x[i] );
t.strictEqual( isAlmostSameValue( y, expected[ i ], 58 ), true, 'returns expected value' );
t.strictEqual( isAlmostSameValue( y, expected[ i ], 10 ), true, 'returns expected value' );
}
t.end();
});
Expand All @@ -199,7 +200,7 @@ tape( 'the created function evaluates the cdf for `x` given large parameter `d1`
for ( i = 0; i < x.length; i++ ) {
cdf = factory( d1[i], d2[i] );
y = cdf( x[i] );
t.strictEqual( isAlmostSameValue( y, expected[ i ], 542 ), true, 'returns expected value' );
t.strictEqual( isAlmostSameValue( y, expected[ i ], 17 ), true, 'returns expected value' );
}
t.end();
});
Expand All @@ -220,7 +221,28 @@ tape( 'the created function evaluates the cdf for `x` given large parameter `d2`
for ( i = 0; i < x.length; i++ ) {
cdf = factory( d1[i], d2[i] );
y = cdf( x[i] );
t.strictEqual( isAlmostSameValue( y, expected[ i ], 171 ), true, 'returns expected value' );
t.strictEqual( isAlmostSameValue( y, expected[ i ], 16 ), true, 'returns expected value' );
}
t.end();
});

tape( 'the created function evaluates the cdf for small `x`', function test( t ) {
var expected;
var cdf;
var d1;
var d2;
var i;
var x;
var y;

expected = smallX.expected;
x = smallX.x;
d1 = smallX.d1;
d2 = smallX.d2;
for ( i = 0; i < x.length; i++ ) {
cdf = factory( d1[i], d2[i] );
y = cdf( x[i] );
t.strictEqual( isAlmostSameValue( y, expected[ i ], 520 ), true, 'returns expected value' );
}
t.end();
});
Loading