|
4 months ago | |
---|---|---|
.github | 5 months ago | |
coverage | 5 months ago | |
dist | 5 months ago | |
src | 5 months ago | |
.drone.yml | 5 months ago | |
.eslintignore | 5 months ago | |
.eslintrc.js | 5 months ago | |
.gitignore | 5 months ago | |
LICENSE | 5 months ago | |
README.md | 4 months ago | |
commitlint.config.js | 5 months ago | |
jest.config.js | 5 months ago | |
package.json | 5 months ago | |
tsconfig.json | 5 months ago |
Check if a number array confirms to the Benford's Law
Heavily inspired by https://github.com/target/huntlib
npm i benfordslaw
Look at the tests for good examples.
E.g.:
import { BenfordsLaw } from 'benfordslaw';
const numbers = [1,2,3,4,5,6,7,8,9];
const benfords = new BenfordsLaw(numbers);
const chiSquared = benfords.getChiSquared();
// chiSquared = 0.40105320411553363
const probability = benfords.getProbability()?.toFixed(1);
// probability = 1.0
The ChiSquared result is a float and describes how well Benford's Law was matched. Lower is better.
The Probability describes how relevant ChiSquared is. It should be >= 0.9
getDist() returns the distribution of the numbers.
With Types TypeScript adds a extra layer of security. I also use mainly TypeScript projects with this project so TypeScript just makes sense. And TS also compiles to JavaScript Code so JS projects also can use it.
License: MIT
Author: Christoph Daniel Miksche