studentt.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. var test = require('tap').test;
  2. var distributions = require('../../distributions.js');
  3. var equals = require('../equal.js');
  4. var reference = require('../assets/studentt.json');
  5. test('testing student t density function', function (t) {
  6. equals.absoluteEqual({
  7. test: t,
  8. map: reference.pdf,
  9. fn: (t, df) => distributions.Studentt(df).pdf(t),
  10. limit: 0.0000005
  11. });
  12. t.end();
  13. });
  14. test('testing student t cumulative function', function (t) {
  15. equals.absoluteEqual({
  16. test: t,
  17. map: reference.cdf,
  18. fn: (t, df) => distributions.Studentt(df).cdf(t),
  19. limit: 0.0000005
  20. });
  21. t.end();
  22. });
  23. test('testing student t inverse function', function (t) {
  24. equals.absoluteEqual({
  25. test: t,
  26. map: reference.ppf,
  27. fn: (p, df) => distributions.Studentt(df).inv(p),
  28. limit: 0.0000005
  29. });
  30. equals.absoluteEqual({
  31. test: t,
  32. map: [
  33. [0.0, 15, -Infinity],
  34. [1.0, 15, +Infinity]
  35. ],
  36. fn: (p, df) => distributions.Studentt(df).inv(p),
  37. limit: 0.0000005
  38. });
  39. t.end();
  40. });
  41. test('testing student t key values', function (t) {
  42. var studentt = distributions.Studentt(15);
  43. t.equal(studentt.median(), 0);
  44. t.equal(studentt.mean(), 0);
  45. t.equal(studentt.variance(), 15/13);
  46. t.end();
  47. });