Skip to content

Commit

Permalink
Merge pull request #3 from msn0/v2
Browse files Browse the repository at this point in the history
V2
  • Loading branch information
msn0 authored Jul 16, 2017
2 parents 37e522a + 6e38312 commit 7f5289b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
28 changes: 28 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module.exports = function (positiveScore, total) {

if (total === 0) {
return {
left: 0,
right: 0
};
}

// phat is the proportion of successes
// in a Bernoulli trial process
const phat = positiveScore / total;

// z is 1-alpha/2 percentile of a standard
// normal distribution for error alpha=5%
const z = 1.96;

// implement the algorithm
// (http://goo.gl/kgmV3g)
const a = phat + z * z / (2 * total);
const b = z * Math.sqrt((phat * (1 - phat) + z * z / (4 * total)) / total);
const c = 1 + z * z / total;

return {
left: (a - b) / c,
right: (a + b) / c
};
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wilson-score-interval",
"version": "2.0.0",
"version": "2.0.1",
"description": "binomial proportion confidence interval",
"author": "Michał Jezierski <ambinanitelo@gmail.com>",
"repository": {
Expand Down

0 comments on commit 7f5289b

Please sign in to comment.