123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- 'use strict';
- const test = require('tap').test;
- const ttest = require('../../hypothesis.js');
- const equals = require('../equals.js');
- const summary = require('summary');
- test('testing not equal alternative', function (t) {
- const res = ttest([1, 2, 2, 2, 4], [0, 3, 3, 3, 2], {
- mu: 1,
- varEqual: false,
- alpha: 0.05,
- alternative: 'not equal'
- });
- equals(t, res, {
- valid: true,
- freedom: 7.769053117782910966582,
- pValue: 0.22661539838413605,
- testValue: -1.313064328597225660644,
- confidence: [
- -1.7653291692417925,
- 1.7653291692417925
- ]
- });
- t.end();
- });
- test('testing not equal alternative with summary', function (t) {
- const res = ttest(summary([1, 2, 2, 2, 4]), summary([0, 3, 3, 3, 2]), {
- mu: 1,
- varEqual: false,
- alpha: 0.05,
- alternative: 'not equal'
- });
- equals(t, res, {
- valid: true,
- freedom: 7.769053117782910966582,
- pValue: 0.22661539838413605,
- testValue: -1.313064328597225660644,
- confidence: [
- -1.7653291692417925,
- 1.7653291692417925
- ]
- });
- t.end();
- });
- test('testing less alternative', function (t) {
- const res = ttest([1, 2, 2, 2, 4], [0, 3, 3, 3, 2], {
- mu: 1,
- varEqual: false,
- alpha: 0.05,
- alternative: 'less'
- });
- equals(t, res, {
- valid: true,
- freedom: 7.769053117782910966582,
- pValue: 0.11330769919206803,
- testValue: -1.313064328597225660644,
- confidence: [
- -Infinity,
- 1.4216665293566955
- ]
- });
- t.end();
- });
- test('testing greater alternative', function (t) {
- const res = ttest([1, 2, 2, 2, 4], [0, 3, 3, 3, 2], {
- mu: 1,
- varEqual: false,
- alpha: 0.05,
- alternative: 'greater'
- });
- equals(t, res, {
- valid: true,
- freedom: 7.769053117782910966582,
- pValue: 0.8866923008079319,
- testValue: -1.313064328597225660644,
- confidence: [
- -1.4216665293566955,
- Infinity
- ]
- });
- t.end();
- });
- test('numerical error when p is close to zero', function (t) {
- const ttest = require('ttest');
- const ref = [
- 3.861147687082808,4.1833109086557325,3.973594179324881,
- 4.067660887263925,3.7661981850423203,3.8407050592346477,
- 3.983494353110395,3.791224198364107,3.7573201433330223,
- 3.6326953678695757,3.649353001081396,4.008367559943343,
- 3.642362926456249,3.9386159539971635,3.965380930294604,
- 3.720419087302582,4.019779785322333,3.916874280250766,
- 3.9826331513375517,3.8487184246955795,3.9777597010041306,
- 3.9301399596581796,3.3977074280624233,4.016225096648127,
- 3.9947182452600187,3.7147293468453944,3.9650116229578796,
- 4.15261985914954,4.072283338272716,4.018258042542346,
- 4.275900504663435,4.247052603538485,3.8632869646479966,
- 4.195181524801175,4.061338223974988,3.997470766890559,
- 4.151394128832368,3.956574144537081,4.102028418283781,
- 3.895513445852064,4.294429613680861,4.147884159109542,
- 4.324981618980995,3.9225663296782742,3.9036535245451747,
- 3.996488485132162,4.068017402803237,3.9086757816917657,
- 4.1985806684438485,4.215712687842988,4.141082407873602,
- 4.130592122446437,3.9844787517550766,4.055413115719177,
- 4.295688728970604,3.9295909891273317,4.018853727187908,
- 4.211687367710041,4.039532923487119,4.150267003760778,
- 3.9571008871840943,4.250207443005561,3.6432440226648395,
- 4.0926554219335065,3.9671228831029244,4.050496312050845,
- 4.08886200014234,3.9569368332194244,3.973713976092726,
- 4.078102228403546,3.8457644781798885,4.063690907132751,
- 4.072802425585134
- ];
- const other = [
- 4.196088504937897,4.297600006725063,4.380931627957188,
- 4.229470416380346,4.51424161894835,4.15374761736698,
- 4.185259220991428,4.1184978606339735,4.242710204234378,
- 4.357880244428704,4.2342678907235465,4.417689232509152,
- 4.391094295930451,4.270372284867759,4.404107881034074,
- 4.088192613114767,4.327923994691726,4.094632609126974,
- 4.169154407256733,4.291471956751135,3.9389016863511612,
- 4.236946427323764,4.429129606388344,4.362366516924023,
- 4.15712520715034,4.273894263027447,4.291340851721514,
- 4.156093971770384,4.18322608310349,4.242268731414564,
- 4.282951092770966,4.250751025033699,4.1722021750486595,
- 4.223035449341226,4.236514858116207,4.370006322215913,
- 4.2523040462607495,4.418104161273623,4.005054694044181,
- 4.332140449797302,4.114901342239478,4.235374982468168,
- 4.189091743846535,4.391354534957378,4.395337620628255,
- 4.331974041511989,4.406671154699146,4.399646144051766,
- 4.2813460855899175,4.289620122487038,4.390782160631226,
- 4.229368785039166,4.006587130212967,4.179324028691534,
- 4.126061175939888,4.2893865958789,4.26270828836601,
- 4.439895292474625,4.221064697480762,4.1670134964393455,
- 4.123864672737084,4.416479313108734,4.253537292991181,
- 4.141417410861353,4.239734666096584,4.263623754941469,
- 3.9763012135882425,4.251617630059521,4.292616064339593,
- 4.498105896751339,4.266088146494694,4.175256450633397,
- 4.375893778023997,4.2857149056812665,4.298162810306891,
- 4.40570741930156,4.332451872647763
- ];
- const res = ttest(ref, other, { varEqual: false });
- equals(t, res, {
- valid: false,
- freedom: 124.78698315673383,
- pValue: 9.192938947804553e-20,
- testValue: -10.865820339325207,
- confidence: [
- -0.31682232117864595,
- -0.21919020661869715
- ]
- });
- t.end();
- });
|