Title
mm_benford() -- Benford's Law (distribution of digits)
Syntax
real vector mm_benford(digits [, position, base])
where
digits: real vector providing the digits for which the probabilities be computed; the digits must be in {0,...,base-1}
position: real scalar specifying the position of the digits
base: real scalar specifying the base of the numeric system
Description
mm_benford() returns the probabilities of the specified digits according to Benford's Law (Newcomb 1881, Benford 1938, Hill 1998). The formula for the 1st (leading) digit in the base 10 number system is:
P(d) = log10(1 + 1/d)
with d in {1,...,9}.
The general formula for the p-th digit in the base b number system is
b^(p-1) - 1 --- 1 \ + 1 + P(d, p, b) = ----- ln|1 + ----- | ln(b) / + k*b+d + --- k = b^(p-2)
with d in {0,...,b-1} (see, e.g., http://www.mathpages.com/home/kmath302/kmath302.htm).
The limit of P(d) with rising p is 1/b. Computation becomes exceedingly intensive with rising p since the number of operations is in the order of b^p - b^(p-1).
Remarks
Examples
Fist digit Benford distribution:
: (1::9), mm_benford(1::9) 1 2 +-----------------------------+ 1 | 1 .3010299957 | 2 | 2 .1760912591 | 3 | 3 .1249387366 | 4 | 4 .096910013 | 5 | 5 .079181246 | 6 | 6 .0669467896 | 7 | 7 .057991947 | 8 | 8 .0511525224 | 9 | 9 .0457574906 | +-----------------------------+ Second digit Benford distribution:
: (0::9), mm_benford(0::9,2) 1 2 +-----------------------------+ 1 | 0 .1196792686 | 2 | 1 .1138901034 | 3 | 2 .108821499 | 4 | 3 .1043295602 | 5 | 4 .1003082023 | 6 | 5 .0966772358 | 7 | 6 .0933747358 | 8 | 7 .0903519893 | 9 | 8 .0875700536 | 10 | 9 .0849973521 | +-----------------------------+
Second digit Benford distribution in base 6:
: (0::5), mm_benford(0::5,2,6) 1 2 +-----------------------------+ 1 | 0 .2019648465 | 2 | 1 .1841218513 | 3 | 2 .1697091954 | 4 | 3 .1577441976 | 5 | 4 .1476009617 | 6 | 5 .1388589474 | +-----------------------------+
Conformability
mm_benford(digits, position, base): digits: r x 1 or 1 x c position: 1 x 1 base: 1 x 1 result: r x 1 or 1 x c.
Diagnostics
mm_benford(0,1,base) evaluates to missing.
Source code
mm_benford.mata
References
Benford, Frank (1938). The law of anomalous numbers. Proceedings of the American Philosophical Society 78: 551–572.
Hill, Theodore P. (1998). The first digit phenomenon. American Scientist 86: 358.
Newcomb, Simon (1881). Note on the frequency of use of the different digits in natural numbers. American Journal of Mathematics 4: 39–40.
Author
Ben Jann, ETH Zurich, jann@soz.gess.ethz.ch
Also see
Online: help for [M-4] statistical, moremata