Benford check

Method and sources

What is computed, the constant behind each verdict and where it was published, and how the results were checked. All of it runs in the browser from js/benford.js and js/engine.js.

Reading an amount

Each cell is read as text. Thousands separators (comma, dot, space, no-break space, apostrophe), currency symbols and three-letter codes are ignored; negatives may be written -48.20, 48.20-, (48.20) or with the minus sign. The decimal mark is detected from the column (whether the last separator is followed by three digits, and whether a separator repeats) and can be set by hand. Cells that are dates, times or codes are counted as “not numbers” and left out, with an example shown.

The significant digits are taken from the written number, not from its binary value. This matters below 1: in floating point 0.29 × 100 is 28.999999999999996, so a program that truncates the product files 0.29 under the digits 28. Zero is always left out. Amounts below 10 are left out by default.

The digit tests

For a test with digit groups d, observed share APd of the N amounts tested, and expected share EPd:

TestGroupsExpected share
First digit1–9log10(1 + 1/d)
Second digit0–9Σk=1..9 log10(1 + 1/(10k + d))
First two digits10–99log10(1 + 1/d)
Last two digits00–991/100

The first three formulas are Benford’s (1938). The last-two digits test is Nigrini’s (2012), who uses it to find rounding and invented numbers. Here it takes the last two digits of the whole-number part, for amounts of 1,000 and over only; that choice is this tool’s, made so that the two digits are the third digit or later, which Benford’s law itself expects to be nearly uniform (the third digit ranges from 10.18% for 0 to 9.83% for 9). Below 1,000 the tens digit is the second digit, which is not uniform.

Mean absolute deviation and its ranges

MAD = (1/K) · Σd |APd − EPd|, K = number of digit groups

Nigrini (2012, Table 7.1, p. 160) gives four conformity ranges for the MAD, building on Drake & Nigrini (2000). The tool uses them as published; a MAD equal to a bound falls in the range above it, as in the R package benford.analysis.

TestClose conformityAcceptableMarginally acceptableNonconformity
First digit0.000–0.0060.006–0.0120.012–0.015above 0.015
Second digit0.000–0.0080.008–0.0100.010–0.012above 0.012
First two digits0.0000–0.00120.0012–0.00180.0018–0.0022above 0.0022
Last two digitsno published range; the tool reports the MAD, chi-square and Z-scores without a verdict

The R package benford.analysis 0.1.5 codes the second-digit upper bound as 0.011 in MAD.conformity(); its benford() function never uses that row. This tool uses Nigrini’s 0.012.

The MAD does depend on the sample size: even data drawn from Benford’s law itself has an expected MAD of about (1/K) · Σ √(2·EPd(1 − EPd) / (π N)), which shrinks as 1/√N (Cerqueti & Lupi 2022). The tool prints that figure as “MAD by chance alone” under each test, so a small file’s verdict can be read in proportion.

Z-statistic for each digit

Z = ( |AP − EP| − 1/(2N) ) / √( EP(1 − EP) / N )

As in Nigrini (2012), the continuity correction 1/(2N) is subtracted only when it is smaller than |AP − EP|. A digit is marked over-represented when AP > EP and Z > 2.576 (two-sided 1% level); 1.96 is the 5% level. The sign shown in the tables is the sign of AP − EP.

Chi-square and Kolmogorov–Smirnov

χ² = Σd (Od − Ed)² / Ed, df = K − 1; D = maxd |cumulative AP − cumulative EP|, 5% critical value 1.36/√N

The p-value is the upper regularised incomplete gamma function Q(df/2, χ²/2), computed with a series and a continued fraction. Both tests are shown for completeness, with a caveat: their power grows with N, so on a large file they reject Benford for deviations of no practical size (Kossovsky 2021; Cerqueti & Lupi 2022). That is the reason Nigrini judges conformity by the MAD.

Summation test

