From 9bdc350f21c926e3a15e94d06214f104b08c106a Mon Sep 17 00:00:00 2001 From: Zhipeng Jiang Date: Wed, 28 Oct 2015 23:55:38 +0100 Subject: [PATCH] Fixed issue #40: BETADIST function does not work correctly. 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. --- lib/statistical.js | 6 +++++- test/statistical.js | 7 +++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/statistical.js b/lib/statistical.js index 7c9491b4..355d8ce7 100644 --- a/lib/statistical.js +++ b/lib/statistical.js @@ -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; @@ -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); -}; \ No newline at end of file +}; diff --git a/test/statistical.js b/test/statistical.js index 55561b51..74145847 100644 --- a/test/statistical.js +++ b/test/statistical.js @@ -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); }); @@ -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); }); -}); \ No newline at end of file +});