welch.js 675 B

123456789101112131415161718192021222324252627
  1. 'use strict';
  2. const Distribution = require('distributions').Studentt;
  3. const AbstactStudentT = require('./abstact.js');
  4. class StudentT extends AbstactStudentT {
  5. constructor(left, right, options) {
  6. super(options);
  7. const leftSE = left.variance / left.size;
  8. const rightSE = right.variance / right.size;
  9. const commonVariance = leftSE + rightSE;
  10. this._df = Math.pow(commonVariance, 2) / (
  11. Math.pow(leftSE, 2) / (left.size - 1) +
  12. Math.pow(rightSE, 2) / (right.size - 1)
  13. );
  14. this._dist = new Distribution(this._df);
  15. this._se = Math.sqrt(commonVariance);
  16. this._mean = left.mean - right.mean;
  17. }
  18. }
  19. module.exports = StudentT;