Skip to content

Commit

Permalink
allow populationSize = null
Browse files Browse the repository at this point in the history
  • Loading branch information
jarib committed May 20, 2019
1 parent 2bee51c commit 4df0049
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 33 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ seriesComparison.C.significant; //=> true
### Development

$ yarn install
$ yarn test:watch
$ yarn tdd

### Credits

Expand Down
56 changes: 28 additions & 28 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
{
"name": "zigne",
"version": "0.0.7",
"description": "Calculate statistical significance.",
"main": "./dist/zigne.node.js",
"browser": "./dist/zigne.browser.js",
"repository": "https://github.com/jarib/zigne",
"author": "[email protected]",
"license": "MIT",
"scripts": {
"build": "NODE_ENV=production webpack",
"prepare": "yarn build",
"test": "NODE_ENV=test jest src/*.test.js",
"test:watch": "NODE_ENV=test jest --watch src/*.test.js"
},
"files": [
"dist"
],
"devDependencies": {
"@babel/core": "^7.4.4",
"@babel/plugin-proposal-object-rest-spread": "^7.4.4",
"@babel/preset-env": "^7.4.4",
"babel-jest": "^24.8.0",
"babel-loader": "^8.0.6",
"jest": "^24.8.0",
"regenerator-runtime": "^0.11.1",
"webpack": "^4.1.1",
"webpack-cli": "^3.3.2"
}
"name": "zigne",
"version": "0.0.7",
"description": "Calculate statistical significance.",
"main": "./dist/zigne.node.js",
"browser": "./dist/zigne.browser.js",
"repository": "https://github.com/jarib/zigne",
"author": "[email protected]",
"license": "MIT",
"scripts": {
"build": "NODE_ENV=production webpack",
"prepare": "yarn build",
"test": "NODE_ENV=test jest src/*.test.js",
"tdd": "NODE_ENV=test jest --watch src/*.test.js"
},
"files": [
"dist"
],
"devDependencies": {
"@babel/core": "^7.4.4",
"@babel/plugin-proposal-object-rest-spread": "^7.4.4",
"@babel/preset-env": "^7.4.4",
"babel-jest": "^24.8.0",
"babel-loader": "^8.0.6",
"jest": "^24.8.0",
"regenerator-runtime": "^0.11.1",
"webpack": "^4.1.1",
"webpack-cli": "^3.3.2"
}
}
5 changes: 3 additions & 2 deletions src/Series.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,9 @@ export class Item {
}

if (
(populationSize && populationSize < left.sampleSize) ||
populationSize < right.sampleSize
populationSize &&
(populationSize < left.sampleSize ||
populationSize < right.sampleSize)
) {
throw new Error('population size must be greater than sample size');
}
Expand Down
35 changes: 33 additions & 2 deletions src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,39 @@ test('it compares two values from the same sample (A)', () => {
test('it compares two values from the same sample (B)', () => {
const sampleSize = 220;

const Kåre = zigne.item({ name: 'Kåre', percentage: 58, sampleSize });
const Gro = zigne.item({ name: 'Gro', percentage: 42, sampleSize });
const Kåre = zigne.item({
name: 'Kåre',
percentage: 58,
sampleSize,
});

const Gro = zigne.item({
name: 'Gro',
percentage: 42,
sampleSize,
});
const diff = Kåre.compare(Gro, { sameSample: true, test: 'oneTailed' });

expect(diff.marginOfError).toBeCloseTo(12.27, 1);
expect(diff.significant).toBe(true);
});

test('it ignores population size if null', () => {
const sampleSize = 220;

const Kåre = zigne.item({
name: 'Kåre',
percentage: 58,
sampleSize,
populationSize: null,
});

const Gro = zigne.item({
name: 'Gro',
percentage: 42,
sampleSize,
populationSize: null,
});
const diff = Kåre.compare(Gro, { sameSample: true, test: 'oneTailed' });

expect(diff.marginOfError).toBeCloseTo(12.27, 1);
Expand Down

0 comments on commit 4df0049

Please sign in to comment.