Skip to content

Commit

Permalink
Merge pull request #41 from zp-j/master
Browse files Browse the repository at this point in the history
Fixed issue #40: BETADIST function does not work correctly.
  • Loading branch information
jalateras committed Mar 19, 2016
2 parents b957077 + 9bdc350 commit 5f32761
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 5 additions & 1 deletion lib/statistical.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ exports.AVERAGEIFS = function() {
exports.BETA = {};

exports.BETA.DIST = function(x, alpha, beta, cumulative, A, B) {
if (arguments.length < 4) {
return error.value;
}

A = (A === undefined) ? 0 : A;
B = (B === undefined) ? 1 : B;

Expand Down Expand Up @@ -1737,4 +1741,4 @@ exports.Z.TEST = function(range, x, sd) {
sd = sd || exports.STDEV.S(range);
var n = range.length;
return 1 - exports.NORM.S.DIST((exports.AVERAGE(range) - x) / (sd / Math.sqrt(n)), true);
};
};
7 changes: 5 additions & 2 deletions test/statistical.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ suite('Statistical', function() {
});

test('BETA.DIST', function() {
statistical.BETA.DIST(2, 8, 10, 1, 3).should.approximately(0.6854705810117458, 1e-9);
statistical.BETA.DIST(2, 8, 10, true, 1, 3).should.approximately(0.6854705810117458, 1e-9);
statistical.BETA.DIST(1/52, 0.4, 9.6, false).should.approximately(9.966606842186748, 1e-9);
statistical.BETA.DIST(1/52, 0.4, 9.6, true).should.approximately(0.5406016379941343, 1e-9);
statistical.BETA.DIST(2, 8, 10).should.equal(error.value);
statistical.BETA.DIST(2, 8, 'invalid', 1, 3).should.equal(error.value);
});

Expand Down Expand Up @@ -949,4 +952,4 @@ suite('Statistical', function() {
statistical.Z.TEST(data, 6).should.approximately(0.86304338912953, 1e-9);
statistical.Z.TEST(data, 'invalid').should.equal(error.value);
});
});
});

0 comments on commit 5f32761

Please sign in to comment.