The amounts are summed within each first-two-digit group. If the data follow Benford, each of the 90 groups carries the same share of the total, 1/90 (Nigrini 2012). A group far above that holds a few very large amounts or many of one size. There is no published cut-off; the chart marks groups above twice 1/90 and the table ranks the five largest.

Number duplication test

Counts how often each exact amount occurs among the amounts tested and ranks them (Nigrini 2012). The test makes no assumption about digits; it is the quickest way to explain a spike.

Drill-down and export

Selecting a digit, a summation group or an amount selects exactly the rows counted in it. The export writes those rows as they were in the file, with a first column source_row giving the data row number (1 = first row under the header), in the file’s own delimiter, UTF-8 with a byte-order mark so Excel opens it correctly.

How it was checked

Last run 2026-11-05: 42 of 42 Node tests and 28 of 28 phone checks passed. The suite is in tests/; tests/run_all.sh runs all of it.

Expected proportions

The first-digit, second-digit, first-two and last-two distributions are checked against Benford’s formula written a second way (as differences of logarithms, and as marginals of the first-two-digit distribution) to 1e-12, against R’s p.these.digits to 1e-12, and against the 5-decimal table printed in the literature. Each sums to 1 within 1e-12.

Same data, same answers as R

The R package benford.analysis 0.1.5 (R version 4.4.1 (2024-06-14)) was run in a container on two datasets it ships: corporate.payment (189,470 payments of a division of a West Coast utility in 2010) and census.2009 (populations of 19,509 US towns and cities, July 2009), both documented by the package as from Nigrini (2012). R keeps all positive values (or all non-zero values, as absolute values, with sign = "both") and does not drop amounts below 10, so the comparison does the same. Bin counts, MAD, chi-square, its p-value, the conformity verdict, the summation sums and the ten most duplicated amounts were compared for each case.

DataSignsTestNMAD in RMAD hereVerdict (both)χ² in Rχ² hereRows read differently
corporate.paymentpositiveFirst digit185,0830.0132114050.013211405Marginally acceptable conformity4317.274317.270
corporate.paymentbothFirst digit189,3470.0131787420.013178742Marginally acceptable conformity4393.344393.340
census.2009positiveFirst digit19,5090.0031192610.003119261Close conformity17.5217.520
corporate.paymentpositiveFirst two185,0830.0023366140.002336614Nonconformity32094.3532100.90146
corporate.paymentbothFirst two189,3470.0023361080.002336108Nonconformity31890.1731908.84146
census.2009positiveFirst two19,5090.0006134140.000613414Close conformity107.16107.160
corporate.paymentpositiveFirst three185,0830.0004569100.000456673Marginally acceptable conformity369052.79368873.20441
corporate.paymentbothFirst three189,3470.0004584910.000458336Marginally acceptable conformity366999.27366804.31455
census.2009positiveFirst three19,5090.0002120100.000212010Close conformity1831.461831.460

Applying R’s own digit rule to the same parsed values reproduces R’s bin counts exactly in all 9 cases, the MAD to within 1e-15, the chi-square and summation sums to 1e-12 and 1e-9 relative, the p-value to 1e-9 relative, and the same verdict. With this tool’s rule (digits read from the written number), the verdicts are unchanged; the MAD and chi-square differ slightly on the rows counted in the last column. The test checks that every one of them is a floating-point case: R computes the digits as trunc(10k−1−floor(log10 x) · x), and for an amount like 0.29 the product is 28.999999999999996, so R files it one digit group too low; this tool reads 29 from the text. On the full first-two digits test of corporate.payment both give MAD 0.002337, nonconformity, as the package’s own printed output shows.

Known answers on synthetic data

Speed

On a phone

At 390 × 844 the page opens with the sample, draws the five charts, opens the drill-down for 48 when its bar is tapped, and exports those rows; it also loads an XLSX with two sheets and a decimal-comma column, and a pasted column. No horizontal overflow, no script errors, no failed requests (28 of 28 checks).

Sources

The explanations on this site are written for it and do not reproduce the text of these works.