Skip to content

Commit

Permalink
Use class syntax and extends keyword instead of util.inherits (#16)
Browse files Browse the repository at this point in the history
`util.inherits` is now deprecated due to issues with how it sets
the prototype chain, see:  nodejs/node#4179
  • Loading branch information
itamar-owlytics committed Dec 29, 2021
1 parent 7a3c1d7 commit edb8750
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 33 deletions.
18 changes: 10 additions & 8 deletions hypothesis/one-data-set.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@

const Distribution = require('distributions').Studentt;

const util = require('util');
const AbstactStudentT = require('./abstact.js');

function StudentT(data, options) {
AbstactStudentT.call(this, options);
class StudentT extends AbstactStudentT {

this._df = data.size - 1;
this._dist = new Distribution(this._df);
constructor(data, options) {
super(options);
this._df = data.size - 1;
this._dist = new Distribution(this._df);

this._se = Math.sqrt(data.variance / data.size);
this._mean = data.mean;
}

this._se = Math.sqrt(data.variance / data.size);
this._mean = data.mean;
}
util.inherits(StudentT, AbstactStudentT);

module.exports = StudentT;
25 changes: 14 additions & 11 deletions hypothesis/two-data-set.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,24 @@

const Distribution = require('distributions').Studentt;

const util = require('util');
const AbstactStudentT = require('./abstact.js');

function StudentT(left, right, options) {
AbstactStudentT.call(this, options);
class StudentT extends AbstactStudentT {

constructor(left, right, options) {
super(options);

this._df = left.size + right.size - 2;
this._dist = new Distribution(this._df);
this._df = left.size + right.size - 2;
this._dist = new Distribution(this._df);

const commonVariance = ((left.size - 1) * left.variance +
(right.size - 1) * right.variance
) / this._df;
const commonVariance = ((left.size - 1) * left.variance +
(right.size - 1) * right.variance
) / this._df;

this._se = Math.sqrt(commonVariance * (1 / left.size + 1 / right.size));
this._mean = left.mean - right.mean;
}

this._se = Math.sqrt(commonVariance * (1 / left.size + 1 / right.size));
this._mean = left.mean - right.mean;
}
util.inherits(StudentT, AbstactStudentT);

module.exports = StudentT;
30 changes: 16 additions & 14 deletions hypothesis/welch.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,26 @@

const Distribution = require('distributions').Studentt;

const util = require('util');
const AbstactStudentT = require('./abstact.js');

function StudentT(left, right, options) {
AbstactStudentT.call(this, options);
class StudentT extends AbstactStudentT {

constructor(left, right, options) {
super(options);

const leftSE = left.variance / left.size;
const rightSE = right.variance / right.size;
const commonVariance = leftSE + rightSE;
const leftSE = left.variance / left.size;
const rightSE = right.variance / right.size;
const commonVariance = leftSE + rightSE;

this._df = Math.pow(commonVariance, 2) / (
Math.pow(leftSE, 2) / (left.size - 1) +
Math.pow(rightSE, 2) / (right.size - 1)
);
this._dist = new Distribution(this._df);
this._df = Math.pow(commonVariance, 2) / (
Math.pow(leftSE, 2) / (left.size - 1) +
Math.pow(rightSE, 2) / (right.size - 1)
);
this._dist = new Distribution(this._df);

this._se = Math.sqrt(commonVariance);
this._mean = left.mean - right.mean;
this._se = Math.sqrt(commonVariance);
this._mean = left.mean - right.mean;
}
}
util.inherits(StudentT, AbstactStudentT);

module.exports = StudentT;

0 comments on commit edb8750

Please sign in to comment.