Learn R Programming

FunWithNumbers (version 1.2)

benprob: Generate random numbers based on the Benford distribution

Description

This function produces numbers whose distribution is based on Benford's Law of the occurrence of the values 1 through 9 in the first digit of numbers.

Usage

benprob(numsamp = 100, numbase = 10)

Value

A vector of random values.

Arguments

numsamp

How many values to generate.

numbase

Specify the base system (binary, octal, decimal, or whatever is desired) in which to apply the Benford distribution. The default is "10," i.e. decimal.

Author

Carl Witthoft, carl@witthoft.com

Details

"Benford's Law," https://en.wikipedia.org/wiki/Benford%27s_law can be used to assess the "true" randomness of demographic data. Probably its most well-known use has been to detect fraudulent patterns in voting and investment returns claimed by various fund operators. The probability function is prob(d) = log(d+1) - log(d), where d can take on the values 1:(log_base_in_use -1) .The data generated with this function can be used to calculate various statistics such as variance, skew, etc., which can then be compared with the real-world sample set being analyzed.

References

https://en.wikipedia.org/wiki/Benford%27s_law https://projecteuclid.org/euclid.ss/1177009869/

Examples

Run this code
samps <- benprob(1000)
 sd(samps)
 hist(samps)

Run the code above in your browser using DataLab