one-data-set.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. 'use strict';
  2. const test = require('tap').test;
  3. const ttest = require('../../hypothesis.js');
  4. const equals = require('../equals.js');
  5. const summary = require('summary');
  6. test('testing not equal alternative', function (t) {
  7. const res = ttest([1, 2, 2, 2, 4], {
  8. mu: 2,
  9. alpha: 0.05,
  10. alternative: 'not equal'
  11. });
  12. equals(t, res, {
  13. valid: true,
  14. freedom: 4,
  15. pValue: 0.703999999999999737099187768763,
  16. testValue: 0.408248290463863405808098150374,
  17. confidence: [
  18. 0.839825238683489017077477001294,
  19. 3.560174761316511560238495803787
  20. ]
  21. });
  22. t.end();
  23. });
  24. test('testing summary as argument', function (t) {
  25. const res = ttest(summary([1, 2, 2, 2, 4]), {
  26. mu: 2,
  27. alpha: 0.05,
  28. alternative: 'not equal'
  29. });
  30. equals(t, res, {
  31. valid: true,
  32. freedom: 4,
  33. pValue: 0.703999999999999737099187768763,
  34. testValue: 0.408248290463863405808098150374,
  35. confidence: [
  36. 0.839825238683489017077477001294,
  37. 3.560174761316511560238495803787
  38. ]
  39. });
  40. t.end();
  41. });
  42. test('testing plain object as argument', function (t) {
  43. const obj = {};
  44. const sum = summary([1, 2, 2, 2, 4]);
  45. ['mean', 'variance', 'size'].forEach(function (name) {
  46. obj[name] = sum[name]();
  47. });
  48. const res = ttest(obj, {
  49. mu: 2,
  50. alpha: 0.05,
  51. alternative: 'not equal'
  52. });
  53. equals(t, res, {
  54. valid: true,
  55. freedom: 4,
  56. pValue: 0.703999999999999737099187768763,
  57. testValue: 0.408248290463863405808098150374,
  58. confidence: [
  59. 0.839825238683489017077477001294,
  60. 3.560174761316511560238495803787
  61. ]
  62. });
  63. t.end();
  64. });
  65. test('testing less alternative', function (t) {
  66. const res = ttest([1, 2, 2, 2, 4], {
  67. mu: 2,
  68. alpha: 0.05,
  69. alternative: 'less'
  70. });
  71. equals(t, res, {
  72. valid: true,
  73. freedom: 4,
  74. pValue: 0.648000000000000131450406115619,
  75. testValue: 0.408248290463863405808098150374,
  76. confidence: [
  77. -Infinity,
  78. 3.244387367258481980059059424093
  79. ]
  80. });
  81. t.end();
  82. });
  83. test('testing greater alternative', function (t) {
  84. const res = ttest([1, 2, 2, 2, 4], {
  85. mu: 2,
  86. alpha: 0.05,
  87. alternative: 'greater'
  88. });
  89. equals(t, res, {
  90. valid: true,
  91. freedom: 4,
  92. pValue: 0.351999999999999868549593884381,
  93. testValue: 0.408248290463863405808098150374,
  94. confidence: [
  95. 1.155612632741518375212308455957,
  96. Infinity
  97. ]
  98. });
  99. t.end();
  100. });