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
75 changes: 17 additions & 58 deletions lib/node_modules/@stdlib/stats/ttest2/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@

var tape = require( 'tape' );
var contains = require( '@stdlib/assert/contains' );
var abs = require( '@stdlib/math/base/special/abs' );
var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' );
var NINF = require( '@stdlib/constants/float64/ninf' );
var PINF = require( '@stdlib/constants/float64/pinf' );
var EPS = require( '@stdlib/constants/float64/eps' );
var ttest2 = require( './../lib' );


Expand Down Expand Up @@ -180,9 +179,7 @@ tape( 'the function throws an error if the `alpha` option is a numeric value out

tape( 'the function by default performs a Welch two-sample t-test assuming unequal population variances', function test( t ) {
var expected;
var delta;
var out;
var tol;
var a;
var b;

Expand All @@ -192,33 +189,23 @@ tape( 'the function by default performs a Welch two-sample t-test assuming unequ

// Tested against R:
expected = unequal.pValue;
delta = abs( out.pValue - expected );
tol = 18.0 * EPS * abs( expected );
t.ok( delta <= tol, 'within tolerance. a: ['+a+']. b: ['+b+']. pValue: '+out.pValue+'. E: '+expected+'. Δ: '+delta+'. tol: '+tol );
t.strictEqual( isAlmostSameValue( out.pValue, expected, 17 ), true, 'returns expected value' );

expected = unequal.statistic;
delta = abs( out.statistic - expected );
tol = 1.0 * EPS * abs( expected );
t.ok( delta <= tol, 'within tolerance. a: ['+a+']. b: ['+b+']. statistic: '+out.statistic+'. E: '+expected+'. Δ: '+delta+'. tol: '+tol );
t.strictEqual( isAlmostSameValue( out.statistic, expected, 0 ), true, 'returns expected value' );

expected = unequal.lower;
delta = abs( out.ci[0] - expected );
tol = 16.0 * EPS * abs( expected );
t.ok( delta <= tol, 'within tolerance. a: ['+a+']. b: ['+b+']. lower CI: '+out.ci[0]+'. E: '+expected+'. Δ: '+delta+'. tol: '+tol );
t.strictEqual( isAlmostSameValue( out.ci[0], expected, 0 ), true, 'returns expected value' );

expected = unequal.upper;
delta = abs( out.ci[1] - expected );
tol = 1.0 * EPS * abs( expected );
t.ok( delta <= tol, 'within tolerance. a: ['+a+']. b: ['+b+']. upper CI: '+out.ci[1]+'. E: '+expected+'. Δ: '+delta+'. tol: '+tol );
t.strictEqual( isAlmostSameValue( out.ci[1], expected, 1 ), true, 'returns expected value' );

t.end();
});

tape( 'the function performs a two-sample t-test assuming equal population variances if `variance` option is set to `equal`', function test( t ) {
var expected;
var delta;
var out;
var tol;
var a;
var b;

Expand All @@ -230,33 +217,23 @@ tape( 'the function performs a two-sample t-test assuming equal population varia

// Tested against R:
expected = equal.pValue;
delta = abs( out.pValue - expected );
tol = 2.0 * EPS * abs( expected );
t.ok( delta <= tol, 'within tolerance. a: ['+a+']. b: ['+b+']. pValue: '+out.pValue+'. E: '+expected+'. Δ: '+delta+'. tol: '+tol );
t.strictEqual( isAlmostSameValue( out.pValue, expected, 1 ), true, 'returns expected value' );

expected = equal.statistic;
delta = abs( out.statistic - expected );
tol = 4.0 * EPS * abs( expected );
t.ok( delta <= tol, 'within tolerance. a: ['+a+']. b: ['+b+']. statistic: '+out.statistic+'. E: '+expected+'. Δ: '+delta+'. tol: '+tol );
t.strictEqual( isAlmostSameValue( out.statistic, expected, 0 ), true, 'returns expected value' );

expected = equal.lower;
delta = abs( out.ci[0] - expected );
tol = 8.0 * EPS * abs( expected );
t.ok( delta <= tol, 'within tolerance. a: ['+a+']. b: ['+b+']. lower CI: '+out.ci[0]+'. E: '+expected+'. Δ: '+delta+'. tol: '+tol );
t.strictEqual( isAlmostSameValue( out.ci[0], expected, 0 ), true, 'returns expected value' );

expected = equal.upper;
delta = abs( out.ci[1] - expected );
tol = 8.0 * EPS * abs( expected );
t.ok( delta <= tol, 'within tolerance. a: ['+a+']. b: ['+b+']. upper CI: '+out.ci[1]+'. E: '+expected+'. Δ: '+delta+'. tol: '+tol );
t.strictEqual( isAlmostSameValue( out.ci[1], expected, 0 ), true, 'returns expected value' );

t.end();
});

tape( 'the function performs a two-sample t-test assuming the true difference in means being equal to the value of `difference` option', function test( t ) {
var expected;
var delta;
var out;
var tol;
var a;
var b;

Expand All @@ -271,23 +248,17 @@ tape( 'the function performs a two-sample t-test assuming the true difference in
t.strictEqual( out.statistic, diff.statistic, 'returns correct test statistic' );

expected = diff.lower;
delta = abs( out.ci[0] - expected );
tol = 6.0 * EPS * abs( expected );
t.ok( delta <= tol, 'within tolerance. a: ['+a+']. b: ['+b+']. lower CI: '+out.ci[0]+'. E: '+expected+'. Δ: '+delta+'. tol: '+tol );
t.strictEqual( isAlmostSameValue( out.ci[0], expected, 0 ), true, 'returns expected value' );

expected = diff.upper;
delta = abs( out.ci[1] - expected );
tol = 12.0 * EPS * abs( expected );
t.ok( delta <= tol, 'within tolerance. a: ['+a+']. b: ['+b+']. upper CI: '+out.ci[1]+'. E: '+expected+'. Δ: '+delta+'. tol: '+tol );
t.strictEqual( isAlmostSameValue( out.ci[1], expected, 0 ), true, 'returns expected value' );

t.end();
});

tape( 'the function performs a one-sided Welch two-sample t-test assuming unequal population variances', function test( t ) {
var expected;
var delta;
var out;
var tol;
var a;
var b;

Expand All @@ -299,41 +270,29 @@ tape( 'the function performs a one-sided Welch two-sample t-test assuming unequa

// Tested against R:
expected = less.pValue;
delta = abs( out.pValue - expected );
tol = 18.0 * EPS * abs( expected );
t.ok( delta <= tol, 'within tolerance. direction: less. a: ['+a+']. b: ['+b+']. pValue: '+out.pValue+'. E: '+expected+'. Δ: '+delta+'. tol: '+tol );
t.strictEqual( isAlmostSameValue( out.pValue, expected, 17 ), true, 'returns expected value' );

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

t.strictEqual( out.ci[0], NINF, 'returns -Infinity as lower bound of CI' );

expected = less.upper;
delta = abs( out.ci[1] - expected );
tol = 4.0 * EPS * abs( expected );
t.ok( delta <= tol, 'within tolerance. direction: less. a: ['+a+']. b: ['+b+']. upper CI: '+out.ci[1]+'. E: '+expected+'. Δ: '+delta+'. tol: '+tol );
t.strictEqual( isAlmostSameValue( out.ci[1], expected, 0 ), true, 'returns expected value' );

out = ttest2( a, b, {
'alternative': 'greater'
});

// Tested against R:
expected = greater.pValue;
delta = abs( out.pValue - expected );
tol = 4.0 * EPS * abs( expected );
t.ok( delta <= tol, 'within tolerance. direction: greater. a: ['+a+']. b: ['+b+']. pValue: '+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 = 2.0 * EPS * abs( expected );
t.ok( delta <= tol, 'within tolerance. direction: greater. a: ['+a+']. b: ['+b+']. statistic: '+out.statistic+'. E: '+expected+'. Δ: '+delta+'. tol: '+tol );
t.strictEqual( isAlmostSameValue( out.statistic, expected, 0 ), true, 'returns expected value' );

expected = greater.lower;
delta = abs( out.ci[0] - expected );
tol = 7.0 * EPS * abs( expected );
t.ok( delta <= tol, 'within tolerance. direction: greater. a: ['+a+']. b: ['+b+']. lower CI: '+out.ci[0]+'. E: '+expected+'. Δ: '+delta+'. tol: '+tol );
t.strictEqual( isAlmostSameValue( out.ci[0], expected, 0 ), true, 'returns expected value' );

t.strictEqual( out.ci[1], PINF, 'returns Infinity as upper bound of CI' );

Expand Down
Loading