A leading digit is the first significant digit of a number. In a first-digit analysis, it is one of 1 through 9: an initial zero does not count. Benford’s law predicts that, in many suitable numeric data sets, smaller leading digits occur more often than larger ones. A leading 1 has probability about 30.1%; a leading 9, about 4.6%. The digits are not expected to be equally frequent. section 12.1
For digit d from 1 to 9, the expected proportion is P(d) = log10(1 + 1/d). This logarithmic pattern is most useful for naturally occurring quantities spread across several orders of magnitude without preset minimum and maximum values. Identifiers and bounded scores are poor candidates. Before interpreting a mismatch, check whether the data plausibly belongs to a population where Benford’s law applies. section 12.1 section 12.6
>>> import numpy as np >>> df1 = df1.assign(benford = round(np.log10(1 + (1 / df1.d)), 3)) >>> print(df1) d benford 0 1 0.301 1 2 0.176 2 3 0.125 3 4 0.097 4 5 0.079 5 6 0.067 6 7 0.058 7 8 0.051 8 9 0.046
The calculated probabilities for digits 1–9 provide a direct reference for comparing observed leading-digit frequencies. section 12.1
A practical first-digit check has four stages:
- Inspect the numeric field and extract its first digit. For positive values, a simple pandas approach is `df['first_digit'] = df['value'].apply(lambda x: str(x)[0])`. Inspect the resulting values: address records, for example, can begin with letters. section 12.4.1
- Keep valid digits 1–9 and convert them to integers. A string-first-character approach extracts `-` from negative payments and `0` from zero payments, so those records need deliberate handling before analysis. section 12.4.1 section 12.4.3
- Count each digit, divide by the retained record count, and compare observed proportions with Benford’s expected proportions. Plotting both distributions is a useful first check, not a statistical conclusion. section 12.4 section 12.5
- Validate an apparent match or mismatch. For a chi-square goodness-of-fit test, multiply each expected proportion by the record count to obtain its expected count, then compare expected and observed counts. section 12.5.1
Population counts: looking beyond the chart
For 235 country and territory population counts from 2020, leading digits 1–3 make up 58.3% of observations, versus 60.2% under a perfect Benford distribution. A chi-square test comparing counts for all nine digits gives a statistic of about 7.193 and a p-value of about 0.516. At a 5% threshold, this does not provide grounds to reject the Benford model; it does not prove perfect conformity. The result depends on both the observed counts and the expected counts, not just the chart’s appearance. section 12.4.2 section 12.5.1
Leading-digit checks can flag irregularities in payments, expenses, and other suitable data. A substantial deviation is a reason to investigate, not proof of fraud. Conversely, a visually close fit should not end validation: use statistical checks where appropriate and avoid basing a consequential conclusion on one test alone. section 12.0 section 12.6
