wilson-interval 4.0.5 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/codecov.yml +23 -0
- package/.github/workflows/node.js.yml +31 -0
- package/.github/workflows/npm-publish.yml +33 -0
- package/README.md +1 -4
- package/codecov.yml +25 -0
- package/package.json +13 -22
- package/src/index.js +8 -12
- package/src/index.test.js +34 -7
- package/.babelrc +0 -5
- package/.coveralls.yml +0 -1
- package/.eslintignore +0 -3
- package/.eslintrc +0 -120
- package/circle.yml +0 -27
- package/jsconfig.json +0 -11
- package/lib/index.js +0 -61
- package/src/__snapshots__/index.test.js.snap +0 -33
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Adapted from https://github.com/codecov/example-javascript
|
|
2
|
+
name: Codecov Test Coverage Report
|
|
3
|
+
on: [pull_request]
|
|
4
|
+
jobs:
|
|
5
|
+
build:
|
|
6
|
+
|
|
7
|
+
runs-on: ubuntu-latest
|
|
8
|
+
|
|
9
|
+
steps:
|
|
10
|
+
- uses: actions/checkout@v4
|
|
11
|
+
- name: Use Node.js ${{ matrix.node-version }}
|
|
12
|
+
uses: actions/setup-node@v4
|
|
13
|
+
with:
|
|
14
|
+
node-version: 21 # Node native test coverage reporting introduced in v20.11.0
|
|
15
|
+
cache: 'npm'
|
|
16
|
+
- run: npm ci
|
|
17
|
+
- run: npm run build --if-present
|
|
18
|
+
- run: npm run test:cc
|
|
19
|
+
- name: Upload coverage reports to Codecov
|
|
20
|
+
uses: codecov/codecov-action@v5
|
|
21
|
+
with:
|
|
22
|
+
token: ${{ secrets.CODECOV_TOKEN }}
|
|
23
|
+
slug: erikfox/wilson-interval
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
|
|
2
|
+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs
|
|
3
|
+
|
|
4
|
+
name: Node.js CI
|
|
5
|
+
|
|
6
|
+
on:
|
|
7
|
+
push:
|
|
8
|
+
branches: [ "master" ]
|
|
9
|
+
pull_request:
|
|
10
|
+
branches: [ "master" ]
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
build:
|
|
14
|
+
|
|
15
|
+
runs-on: ubuntu-latest
|
|
16
|
+
|
|
17
|
+
strategy:
|
|
18
|
+
matrix:
|
|
19
|
+
node-version: [18.x, 20.x, 22.x]
|
|
20
|
+
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
|
|
21
|
+
|
|
22
|
+
steps:
|
|
23
|
+
- uses: actions/checkout@v4
|
|
24
|
+
- name: Use Node.js ${{ matrix.node-version }}
|
|
25
|
+
uses: actions/setup-node@v4
|
|
26
|
+
with:
|
|
27
|
+
node-version: ${{ matrix.node-version }}
|
|
28
|
+
cache: 'npm'
|
|
29
|
+
- run: npm ci
|
|
30
|
+
- run: npm run build --if-present
|
|
31
|
+
- run: npm test
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
|
|
2
|
+
# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages
|
|
3
|
+
|
|
4
|
+
name: Node.js Package
|
|
5
|
+
|
|
6
|
+
on:
|
|
7
|
+
release:
|
|
8
|
+
types: [created]
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
build:
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
steps:
|
|
14
|
+
- uses: actions/checkout@v4
|
|
15
|
+
- uses: actions/setup-node@v4
|
|
16
|
+
with:
|
|
17
|
+
node-version: 20
|
|
18
|
+
- run: npm ci
|
|
19
|
+
- run: npm test
|
|
20
|
+
|
|
21
|
+
publish-npm:
|
|
22
|
+
needs: build
|
|
23
|
+
runs-on: ubuntu-latest
|
|
24
|
+
steps:
|
|
25
|
+
- uses: actions/checkout@v4
|
|
26
|
+
- uses: actions/setup-node@v4
|
|
27
|
+
with:
|
|
28
|
+
node-version: 20
|
|
29
|
+
registry-url: https://registry.npmjs.org/
|
|
30
|
+
- run: npm ci
|
|
31
|
+
- run: npm publish
|
|
32
|
+
env:
|
|
33
|
+
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
|
package/README.md
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
# Wilson Interval
|
|
2
2
|
|
|
3
|
-
[<img src="https://img.shields.io/twitter/follow/erkfox.svg?style=social&label=Say%20hello!" align="right" alt="Twitter @erkfox" />](https://twitter.com/erkfox)
|
|
4
|
-
|
|
5
3
|
[](https://opensource.org/licenses/MIT)
|
|
6
4
|
[](https://www.npmjs.com/package/wilson-interval)
|
|
7
5
|
[](https://www.npmjs.com/package/wilson-interval)
|
|
8
|
-
[](https://coveralls.io/github/erikfox/wilson-interval)
|
|
6
|
+
[](https://codecov.io/github/erikfox/wilson-interval)
|
|
10
7
|
|
|
11
8
|
|
|
12
9
|
[]()
|
package/codecov.yml
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
coverage:
|
|
2
|
+
status:
|
|
3
|
+
project:
|
|
4
|
+
default: # default is the status check's name, not default settings
|
|
5
|
+
target: 100%
|
|
6
|
+
threshold: 1%
|
|
7
|
+
base: auto
|
|
8
|
+
flags:
|
|
9
|
+
- unit
|
|
10
|
+
paths:
|
|
11
|
+
- "src"
|
|
12
|
+
# advanced settings
|
|
13
|
+
branches:
|
|
14
|
+
- master
|
|
15
|
+
if_ci_failed: error #success, failure, error, ignore
|
|
16
|
+
informational: false
|
|
17
|
+
only_pulls: false
|
|
18
|
+
|
|
19
|
+
comment:
|
|
20
|
+
layout: " diff, flags, files"
|
|
21
|
+
behavior: default
|
|
22
|
+
require_changes: false
|
|
23
|
+
require_base: false
|
|
24
|
+
require_head: true
|
|
25
|
+
hide_project_coverage: false
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wilson-interval",
|
|
3
|
-
"version": "
|
|
4
|
-
"author": "Erik Fox <
|
|
3
|
+
"version": "5.0.0",
|
|
4
|
+
"author": "Erik Fox <eriktfox@gmail.com> (http://erikfox.dev)",
|
|
5
5
|
"description": "Used to calculate the high bound, low bound, and center of a Wilson score interval. Features support for continuity correction and Singleton's adjustment.",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://github.com/erikfox/wilson-interval",
|
|
@@ -25,29 +25,20 @@
|
|
|
25
25
|
"upvotes",
|
|
26
26
|
"downvotes"
|
|
27
27
|
],
|
|
28
|
-
"
|
|
28
|
+
"engines": {
|
|
29
|
+
"node": ">=18.0.0"
|
|
30
|
+
},
|
|
31
|
+
"type": "module",
|
|
32
|
+
"main": "./src/index.js",
|
|
33
|
+
"exports": {
|
|
34
|
+
".": "./src/index.js"
|
|
35
|
+
},
|
|
29
36
|
"scripts": {
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"test": "jest --coverage",
|
|
33
|
-
"test-ci": "jest --coverage && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js",
|
|
34
|
-
"lint": "eslint src",
|
|
35
|
-
"precommit": "npm run lint && npm run test && npm run build && git add lib"
|
|
37
|
+
"test": "node --test src/index.test.js",
|
|
38
|
+
"test:cc": "node --test --experimental-test-coverage --test-reporter=lcov --test-reporter-destination=lcov.info src/index.test.js"
|
|
36
39
|
},
|
|
37
40
|
"dependencies": {
|
|
38
|
-
"mathjs": "^
|
|
41
|
+
"mathjs": "^14.0.0",
|
|
39
42
|
"pnormaldist": "^1.0.0"
|
|
40
|
-
},
|
|
41
|
-
"devDependencies": {
|
|
42
|
-
"babel-cli": "^6.26.0",
|
|
43
|
-
"babel-eslint": "^7.2.3",
|
|
44
|
-
"babel-jest": "^24.8.0",
|
|
45
|
-
"babel-preset-env": "^1.7.0",
|
|
46
|
-
"coveralls": "^3.0.3",
|
|
47
|
-
"eslint": "^5.16.0",
|
|
48
|
-
"eslint-plugin-babel": "^4.1.2",
|
|
49
|
-
"eslint-plugin-jest": "^20.0.3",
|
|
50
|
-
"husky": "^0.14.3",
|
|
51
|
-
"jest": "^24.8.0"
|
|
52
43
|
}
|
|
53
44
|
}
|
package/src/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { create, all } from 'mathjs';
|
|
2
2
|
import pnormaldist from 'pnormaldist';
|
|
3
3
|
|
|
4
4
|
export default function wilson(observed, sample, population = false, options = {}) {
|
|
@@ -7,40 +7,36 @@ export default function wilson(observed, sample, population = false, options = {
|
|
|
7
7
|
precision = 20,
|
|
8
8
|
} = options;
|
|
9
9
|
|
|
10
|
-
math
|
|
10
|
+
const math = create(all, { number: 'BigNumber', precision });
|
|
11
11
|
|
|
12
12
|
observed = math.bignumber(observed);
|
|
13
13
|
sample = math.bignumber(sample);
|
|
14
14
|
|
|
15
|
-
const proportion = math.
|
|
15
|
+
const proportion = math.evaluate('observed / sample', { observed, sample });
|
|
16
16
|
|
|
17
17
|
if (population) {
|
|
18
|
-
sample = math.
|
|
18
|
+
sample = math.evaluate('sample / (sqrt(1 - sample / population))', { sample, population });
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
const zScore = pnormaldist(math.
|
|
21
|
+
const zScore = pnormaldist(math.evaluate('1 - (1 - confidence) / 2', { confidence }));
|
|
22
22
|
|
|
23
|
-
return wilsonInterval(proportion, sample, zScore);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function wilsonInterval(proportion, sample, zScore) {
|
|
27
23
|
const scope = {
|
|
28
24
|
p: math.bignumber(proportion),
|
|
29
25
|
n: math.bignumber(sample),
|
|
30
26
|
z: math.bignumber(zScore),
|
|
31
27
|
};
|
|
32
28
|
|
|
33
|
-
const high = math.format(math.
|
|
29
|
+
const high = math.format(math.evaluate(
|
|
34
30
|
'(p + z * z / (2 * n) + z * sqrt(p * (1 - p) / n + z * z / (4 * (n * n)))) / (1 + z * z / n)',
|
|
35
31
|
scope,
|
|
36
32
|
));
|
|
37
33
|
|
|
38
|
-
const low = math.format(math.
|
|
34
|
+
const low = math.format(math.evaluate(
|
|
39
35
|
'(p + z * z / (2 * n) - z * sqrt(p * (1 - p) / n + z * z / (4 * (n * n)))) / (1 + z * z / n)',
|
|
40
36
|
scope,
|
|
41
37
|
));
|
|
42
38
|
|
|
43
|
-
const center = math.format(math.
|
|
39
|
+
const center = math.format(math.evaluate(
|
|
44
40
|
'(p + z * z / (2 * n)) / (1 + z * z / n)',
|
|
45
41
|
scope,
|
|
46
42
|
));
|
package/src/index.test.js
CHANGED
|
@@ -1,27 +1,54 @@
|
|
|
1
|
-
import wilson from '.';
|
|
1
|
+
import wilson from './index.js';
|
|
2
|
+
import test from 'node:test';
|
|
3
|
+
import assert from 'node:assert';
|
|
4
|
+
import { describe } from 'node:test';
|
|
2
5
|
|
|
3
6
|
describe('wilson()', () => {
|
|
4
|
-
describe('
|
|
7
|
+
describe('handles base args', () => {
|
|
5
8
|
test('wilson(5, 100)', () => {
|
|
6
9
|
const result = wilson(5, 100);
|
|
7
|
-
|
|
10
|
+
|
|
11
|
+
assert.deepEqual(result, {
|
|
12
|
+
"high": "0.11175046869375655694",
|
|
13
|
+
"center": "0.066647073981204927863",
|
|
14
|
+
"low": "0.021543679268653298792",
|
|
15
|
+
});
|
|
8
16
|
});
|
|
17
|
+
});
|
|
9
18
|
|
|
19
|
+
describe('handles population arg', () => {
|
|
10
20
|
test('wilson(5, 100, 227)', () => {
|
|
11
21
|
const result = wilson(5, 100, 227);
|
|
12
|
-
|
|
22
|
+
|
|
23
|
+
assert.deepEqual(result, {
|
|
24
|
+
"center": "0.062568829500944323976",
|
|
25
|
+
"high": "0.10110044321850152858",
|
|
26
|
+
"low": "0.024037215783387119365",
|
|
27
|
+
});
|
|
13
28
|
});
|
|
14
29
|
});
|
|
15
30
|
|
|
16
|
-
describe('
|
|
31
|
+
describe('handles precision option', () => {
|
|
17
32
|
test('wilson(5, 100, false, { precision: 6 })', () => {
|
|
18
33
|
const result = wilson(5, 100, false, { precision: 6 });
|
|
19
|
-
|
|
34
|
+
|
|
35
|
+
assert.deepEqual(result, {
|
|
36
|
+
"center": "0.0666474",
|
|
37
|
+
"high": "0.111751",
|
|
38
|
+
"low": "0.0215437",
|
|
39
|
+
});
|
|
20
40
|
});
|
|
41
|
+
});
|
|
21
42
|
|
|
43
|
+
describe('handles confidence option', () => {
|
|
22
44
|
test('wilson(5, 100, 227, { confidence: 0.9 })', () => {
|
|
23
45
|
const result = wilson(5, 100, 227, { confidence: 0.9 });
|
|
24
|
-
|
|
46
|
+
|
|
47
|
+
assert.deepEqual(result, {
|
|
48
|
+
"center": "0.058925960344442384957",
|
|
49
|
+
"high": "0.090892465800857729375",
|
|
50
|
+
"low": "0.02695945488802704054",
|
|
51
|
+
});
|
|
25
52
|
});
|
|
26
53
|
});
|
|
27
54
|
});
|
package/.coveralls.yml
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
repo_token: 3QLq1SKbTjP1d5Dk7rO7oXKYouGbUfuxy
|
package/.eslintignore
DELETED
package/.eslintrc
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"root": true,
|
|
3
|
-
"env": {
|
|
4
|
-
"node": true,
|
|
5
|
-
"es6": true,
|
|
6
|
-
"browser": true,
|
|
7
|
-
"jest/globals": true
|
|
8
|
-
},
|
|
9
|
-
"extends": [
|
|
10
|
-
"plugin:jest/recommended"
|
|
11
|
-
],
|
|
12
|
-
"parser": "babel-eslint",
|
|
13
|
-
"parserOptions": {
|
|
14
|
-
"sourceType": "module"
|
|
15
|
-
},
|
|
16
|
-
"plugins": [
|
|
17
|
-
"babel",
|
|
18
|
-
"jest"
|
|
19
|
-
],
|
|
20
|
-
"rules": {
|
|
21
|
-
"strict": 0,
|
|
22
|
-
"eqeqeq": [ "error", "allow-null" ],
|
|
23
|
-
"guard-for-in": "error",
|
|
24
|
-
"no-extend-native": "error",
|
|
25
|
-
"comma-dangle": [ "error", "always-multiline" ],
|
|
26
|
-
"no-use-before-define": ["error", "nofunc"],
|
|
27
|
-
"no-constant-condition": "error",
|
|
28
|
-
"no-debugger": "error",
|
|
29
|
-
"no-dupe-args": "error",
|
|
30
|
-
"no-dupe-keys": "error",
|
|
31
|
-
"no-duplicate-case": "error",
|
|
32
|
-
"no-empty-character-class": "error",
|
|
33
|
-
"no-empty": "error",
|
|
34
|
-
"no-ex-assign": "error",
|
|
35
|
-
"no-extra-boolean-cast": "error",
|
|
36
|
-
"no-extra-parens": "warn",
|
|
37
|
-
"no-extra-semi": "error",
|
|
38
|
-
"no-func-assign": "error",
|
|
39
|
-
"no-inner-declarations": ["error", "functions"],
|
|
40
|
-
"no-invalid-regexp": "error",
|
|
41
|
-
"no-irregular-whitespace": "error",
|
|
42
|
-
"no-negated-in-lhs": "error",
|
|
43
|
-
"no-obj-calls": "error",
|
|
44
|
-
"no-sparse-arrays": "error",
|
|
45
|
-
"no-unreachable": "error",
|
|
46
|
-
"use-isnan": "error",
|
|
47
|
-
"valid-typeof": "error",
|
|
48
|
-
"complexity": ["error", 10],
|
|
49
|
-
"consistent-return": "error",
|
|
50
|
-
"no-with": "error",
|
|
51
|
-
"radix": "error",
|
|
52
|
-
"yoda": ["error", "never"],
|
|
53
|
-
"no-unused-vars": "error",
|
|
54
|
-
"no-var": "error",
|
|
55
|
-
"object-shorthand": "error",
|
|
56
|
-
"prefer-const": "error",
|
|
57
|
-
"prefer-spread": "error",
|
|
58
|
-
"prefer-template": "error",
|
|
59
|
-
"no-undef": "error",
|
|
60
|
-
"max-depth": ["error", 5],
|
|
61
|
-
"max-len": [ "error", 120, 2, { "ignoreComments": true, "ignoreUrls": true } ],
|
|
62
|
-
"max-params": ["error", 5],
|
|
63
|
-
"no-caller": "error",
|
|
64
|
-
"no-sequences": "error",
|
|
65
|
-
"no-throw-literal": "error",
|
|
66
|
-
"new-cap": [ "error", { "capIsNewExceptions": [ "Q", "ObjectId", "Promise" ] } ],
|
|
67
|
-
"no-this-before-super": "error",
|
|
68
|
-
"no-new-object": "error",
|
|
69
|
-
"dot-location": ["error", "property"],
|
|
70
|
-
"dot-notation": "error",
|
|
71
|
-
"no-return-assign": "error",
|
|
72
|
-
"no-useless-call": "error",
|
|
73
|
-
"no-unused-expressions": "error",
|
|
74
|
-
"no-self-compare": "error",
|
|
75
|
-
"wrap-iife": ["error", "inside"],
|
|
76
|
-
"no-alert": "error",
|
|
77
|
-
"no-fallthrough": "error",
|
|
78
|
-
|
|
79
|
-
"eol-last": "error",
|
|
80
|
-
"quotes": [ "error", "single" ],
|
|
81
|
-
"semi": [ "error", "always" ],
|
|
82
|
-
"array-bracket-spacing": [ "error", "always", {
|
|
83
|
-
"singleValue": true,
|
|
84
|
-
"objectsInArrays": true,
|
|
85
|
-
"arraysInArrays": true
|
|
86
|
-
} ],
|
|
87
|
-
"brace-style": [ "error", "1tbs", { "allowSingleLine": true } ],
|
|
88
|
-
"camelcase": [ "error", { "properties": "always" } ],
|
|
89
|
-
"comma-spacing": [ "error", { "before": false, "after": true } ],
|
|
90
|
-
"comma-style": [ "error", "last" ],
|
|
91
|
-
"computed-property-spacing": [ "error", "never" ],
|
|
92
|
-
"func-style": [ "error", "declaration" ],
|
|
93
|
-
"indent": [ "error", 2, { "SwitchCase": 1 } ],
|
|
94
|
-
"key-spacing": [ "error", { "beforeColon": false, "afterColon": true } ],
|
|
95
|
-
"new-parens": "error",
|
|
96
|
-
"no-lonely-if": "error",
|
|
97
|
-
"no-multiple-empty-lines": [ "error", { "max": 2 } ],
|
|
98
|
-
"no-mixed-spaces-and-tabs": "error",
|
|
99
|
-
"no-nested-ternary": "error",
|
|
100
|
-
"no-spaced-func": "error",
|
|
101
|
-
"no-trailing-spaces": "error",
|
|
102
|
-
"no-unneeded-ternary": "error",
|
|
103
|
-
"object-curly-spacing": [ "error", "always" ],
|
|
104
|
-
"operator-assignment": [ "error", "always" ],
|
|
105
|
-
"operator-linebreak": [ "error", "before" ],
|
|
106
|
-
"padded-blocks": [ "error", "never" ],
|
|
107
|
-
"quote-props": [ "error", "as-needed" ],
|
|
108
|
-
"semi-spacing": [ "error", { "before": false, "after": true } ],
|
|
109
|
-
"space-before-blocks": [ "error", "always" ],
|
|
110
|
-
"space-before-function-paren": [ "error", { "anonymous": "always", "named": "never" } ],
|
|
111
|
-
"space-in-parens": [ "error", "never" ],
|
|
112
|
-
"space-infix-ops": "error",
|
|
113
|
-
"space-unary-ops": [ "error", { "words": true, "nonwords": false } ],
|
|
114
|
-
"spaced-comment": [ "error", "always", { "markers": [ "*" ] } ],
|
|
115
|
-
"arrow-spacing": [ "error", { "before": true, "after": true } ],
|
|
116
|
-
"arrow-parens": [ "error", "as-needed" ],
|
|
117
|
-
"block-spacing": [ "error", "always" ],
|
|
118
|
-
"keyword-spacing": "error"
|
|
119
|
-
}
|
|
120
|
-
}
|
package/circle.yml
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
version: 2
|
|
3
|
-
jobs:
|
|
4
|
-
build:
|
|
5
|
-
docker:
|
|
6
|
-
- image: circleci/node:7.10
|
|
7
|
-
|
|
8
|
-
working_directory: ~/repo
|
|
9
|
-
|
|
10
|
-
steps:
|
|
11
|
-
- checkout
|
|
12
|
-
|
|
13
|
-
- restore_cache:
|
|
14
|
-
keys:
|
|
15
|
-
- v1-dependencies-{{ checksum "package.json" }}
|
|
16
|
-
- v1-dependencies-
|
|
17
|
-
|
|
18
|
-
- run: npm install
|
|
19
|
-
|
|
20
|
-
- save_cache:
|
|
21
|
-
paths:
|
|
22
|
-
- node_modules
|
|
23
|
-
key: v1-dependencies-{{ checksum "package.json" }}
|
|
24
|
-
|
|
25
|
-
# run tests!
|
|
26
|
-
- run: npm run lint
|
|
27
|
-
- run: npm run test-ci
|
package/jsconfig.json
DELETED
package/lib/index.js
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = wilson;
|
|
7
|
-
|
|
8
|
-
var _mathjs = require('mathjs');
|
|
9
|
-
|
|
10
|
-
var _mathjs2 = _interopRequireDefault(_mathjs);
|
|
11
|
-
|
|
12
|
-
var _pnormaldist = require('pnormaldist');
|
|
13
|
-
|
|
14
|
-
var _pnormaldist2 = _interopRequireDefault(_pnormaldist);
|
|
15
|
-
|
|
16
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
|
-
|
|
18
|
-
function wilson(observed, sample) {
|
|
19
|
-
var population = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
20
|
-
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
21
|
-
var _options$confidence = options.confidence,
|
|
22
|
-
confidence = _options$confidence === undefined ? 0.95 : _options$confidence,
|
|
23
|
-
_options$precision = options.precision,
|
|
24
|
-
precision = _options$precision === undefined ? 20 : _options$precision;
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
_mathjs2.default.config({ number: 'BigNumber', precision: precision });
|
|
28
|
-
|
|
29
|
-
observed = _mathjs2.default.bignumber(observed);
|
|
30
|
-
sample = _mathjs2.default.bignumber(sample);
|
|
31
|
-
|
|
32
|
-
var proportion = _mathjs2.default.eval('observed / sample', { observed: observed, sample: sample });
|
|
33
|
-
|
|
34
|
-
if (population) {
|
|
35
|
-
sample = _mathjs2.default.eval('sample / (sqrt(1 - sample / population))', { sample: sample, population: population });
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
var zScore = (0, _pnormaldist2.default)(_mathjs2.default.eval('1 - (1 - confidence) / 2', { confidence: confidence }));
|
|
39
|
-
|
|
40
|
-
return wilsonInterval(proportion, sample, zScore);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function wilsonInterval(proportion, sample, zScore) {
|
|
44
|
-
var scope = {
|
|
45
|
-
p: _mathjs2.default.bignumber(proportion),
|
|
46
|
-
n: _mathjs2.default.bignumber(sample),
|
|
47
|
-
z: _mathjs2.default.bignumber(zScore)
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
var high = _mathjs2.default.format(_mathjs2.default.eval('(p + z * z / (2 * n) + z * sqrt(p * (1 - p) / n + z * z / (4 * (n * n)))) / (1 + z * z / n)', scope));
|
|
51
|
-
|
|
52
|
-
var low = _mathjs2.default.format(_mathjs2.default.eval('(p + z * z / (2 * n) - z * sqrt(p * (1 - p) / n + z * z / (4 * (n * n)))) / (1 + z * z / n)', scope));
|
|
53
|
-
|
|
54
|
-
var center = _mathjs2.default.format(_mathjs2.default.eval('(p + z * z / (2 * n)) / (1 + z * z / n)', scope));
|
|
55
|
-
|
|
56
|
-
return {
|
|
57
|
-
high: high,
|
|
58
|
-
center: center,
|
|
59
|
-
low: low
|
|
60
|
-
};
|
|
61
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
-
|
|
3
|
-
exports[`wilson() accepts options wilson(5, 100, 227, { confidence: 0.9 }) 1`] = `
|
|
4
|
-
Object {
|
|
5
|
-
"center": "0.058925960344442384957",
|
|
6
|
-
"high": "0.090892465800857729375",
|
|
7
|
-
"low": "0.02695945488802704054",
|
|
8
|
-
}
|
|
9
|
-
`;
|
|
10
|
-
|
|
11
|
-
exports[`wilson() accepts options wilson(5, 100, false, { precision: 6 }) 1`] = `
|
|
12
|
-
Object {
|
|
13
|
-
"center": "0.0666474",
|
|
14
|
-
"high": "0.111751",
|
|
15
|
-
"low": "0.0215437",
|
|
16
|
-
}
|
|
17
|
-
`;
|
|
18
|
-
|
|
19
|
-
exports[`wilson() returns accurate results wilson(5, 100) 1`] = `
|
|
20
|
-
Object {
|
|
21
|
-
"center": "0.066647073981204927863",
|
|
22
|
-
"high": "0.11175046869375655694",
|
|
23
|
-
"low": "0.021543679268653298792",
|
|
24
|
-
}
|
|
25
|
-
`;
|
|
26
|
-
|
|
27
|
-
exports[`wilson() returns accurate results wilson(5, 100, 227) 1`] = `
|
|
28
|
-
Object {
|
|
29
|
-
"center": "0.062568829500944323976",
|
|
30
|
-
"high": "0.10110044321850152858",
|
|
31
|
-
"low": "0.024037215783387119365",
|
|
32
|
-
}
|
|
33
|
-
`;
|