wilson-interval 4.0.5 → 5.1.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.
@@ -0,0 +1,11 @@
1
+ # To get started with Dependabot version updates, you'll need to specify which
2
+ # package ecosystems to update and where the package manifests are located.
3
+ # Please see the documentation for all configuration options:
4
+ # https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
5
+
6
+ version: 2
7
+ updates:
8
+ - package-ecosystem: "npm" # See documentation for possible values
9
+ directory: "/" # Location of package manifests
10
+ schedule:
11
+ interval: "weekly"
@@ -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,14 +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
  [![license](https://img.shields.io/github/license/erikfox/wilson-interval.svg)](https://opensource.org/licenses/MIT)
6
4
  [![npm](https://img.shields.io/npm/v/wilson-interval.svg)](https://www.npmjs.com/package/wilson-interval)
7
5
  [![npm](https://img.shields.io/npm/dt/wilson-interval.svg?colorB=32CD32)](https://www.npmjs.com/package/wilson-interval)
8
- [![CircleCI](https://img.shields.io/circleci/project/github/erikfox/wilson-interval.svg?colorB=32CD32)](https://circleci.com/gh/erikfox/wilson-interval/tree/master)
9
- [![Coveralls](https://img.shields.io/coveralls/erikfox/wilson-interval.svg?colorB=32CD32)](https://coveralls.io/github/erikfox/wilson-interval)
10
-
11
-
6
+ [![codecov](https://codecov.io/github/erikfox/wilson-interval/graph/badge.svg?token=R0A2KJQWU6)](https://codecov.io/github/erikfox/wilson-interval)
12
7
  [![Pull Requests Welcome](https://img.shields.io/badge/pull_requests-welcome-FF69B4.svg)]()
13
8
  [![](https://img.shields.io/github/issues-raw/erikfox/wilson-interval.svg?colorB=FF69B4)](https://github.com/erikfox/wilson-interval/issues)
14
9
 
@@ -30,20 +25,15 @@ import wilson from 'wilson-interval';
30
25
 
31
26
  ## Usage
32
27
 
33
- ### wilson(observed, sample[, population ][, options ]);
28
+ ### wilson(observed, sample[, population ][, confidence ]);
34
29
 
35
- - `observed` - Number of observed positive outcomes.
36
-
37
- - `sample` - Size of sample.
30
+ - `observed` - Required, accepts `Number >= 0`. Count of observed positive outcomes as a whole number.
31
+ - `sample` - Required, accepts `Number > 0`. Size of sample as a whole number.
38
32
 
39
33
  Optional arguments:
40
34
 
41
- - `population` - Default `false`. Total population from which sample was taken (to use **[Singleton's adjustment](https://corplingstats.wordpress.com/2012/04/30/inferential-statistics/)**<sup>[1]</sup>).
42
-
43
- - `options` - Default `{}`. Options object. Available parameters:
44
-
45
- - `confidence` - Default `0.95`. Desired confidence level of interval.
46
- - `precision` - Default `20`. Number of significant figures to use in calculations and output.
35
+ - `population` - Default `null`, accepts `Number > 0`. Total population from which sample was taken (to use **[Singleton's adjustment](https://corplingstats.wordpress.com/2012/04/30/inferential-statistics/)**<sup>[1]</sup>). Must be a positive whole number.
36
+ - `confidence` - Default `0.95`, accepts `1 > Number > 0`. Desired confidence level of interval as a fractional decimal value between 0 and 1.
47
37
 
48
38
  #### Example
49
39
  ```js
@@ -52,9 +42,9 @@ return wilson(5, 100);
52
42
  returns
53
43
  ```json
54
44
  {
55
- "center": "0.066647073981204927863",
56
- "high": "0.11175046869375655694",
57
- "low": "0.021543679268653298792",
45
+ "center": 0.06664707421899263,
46
+ "high": 0.11175046929755608,
47
+ "low": 0.02154367914042918
58
48
  }
59
49
  ```
60
50
 
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,13 +1,13 @@
1
1
  {
2
2
  "name": "wilson-interval",
3
- "version": "4.0.5",
4
- "author": "Erik Fox <erik@erikfox.co> (http://erikfox.co)",
3
+ "version": "5.1.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",
8
8
  "repository": {
9
9
  "type": "git",
10
- "url": "https://github.com/erikfox/wilson-interval.git"
10
+ "url": "git+https://github.com/erikfox/wilson-interval.git"
11
11
  },
12
12
  "bugs": {
13
13
  "url": "https://github.com/erikfox/wilson-interval/issues"
@@ -25,29 +25,16 @@
25
25
  "upvotes",
26
26
  "downvotes"
27
27
  ],
28
- "main": "./lib/index.js",
29
- "scripts": {
30
- "dev": "npm run build -- --watch & npm test -- --watchAll & wait",
31
- "build": "babel ./src/index.js --out-file ./lib/index.js",
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"
28
+ "engines": {
29
+ "node": ">=18.0.0"
36
30
  },
37
- "dependencies": {
38
- "mathjs": "^5.10.0",
39
- "pnormaldist": "^1.0.0"
31
+ "type": "module",
32
+ "main": "./src/index.js",
33
+ "exports": {
34
+ ".": "./src/index.js"
40
35
  },
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"
36
+ "scripts": {
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"
52
39
  }
53
40
  }
package/src/index.js CHANGED
@@ -1,49 +1,36 @@
1
- import math from 'mathjs';
2
- import pnormaldist from 'pnormaldist';
1
+ export default function wilson(observed, sample, population = null, confidence = 0.95) {
2
+ observed = Number(observed);
3
+ sample = Number(sample);
4
+ confidence = Number(confidence);
3
5
 
4
- export default function wilson(observed, sample, population = false, options = {}) {
5
- const {
6
- confidence = 0.95,
7
- precision = 20,
8
- } = options;
9
-
10
- math.config({ number: 'BigNumber', precision });
11
-
12
- observed = math.bignumber(observed);
13
- sample = math.bignumber(sample);
14
-
15
- const proportion = math.eval('observed / sample', { observed, sample });
16
-
17
- if (population) {
18
- sample = math.eval('sample / (sqrt(1 - sample / population))', { sample, population });
6
+ if (observed < 0) {
7
+ throw new Error('Observed must be a non-negative whole number');
19
8
  }
20
9
 
21
- const zScore = pnormaldist(math.eval('1 - (1 - confidence) / 2', { confidence }));
10
+ if (sample <= 0) {
11
+ throw new Error('Sample must be a positive whole number');
12
+ }
22
13
 
23
- return wilsonInterval(proportion, sample, zScore);
24
- }
14
+ if (confidence <= 0 || confidence >= 1) {
15
+ throw new Error('Confidence must be a decimal between 0 and 1');
16
+ }
25
17
 
26
- function wilsonInterval(proportion, sample, zScore) {
27
- const scope = {
28
- p: math.bignumber(proportion),
29
- n: math.bignumber(sample),
30
- z: math.bignumber(zScore),
31
- };
18
+ if (Number.isSafeInteger(population)) {
19
+ if (population <= 0) {
20
+ throw new Error('Population must be a positive whole number');
21
+ }
22
+ sample = sample / Math.sqrt(1 - sample / population);
23
+ }
32
24
 
33
- const high = math.format(math.eval(
34
- '(p + z * z / (2 * n) + z * sqrt(p * (1 - p) / n + z * z / (4 * (n * n)))) / (1 + z * z / n)',
35
- scope,
36
- ));
25
+ const zScore = normalQuantile(1 - (1 - confidence) / 2);
37
26
 
38
- const low = math.format(math.eval(
39
- '(p + z * z / (2 * n) - z * sqrt(p * (1 - p) / n + z * z / (4 * (n * n)))) / (1 + z * z / n)',
40
- scope,
41
- ));
27
+ const p = observed / sample;
28
+ const n = sample;
29
+ const z = zScore;
42
30
 
43
- const center = math.format(math.eval(
44
- '(p + z * z / (2 * n)) / (1 + z * z / n)',
45
- scope,
46
- ));
31
+ const high = ((p + z * z / (2 * n) + z * Math.sqrt(p * (1 - p) / n + z * z / (4 * n * n))) / (1 + z * z / n));
32
+ const low = ((p + z * z / (2 * n) - z * Math.sqrt(p * (1 - p) / n + z * z / (4 * n * n))) / (1 + z * z / n));
33
+ const center = ((p + z * z / (2 * n)) / (1 + z * z / n));
47
34
 
48
35
  return {
49
36
  high,
@@ -51,3 +38,66 @@ function wilsonInterval(proportion, sample, zScore) {
51
38
  low,
52
39
  };
53
40
  }
41
+
42
+ // Returns the quantile (inverse CDF) for the standard normal distribution
43
+ export function normalQuantile(p) {
44
+ if (p < 0 || p > 1) {
45
+ throw new Error('The probability p must be between 0 and 1');
46
+ }
47
+ if (p === 0) return -Infinity;
48
+ if (p === 1) return Infinity;
49
+
50
+ // Coefficients in rational approximations
51
+ const a = [
52
+ -3.969683028665376e+01,
53
+ 2.209460984245205e+02,
54
+ -2.759285104469687e+02,
55
+ 1.383577518672690e+02,
56
+ -3.066479806614716e+01,
57
+ 2.506628277459239e+00
58
+ ];
59
+ const b = [
60
+ -5.447609879822406e+01,
61
+ 1.615858368580409e+02,
62
+ -1.556989798598866e+02,
63
+ 6.680131188771972e+01,
64
+ -1.328068155288572e+01
65
+ ];
66
+ const c = [
67
+ -7.784894002430293e-03,
68
+ -3.223964580411365e-01,
69
+ -2.400758277161838e+00,
70
+ -2.549732539343734e+00,
71
+ 4.374664141464968e+00,
72
+ 2.938163982698783e+00
73
+ ];
74
+ const d = [
75
+ 7.784695709041462e-03,
76
+ 3.224671290700398e-01,
77
+ 2.445134137142996e+00,
78
+ 3.754408661907416e+00
79
+ ];
80
+
81
+ // Define break-points
82
+ const plow = 0.02425;
83
+ const phigh = 1 - plow;
84
+
85
+ let q, r;
86
+ if (p < plow) {
87
+ // Rational approximation for lower region
88
+ q = Math.sqrt(-2 * Math.log(p));
89
+ return (((((c[0]*q + c[1])*q + c[2])*q + c[3])*q + c[4])*q + c[5]) /
90
+ ((((d[0]*q + d[1])*q + d[2])*q + d[3])*q + 1);
91
+ } else if (phigh < p) {
92
+ // Rational approximation for upper region
93
+ q = Math.sqrt(-2 * Math.log(1 - p));
94
+ return -(((((c[0]*q + c[1])*q + c[2])*q + c[3])*q + c[4])*q + c[5]) /
95
+ ((((d[0]*q + d[1])*q + d[2])*q + d[3])*q + 1);
96
+ } else {
97
+ // Rational approximation for central region
98
+ q = p - 0.5;
99
+ r = q * q;
100
+ return (((((a[0]*r + a[1])*r + a[2])*r + a[3])*r + a[4])*r + a[5])*q /
101
+ (((((b[0]*r + b[1])*r + b[2])*r + b[3])*r + b[4])*r + 1);
102
+ }
103
+ }
package/src/index.test.js CHANGED
@@ -1,27 +1,111 @@
1
- import wilson from '.';
1
+ import wilson, { normalQuantile } 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('returns accurate results', () => {
7
+ describe('handles base args', () => {
5
8
  test('wilson(5, 100)', () => {
6
9
  const result = wilson(5, 100);
7
- expect(result).toMatchSnapshot();
10
+
11
+ assert.deepEqual(result, {
12
+ center: 0.06664707421899263,
13
+ high: 0.11175046929755608,
14
+ low: 0.02154367914042918
15
+ });
8
16
  });
9
17
 
18
+ test('wilson(-1, 100)', () => {
19
+ assert.throws(() => wilson(-1, 100), {
20
+ message: 'Observed must be a non-negative whole number'
21
+ });
22
+ });
23
+
24
+ test('wilson(5, 0)', () => {
25
+ assert.throws(() => wilson(5, 0), {
26
+ message: 'Sample must be a positive whole number'
27
+ });
28
+ });
29
+ });
30
+
31
+ describe('handles population arg', () => {
10
32
  test('wilson(5, 100, 227)', () => {
11
33
  const result = wilson(5, 100, 227);
12
- expect(result).toMatchSnapshot();
34
+
35
+ assert.deepEqual(result, {
36
+ center: 0.050319696641804315,
37
+ high: 0.08456089359579015,
38
+ low: 0.016078499687818482
39
+ });
40
+ });
41
+
42
+ test('wilson(5, 100, 0)', () => {
43
+ assert.throws(() => wilson(5, 100, 0), {
44
+ message: 'Population must be a positive whole number'
45
+ });
13
46
  });
14
47
  });
15
48
 
16
- describe('accepts options', () => {
17
- test('wilson(5, 100, false, { precision: 6 })', () => {
18
- const result = wilson(5, 100, false, { precision: 6 });
19
- expect(result).toMatchSnapshot();
49
+ describe('handles confidence arg', () => {
50
+ test('wilson(5, 100, 227, 0.9)', () => {
51
+ const result = wilson(5, 100, 227, 0.9);
52
+
53
+ assert.deepEqual(result, {
54
+ center: 0.04657481789797846,
55
+ high: 0.0748286439672683,
56
+ low: 0.018320991828688626
57
+ });
20
58
  });
21
59
 
22
- test('wilson(5, 100, 227, { confidence: 0.9 })', () => {
23
- const result = wilson(5, 100, 227, { confidence: 0.9 });
24
- expect(result).toMatchSnapshot();
60
+ test('wilson(5, 100, 227, 1)', () => {
61
+ assert.throws(() => wilson(5, 100, 227, 1), {
62
+ message: 'Confidence must be a decimal between 0 and 1'
63
+ });
25
64
  });
26
65
  });
27
66
  });
67
+
68
+ describe('normalQuantile()', () => {
69
+ describe('handles base args', () => {
70
+ test('normalQuantile(0.95)', () => {
71
+ const result = normalQuantile(0.95);
72
+ assert.strictEqual(result, 1.644853625133699);
73
+ });
74
+
75
+ test('normalQuantile(0.01)', () => {
76
+ const result = normalQuantile(0.01);
77
+ assert.strictEqual(result, -2.326347874388028);
78
+ });
79
+
80
+ test('normalQuantile(0.99)', () => {
81
+ const result = normalQuantile(0.99);
82
+ assert.strictEqual(result, 2.326347874388028);
83
+ });
84
+ });
85
+
86
+ describe('handles edge cases', () => {
87
+ test('normalQuantile(0)', () => {
88
+ const result = normalQuantile(0);
89
+ assert.strictEqual(result, -Infinity);
90
+ });
91
+
92
+ test('normalQuantile(1)', () => {
93
+ const result = normalQuantile(1);
94
+ assert.strictEqual(result, Infinity);
95
+ });
96
+ });
97
+
98
+ describe('throws on invalid args', () => {
99
+ test('normalQuantile(-1)', () => {
100
+ assert.throws(() => normalQuantile(-1), {
101
+ message: 'The probability p must be between 0 and 1'
102
+ });
103
+ });
104
+
105
+ test('normalQuantile(2)', () => {
106
+ assert.throws(() => normalQuantile(2), {
107
+ message: 'The probability p must be between 0 and 1'
108
+ });
109
+ });
110
+ });
111
+ });
package/.babelrc DELETED
@@ -1,5 +0,0 @@
1
- {
2
- "presets": [
3
- "env"
4
- ]
5
- }
package/.coveralls.yml DELETED
@@ -1 +0,0 @@
1
- repo_token: 3QLq1SKbTjP1d5Dk7rO7oXKYouGbUfuxy
package/.eslintignore DELETED
@@ -1,3 +0,0 @@
1
- node_modules
2
- lib
3
- coverage
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
@@ -1,11 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "baseUrl": ".",
4
- "paths": {
5
- "*": [
6
- "*",
7
- "src/*"
8
- ]
9
- }
10
- }
11
- }
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
- `;