Skip to content
Merged
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
59 changes: 13 additions & 46 deletions lib/node_modules/@stdlib/stats/kstest/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@
// MODULES //

var tape = require( 'tape' );
var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' );
var contains = require( '@stdlib/assert/contains' );
var uniform = require( '@stdlib/random/base/uniform' ).factory;
var uniformCDF = require( '@stdlib/stats/base/dists/uniform/cdf' );
var abs = require( '@stdlib/math/base/special/abs' );
var Float64Array = require( '@stdlib/array/float64' );
var EPS = require( '@stdlib/constants/float64/eps' );
var zeros = require( '@stdlib/array/base/zeros' );
var kstest = require( './../lib' );

Expand Down Expand Up @@ -183,46 +182,34 @@ tape( 'the function throws an error if the `alpha` option is a numeric value out

tape( 'the function correctly computes the two-sided Kolmogorov-Smirnov test', function test( t ) {
var expected;
var delta;
var out;
var tol;

// Choosing the CDF via a string...
out = kstest( data, 'uniform', 0.0, 1.0 );

// Tested against R:
expected = twosided.pvalue;
delta = abs( out.pValue - expected );
tol = 20.0 * EPS * abs( expected );
t.ok( delta <= tol, 'within tolerance. p-value: '+out.pValue+'. E: '+expected+' Δ: '+delta+'. tol: '+tol );
t.strictEqual( isAlmostSameValue( out.pValue, expected, 0 ), true, 'returns expected value' );

expected = twosided.statistic;
delta = abs( out.statistic - expected );
tol = 5.0 * EPS * abs( expected );
t.ok( delta <= tol, 'within tolerance. test statistic: '+out.statistic+'. E: '+expected+' Δ: '+delta+'. tol: '+tol );
t.strictEqual( isAlmostSameValue( out.statistic, expected, 0 ), true, 'returns expected value' );

// Directly passing the CDF...
out = kstest( data, uniformCDF, 0.0, 1.0 );

// Tested against R:
expected = twosided.pvalue;
delta = abs( out.pValue - expected );
tol = 20.0 * EPS * abs( expected );
t.ok( delta <= tol, 'within tolerance. p-value: '+out.pValue+'. E: '+expected+' Δ: '+delta+'. tol: '+tol );
t.strictEqual( isAlmostSameValue( out.pValue, expected, 0 ), true, 'returns expected value' );

expected = twosided.statistic;
delta = abs( out.statistic - expected );
tol = 5.0 * EPS * abs( expected );
t.ok( delta <= tol, 'within tolerance. test statistic: '+out.statistic+'. E: '+expected+' Δ: '+delta+'. tol: '+tol );
t.strictEqual( isAlmostSameValue( out.statistic, expected, 0 ), true, 'returns expected value' );

t.end();
});

tape( 'the function correctly computes the two-sided Kolmogorov-Smirnov test for an already sorted array', function test( t ) {
var expected;
var delta;
var out;
var tol;
var x;

x = [ 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.8, 0.9 ];
Expand All @@ -232,23 +219,17 @@ tape( 'the function correctly computes the two-sided Kolmogorov-Smirnov test for

// Tested against R:
expected = 0.99963712;
delta = abs( out.pValue - expected );
tol = EPS * abs( expected );
t.ok( delta <= tol, 'within tolerance. p-value: '+out.pValue+'. E: '+expected+' Δ: '+delta+'. tol: '+tol );
t.strictEqual( isAlmostSameValue( out.pValue, expected, 0 ), true, 'returns expected value' );

expected = 0.10000000000000009;
delta = abs( out.statistic - expected );
tol = EPS * abs( expected );
t.ok( delta <= tol, 'within tolerance. test statistic: '+out.statistic+'. E: '+expected+' Δ: '+delta+'. tol: '+tol );
t.strictEqual( isAlmostSameValue( out.statistic, expected, 0 ), true, 'returns expected value' );

t.end();
});

tape( 'the function correctly computes the two-sided Kolmogorov-Smirnov test for an already sorted typed array', function test( t ) {
var expected;
var delta;
var out;
var tol;
var x;

x = new Float64Array( [ 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.8, 0.9 ] ); // eslint-disable-line max-len
Expand All @@ -258,53 +239,39 @@ tape( 'the function correctly computes the two-sided Kolmogorov-Smirnov test for

// Tested against R:
expected = 0.99963712;
delta = abs( out.pValue - expected );
tol = EPS * abs( expected );
t.ok( delta <= tol, 'within tolerance. p-value: '+out.pValue+'. E: '+expected+' Δ: '+delta+'. tol: '+tol );
t.strictEqual( isAlmostSameValue( out.pValue, expected, 0 ), true, 'returns expected value' );

expected = 0.10000000000000009;
delta = abs( out.statistic - expected );
tol = EPS * abs( expected );
t.ok( delta <= tol, 'within tolerance. test statistic: '+out.statistic+'. E: '+expected+' Δ: '+delta+'. tol: '+tol );
t.strictEqual( isAlmostSameValue( out.statistic, expected, 0 ), true, 'returns expected value' );

t.end();
});

tape( 'the function correctly computes a one-sided Kolmogorov-Smirnov test', function test( t ) {
var expected;
var delta;
var out;
var tol;

out = kstest( data, 'uniform', 0.0, 1.0, {
'alternative': 'less'
});

// Tested against R:
expected = less.pvalue;
delta = abs( out.pValue - expected );
tol = 60.0 * EPS * abs( expected );
t.ok( delta <= tol, 'within tolerance. p-value: '+out.pValue+'. E: '+expected+' Δ: '+delta+'. tol: '+tol );
t.strictEqual( isAlmostSameValue( out.pValue, expected, 2 ), true, 'returns expected value' );

expected = less.statistic;
delta = abs( out.statistic - expected );
tol = 20.0 * EPS * abs( expected );
t.ok( delta <= tol, 'within tolerance. test statistic: '+out.statistic+'. E: '+expected+' Δ: '+delta+'. tol: '+tol );
t.strictEqual( isAlmostSameValue( out.statistic, expected, 0 ), true, 'returns expected value' );

out = kstest( data, 'uniform', 0.0, 1.0, {
'alternative': 'greater'
});

// Tested against R:
expected = greater.pvalue;
delta = abs( out.pValue - expected );
tol = 40.0 * EPS * abs( expected );
t.ok( delta <= tol, 'within tolerance. p-value: '+out.pValue+'. E: '+expected+' Δ: '+delta+'. tol: '+tol );
t.strictEqual( isAlmostSameValue( out.pValue, expected, 1 ), true, 'returns expected value' );

expected = greater.statistic;
delta = abs( out.statistic - expected );
tol = 80.0 * EPS * abs( expected );
t.ok( delta <= tol, 'within tolerance. test statistic: '+out.statistic+'. E: '+expected+' Δ: '+delta+'. tol: '+tol );
t.strictEqual( isAlmostSameValue( out.statistic, expected, 0 ), true, 'returns expected value' );

t.end();
});
Expand Down
Loading