Skip to content

Commit

Permalink
Fixed issue #40: BETADIST function does not work correctly.
Browse files Browse the repository at this point in the history
Issue:

Following latest MS Excel documentation: [BETA.DIST](https://support.office.com/en-my/article/BETA-DIST-function-11188c9c-780a-42c7-ba43-9ecb5a878d31?ui=en-US&rs=en-MY&ad=MY&fromAR=1) will take at least four arguments.

Solution:

Added argument checks in function BETA.DIST().
More tests are also added.
  • Loading branch information
0x333333 committed Oct 28, 2015
1 parent b957077 commit 9bdc350
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 9bdc350

Please sign in to comment.