x = c(0:10, NA, NaN, -Inf, Inf)
dbenf(x)
pbenf(x)
x = 1:9; # par(mfrow=c(2,1))
barplot(dbenf(x), col = "lightblue", las=1, xlab="Leading digit",
ylab = "Probability",
main=paste("Benford's distribution", sep=""),
names.arg = as.character(x))
hist(rbenf(n=1000), border = "blue", prob=TRUE,
main="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(1:9, dbenf(1:9), col="red", type="h")
points(1:9, dbenf(1:9), col="red")
Run the code above in your browser using DataLab