Last chance! 50% off unlimited learning
Sale ends in
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.dbenf()
etc. in the dBenf(x <- c(0:10, NA, NaN, -Inf, Inf))
pBenf(x)
xx <- 1:9
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