dbenf(x, ndigits = 1, log = FALSE)
pbenf(q, ndigits = 1, log.p = FALSE)
qbenf(p, ndigits = 1)
rbenf(n, ndigits = 1)
ndigits
.length(n) > 1
then the length is
taken to be the number required.log.p = TRUE
then all probabilities p
are
given as log(p)
.dbenf
gives the density,
pbenf
gives the distribution function, and
qbenf
gives the quantile function, and
rbenf
generates random deviates.Benford's Law was apparently first discovered in 1881 by astronomer/mathematician S. Newcombe. It started by the observation that the pages of a book of logarithms were dirtiest at the beginning and progressively cleaner throughout. In 1938, a General Electric physicist called F. Benford rediscovered the law on this same observation. Over several years he collected data from different sources as different as atomic weights, baseball statistics, numerical data from Reader's Digest, and drainage areas of rivers.
Applications of Benford's Law has been as diverse as to the area of fraud detection in accounting and the design computers.
Newcomb, S. (1881) Note on the Frequency of Use of the Different Digits in Natural Numbers. American Journal of Mathematics, 4, 39--40.
dbenf(x <- c(0:10, NA, NaN, -Inf, Inf))
pbenf(x)
xx = 1:9; # par(mfrow=c(2,1))
barplot(dbenf(xx), col = "lightblue", las = 1, xlab = "Leading digit",
ylab = "Probability", names.arg = as.character(xx),
main = paste("Benford's distribution", sep = ""))
hist(rbenf(n = 1000), border = "blue", prob = TRUE,
main = "1000 random variates from Benford's distribution",
xlab = "Leading digit", sub="Red is the true probability",
breaks = 0:9 + 0.5, ylim = c(0, 0.35), xlim = c(0, 10.0))
lines(xx, dbenf(xx), col = "red", type = "h")
points(xx, dbenf(xx), col = "red")
Run the code above in your browser using DataLab