zigne
v0.0.9
Published
Calculate statistical significance (z-test), for e.g. polls.
Downloads
211
Readme
zigne
Simple utilities to calculate statistical significance and confidence intervals. Made in the context of multi-party election polling where you may want to check if the difference between two population proportions are significant.
Installation
$ npm install zigne
or
$ yarn add zigne
Usage
import zigne from 'zigne';
// Check if diff between two items change is significant
const itemLeft = zigne.item({ name: 'A', percentage: 25.8, sampleSize: 977 });
const itemRight = zigne.item({ name: 'A', percentage: 20.1, sampleSize: 980 });
const comparison = itemLeft.compare(itemRight, {
test: 'twoTailed',
confidenceLevel: 95,
});
comparison.significant; //=> true
comparison.marginOfError; //=> 3.12
comparison.difference; //=> -5.6...
// Compare two series
const seriesLeft = zigne.series({ sampleSize: 1000 });
const seriesRight = zigne.series({ sampleSize: 980 });
seriesLeft.add({ name: 'A', percentage: 25.8 });
seriesLeft.add({ name: 'B', percentage: 13.8 });
seriesLeft.add({ name: 'C', percentage: 2.2 });
seriesRight.add({ name: 'A', percentage: 29.8 });
seriesRight.add({ name: 'B', percentage: 11.8 });
seriesRight.add({ name: 'C', percentage: 1.2 });
const seriesComparison = seriesLeft.compare(seriesRight, {
test: 'oneTailed',
confidenceLevel: 95,
});
seriesComparison.A.significant; //=> true
seriesComparison.B.significant; //=> false
seriesComparison.C.significant; //=> true
Development
$ yarn install
$ yarn tdd