benford-law
Version:
A simple library to check if a dataset follows the Benford's law
28 lines (27 loc) • 1.41 kB
TypeScript
/**
* Generates a single random number that follows Benford's Law
* Uses logarithmic distribution to ensure first digits follow Benford's Law
* @returns A number between 1 and 1000 following Benford's Law
*/
export declare const generateBenfordLawNumber: () => number;
/**
* Generates an array of random numbers that follow Benford's Law
* @param length - The number of random numbers to generate (must be > 0)
* @returns An array of numbers following Benford's Law
* @throws Error if length is not a positive integer
*/
export declare const generateBenfordLawNumbers: (length: number) => number[];
/**
* Analyzes a dataset to determine if it follows Benford's Law
* @param numbers - Array of positive numbers to analyze
* @param threshold - Maximum acceptable deviation from Benford's probabilities (default: 0.01)
* @param benfordProbabilities - Expected probabilities for each first digit (default: standard Benford)
* @returns Analysis results including whether the dataset follows Benford's Law
* @throws Error if the array is empty or contains invalid numbers
*/
export declare const processBenfordLaw: (numbers: number[], threshold?: number, benfordProbabilities?: Record<string, number>) => {
isFollowingBenfordLaw: boolean;
firstDigitCounts: Record<string, number>;
firstDigitProbabilities: Record<string, number>;
firstDigitAccuracies: Record<string, number>;
};