bdig() takes the first nd significant digits of each value. With
dp = -1 they are the digits of the shortest decimal that gives back the
double, decided exactly, so 0.29 gives 29 where truncating x times a
power of ten gives 28; with dp from 0 to 22 the data are taken as
recorded to dp decimals. bnft() tests the digits against Benford's
law, P(d) = log10(1 + 1 / d), by the chi-square statistic with its
exact upper tail, a Monte Carlo p-value from samples of Benford digits of
the same size, and Nigrini's mean absolute deviation. A departure from
Benford's law is a reason to look, not a finding of fabrication: many
honest data sets (bounded amounts, assigned numbers) do not follow it.
Arguments
- x
Numbers. Zeros, non-finite values (including
NA), values of the excluded sign and values outside the exact range are set aside and counted.- nd
The number of leading digits: from 1 to 9 for
bdig(), 1 to 6 forbnft().- dp
-1, or the number of decimals the data were recorded to.- sgn
Which values to keep:
"pos","neg"or"both"(by absolute value).- dig
Digits as
bdig()returns them (0 is skipped).- nsim
The number of Monte Carlo samples: a whole number from 0.
- seed
NULLto draw the simulations' seed from R's generator (soset.seed()fixes them), or one whole number from 0.
Value
bdig(): a list of dig (an integer per value, 0 when set
aside) and cnt (zeros, non-finite, excluded sign, out of range).
bnft(): a list of obs (a data frame of digit, observed count and
Benford expected count) and stat (m digits used, chisq, df,
p, pmc (Monte Carlo, NaN without samples) and mad).
References
Benford, F. (1938). The law of anomalous numbers. Proceedings of the American Philosophical Society, 78(4), 551-572.
Nigrini, M. J. (2012). Benford's Law: Applications for Forensic Accounting, Auditing, and Fraud Detection. Wiley. doi:10.1002/9781119203094