two-data-set.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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], [0, 3, 3, 3, 2], {
  8. mu: 1,
  9. varEqual: true,
  10. alpha: 0.05,
  11. alternative: 'not equal'
  12. });
  13. equals(t, res, {
  14. valid: true,
  15. freedom: 8,
  16. pValue: 0.225571973816597132200811870462,
  17. testValue: -1.313064328597225660644198796945,
  18. confidence: [
  19. -1.756200427489884585696700014523,
  20. 1.756200427489884585696700014523
  21. ]
  22. });
  23. t.end();
  24. });
  25. test('testing not equal alternative', function (t) {
  26. const res = ttest(summary([1, 2, 2, 2, 4]), summary([0, 3, 3, 3, 2]), {
  27. mu: 1,
  28. varEqual: true,
  29. alpha: 0.05,
  30. alternative: 'not equal'
  31. });
  32. equals(t, res, {
  33. valid: true,
  34. freedom: 8,
  35. pValue: 0.225571973816597132200811870462,
  36. testValue: -1.313064328597225660644198796945,
  37. confidence: [
  38. -1.756200427489884585696700014523,
  39. 1.756200427489884585696700014523
  40. ]
  41. });
  42. t.end();
  43. });
  44. test('testing less alternative', function (t) {
  45. const res = ttest([1, 2, 2, 2, 4], [0, 3, 3, 3, 2], {
  46. mu: 1,
  47. varEqual: true,
  48. alpha: 0.05,
  49. alternative: 'less'
  50. });
  51. equals(t, res, {
  52. valid: true,
  53. freedom: 8,
  54. pValue: 0.112785986908298566100405935231,
  55. testValue: -1.313064328597225660644198796945,
  56. confidence: [
  57. -Infinity,
  58. 1.416189593328981199960026060580
  59. ]
  60. });
  61. t.end();
  62. });
  63. test('testing greater alternative', function (t) {
  64. const res = ttest([1, 2, 2, 2, 4], [0, 3, 3, 3, 2], {
  65. mu: 1,
  66. varEqual: true,
  67. alpha: 0.05,
  68. alternative: 'greater'
  69. });
  70. equals(t, res, {
  71. valid: true,
  72. freedom: 8,
  73. pValue: 0.887214013091701447777381872584,
  74. testValue: -1.313064328597225660644198796945,
  75. confidence: [
  76. -1.416189593328981199960026060580,
  77. Infinity
  78. ]
  79. });
  80. t.end();
  81. });