dbenf(x <- c(0:10, NA, NaN, -Inf, Inf))
pbenf(x)
if (FALSE) {
xx <- 1:9
barplot(dbenf(xx), col = "lightblue", xlab = "Leading digit",
ylab = "Probability", names.arg = as.character(xx),
main = "Benford's distribution", las = 1)
hist(rbenf(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