Skip to content

Commit

Permalink
case that total is 0
Browse files Browse the repository at this point in the history
  • Loading branch information
egusahiroaki committed Dec 29, 2019
1 parent 8ec3990 commit 291c1b9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
const jStat = require("jstat");

const BinomialProportion = (count, nobs, alpha = 0.05, method = "normal") => {
if (nobs === 0) {
return {
lowerBound: 0, value: 0, upperBound: 0
}
}

const z = -1 * jStat.normal.inv(alpha / 2, 0, 1);
let p = count / nobs;
let sd;
Expand Down
8 changes: 8 additions & 0 deletions test/test-index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import test from "ava";
import BinomialProportion from "../index";

test("total is 0", t => {
const result = BinomialProportion(50, 0, 0.05, "normal");
t.is(result.lowerBound, 0);
t.is(result.value, 0);
t.is(result.upperBound, 0);
});


test("normal: Binominal(10, 500, 0.05, 'normal')", t => {
const result = BinomialProportion(50, 500, 0.05, "normal");
t.is(result.lowerBound, 0.07370432378270254);
Expand Down

0 comments on commit 291c1b9

Please sign in to comment.