Skip to content
Draft
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
63 changes: 13 additions & 50 deletions lib/node_modules/@stdlib/stats/chi2test/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@

var tape = require( 'tape' );
var array = require( '@stdlib/ndarray/array' );
var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' );
var contains = require( '@stdlib/assert/contains' );
var abs = require( '@stdlib/math/base/special/abs' );
var EPS = require( '@stdlib/constants/float64/eps' );
var chi2test = require( './../lib' );


Expand Down Expand Up @@ -143,8 +142,6 @@ tape( 'the function throws an error if provided a significance level `alpha` out

tape( 'the function correctly computes the chi-square independence test for a two-way contingency table', function test( t ) {
var expected;
var delta;
var tol;
var out;
var x;

Expand All @@ -153,22 +150,16 @@ tape( 'the function correctly computes the chi-square independence test for a tw

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

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

t.end();
});

tape( 'the function correctly computes the chi-square independence test for a two-way contingency table (supplied as an `ndarray`)', function test( t ) {
var expected;
var delta;
var tol;
var out;
var x;

Expand All @@ -177,22 +168,16 @@ tape( 'the function correctly computes the chi-square independence test for a tw

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

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

t.end();
});

tape( 'the function correctly computes the chi-square independence test for a two-way contingency table with two categories each (with continuity correction)', function test( t ) {
var expected;
var delta;
var tol;
var out;
var x;

Expand All @@ -201,22 +186,16 @@ tape( 'the function correctly computes the chi-square independence test for a tw

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

expected = corrected.statistic;
delta = abs( out.statistic - expected );
tol = 2.0 * EPS * abs( expected );
t.ok( delta <= tol, 'within tolerance. x: '+x+'. 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 chi-square independence test for a two-way contingency table with two categories each (without continuity correction)', function test( t ) {
var expected;
var delta;
var tol;
var out;
var x;

Expand All @@ -227,22 +206,16 @@ tape( 'the function correctly computes the chi-square independence test for a tw

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

expected = uncorrected.statistic;
delta = abs( out.statistic - expected );
tol = 2.0 * EPS * abs( expected );
t.ok( delta <= tol, 'within tolerance. x: '+x+'. 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 chi-square independence test for a two-way contingency table with more columns than rows', function test( t ) {
var expected;
var delta;
var tol;
var out;
var x;

Expand All @@ -251,22 +224,16 @@ tape( 'the function correctly computes the chi-square independence test for a tw

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

expected = moreCols.statistic;
delta = abs( out.statistic - expected );
tol = 2.0 * EPS * abs( expected );
t.ok( delta <= tol, 'within tolerance. x: '+x+'. 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 chi-square independence test for a two-way contingency table with more rows than columns', function test( t ) {
var expected;
var delta;
var tol;
var out;
var x;

Expand All @@ -275,14 +242,10 @@ tape( 'the function correctly computes the chi-square independence test for a tw

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

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

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