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
45 changes: 10 additions & 35 deletions lib/node_modules/@stdlib/stats/pcorrtest/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@
// MODULES //

var tape = require( 'tape' );
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 pcorrtest = require( './../lib' );


Expand Down Expand Up @@ -177,9 +176,7 @@ tape( 'the function throws an error if provided arrays with less than four obser

tape( 'the function by default performs a two-sided t-test for the Pearson correlation between paired samples', function test( t ) {
var expected;
var delta;
var out;
var tol;
var i;
var x;
var y;
Expand All @@ -190,29 +187,21 @@ tape( 'the function by default performs a two-sided t-test for the Pearson corre

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

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

expected = twosided.ci;
for ( i = 0; i < 2; i++ ) {
delta = abs( out.ci[ i ] - expected[ i ]);
tol = 20.0 * EPS * abs( expected[ i ] );
t.ok( delta <= tol, 'within tolerance. CI['+i+']: '+out.ci[ i ]+'. E: '+expected[ i ]+' Δ: '+delta+'. tol: '+tol );
t.strictEqual( isAlmostSameValue( out.ci[ i ], expected[ i ], 1 ), true, 'returns expected value' );
}
t.end();
});

tape( 'the function performs a one-sided t-test for the Pearson correlation between paired samples (when alternative is `less`)', function test( t ) {
var expected;
var delta;
var out;
var tol;
var i;
var x;
var y;
Expand All @@ -225,29 +214,21 @@ tape( 'the function performs a one-sided t-test for the Pearson correlation betw

// Tested against R:
expected = less.pValue;
delta = abs( out.pValue - expected );
tol = 100 * 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 = less.statistic;
delta = abs( out.statistic - expected );
tol = 10.0 * EPS * abs( expected );
t.ok( delta <= tol, 'within tolerance. statistic: '+out.statistic+'. E: '+expected+' Δ: '+delta+'. tol: '+tol );
t.strictEqual( isAlmostSameValue( out.statistic, expected, 0 ), true, 'returns expected value' );

expected = less.ci;
for ( i = 0; i < 2; i++ ) {
delta = abs( out.ci[ i ] - expected[ i ]);
tol = 10.0 * EPS * abs( expected[ i ] );
t.ok( delta <= tol, 'within tolerance. CI['+i+']: '+out.ci[ i ]+'. E: '+expected[ i ]+' Δ: '+delta+'. tol: '+tol );
t.strictEqual( isAlmostSameValue( out.ci[ i ], expected[ i ], 3 ), true, 'returns expected value' );
}
t.end();
});

tape( 'the function performs a one-sided t-test for the Pearson correlation between paired samples (when alternative is `greater`)', function test( t ) {
var expected;
var delta;
var out;
var tol;
var i;
var x;
var y;
Expand All @@ -260,20 +241,14 @@ tape( 'the function performs a one-sided t-test for the Pearson correlation betw

// Tested against R:
expected = greater.pValue;
delta = abs( out.pValue - expected );
tol = 100 * 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 = greater.statistic;
delta = abs( out.statistic - expected );
tol = 10.0 * EPS * abs( expected );
t.ok( delta <= tol, 'within tolerance. statistic: '+out.statistic+'. E: '+expected+' Δ: '+delta+'. tol: '+tol );
t.strictEqual( isAlmostSameValue( out.statistic, expected, 2 ), true, 'returns expected value' );

expected = greater.ci;
for ( i = 0; i < 2; i++ ) {
delta = abs( out.ci[ i ] - expected[ i ]);
tol = 10.0 * EPS * abs( expected[ i ] );
t.ok( delta <= tol, 'within tolerance. CI['+i+']: '+out.ci[ i ]+'. E: '+expected[ i ]+' Δ: '+delta+'. tol: '+tol );
t.strictEqual( isAlmostSameValue( out.ci[ i ], expected[ i ], 3 ), true, 'returns expected value' );
}
t.end();
});
Expand Down
Loading