Benford First-Digit Test Across Vendor Payment Populations
Last updated: November 29, 2026
Quick Overview
Write a Python function that runs a Benford's law first-digit test on a population of payment amounts and, grouped by vendor, ranks vendors by how far their leading-digit distribution departs from Benford's expected frequencies.
PwC
November 29, 20260
0
0 solved
Write a Python function that runs a Benford's law first-digit test on a population of payment amounts and, grouped by vendor, ranks vendors by how far their leading-digit distribution departs from Benford's expected frequencies.
Audit analytics teams at PwC run full-population tests over client AP and GL extracts rather than sampling, and Benford analysis is a classic first screen for fabricated or threshold-gamed amounts. The interviewer checks that you extract leading digits robustly, pick a sensible conformity statistic, and know when the test is not valid.
What the Interviewer Expects
- Extract the leading significant digit correctly for decimals, negatives and zeros
- Compare observed proportions to $\log_{10}(1 + 1/d)$
- Use a size-robust statistic such as mean absolute deviation, not only chi-square
- Enforce a minimum population size per group
- Explain populations where Benford should not apply
Key Topics to Cover
How to Approach This
- Clarify the schema and expected output format before writing queries.
- Use CTEs (WITH clauses) to break complex queries into readable steps.
- Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
- Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
- For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
- Why does chi-square flag almost everything on a million-row population?
- How would you extend this to the first-two-digits test?
- Which kinds of amounts (fixed fees, capped reimbursements) violate Benford by design?
- How do you turn a nonconforming vendor into specific invoices to pull?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice SQL ProblemsSample Answer
Clarify the Data
Input is (vendor, amount) records from an AP extract. Amounts can be negative (credit notes), zero, or fractional. I treat sign as irrelevant, drop zeros, and only test vendors with at least 100 pay...
Approach
Benford's expected share for leading digit is , so about 30.1% of amounts should start with 1 and 4.6% with 9. For each vendor I count leading digits, then compute chi-s...