3 ms·
You chose N in such a way to make your hypothesis true.
by dmurray 7y ago
You chose N in such a way to make your hypothesis true.
- susam 7y agoThe variable 'n' has to be sufficiently large. The larger 'n' is, the more it agrees with Benford's law. For example, with n = 10 (as opposed to n = 10000 in my original code), we get results that disagree with Benford's law quite a bit: 0 => 0.000 1 => 0.301 2 => 0.200 3 => 0.100 4 => 0.100 5 => 0.100 6 => 0.100 7 => 0.000 8 => 0.100 9 => 0.000 In fact, the results for digits 7 and 9 are in complete disagreement with Benford's law. That's not surprising because there is no integer n between 0 and 10 such that 2^n has 7 or 9 as its first digit. Therefore, no matter how many trials we perform, the frequency of the first digit as 7 or 9 would always be 0. The first power of 2 for which we get 7 as the leading digit is 2^46. Similarly, the first power of 2 for which we get 9 as the leading digit is 2^53. So unless the powers are much larger than these numbers, we won't get frequencies for 7 and 9 that agree with Benford's law. With n = 100, the experimental results become closer to Benford's law: 0 => 0.000 1 => 0.300 2 => 0.170 3 => 0.130 4 => 0.100 5 => 0.070 6 => 0.070 7 => 0.060 8 => 0.050 9 => 0.050 But with n = 1000, the results become even closer to Benford's law: 0 => 0.000 1 => 0.301 2 => 0.176 3 => 0.125 4 => 0.097 5 => 0.079 6 => 0.069 7 => 0.056 8 => 0.052 9 => 0.045
- susam 7y agoInstead of performing trials in an experiment, another way to look at this problem is to simply analyze the frequency distribution of the leading significant digit for a function that grows exponentially. Like before, let us choose 2^n as that function. Here is the code: import random N = 10 counts = [0] * 10 for n in range(N): first_digit = int(str(2**n)[0]) counts[first_digit] += 1 for i, count in enumerate(counts): print('{} => {:.3f}'.format(i, counts[i] / N)) For N = 10, i.e., 0 < n < 10, we get: 0 => 0.000 1 => 0.300 2 => 0.200 3 => 0.100 4 => 0.100 5 => 0.100 6 => 0.100 7 => 0.000 8 => 0.100 9 => 0.000 For N = 100, i.e., 0 < n < 100, we get: 0 => 0.000 1 => 0.300 2 => 0.170 3 => 0.130 4 => 0.100 5 => 0.070 6 => 0.070 7 => 0.060 8 => 0.050 9 => 0.050 For N = 1000, i.e., 0 < n < 1000, we get: 0 => 0.000 1 => 0.301 2 => 0.176 3 => 0.125 4 => 0.097 5 => 0.079 6 => 0.069 7 => 0.056 8 => 0.052 9 => 0.045 For N = 10000, i.e., 0 < n < 10000, we get: 0 => 0.000 1 => 0.301 2 => 0.176 3 => 0.125 4 => 0.097 5 => 0.079 6 => 0.067 7 => 0.058 8 => 0.051 9 => 0.046 These results are consistent with the experimental results in my previous comment. As we can see, the larger N is, the more the frequencies of the leading digit obey Benford's law. Similar results can be reproduced with many other exponentially increasing functions too, e.g., 3^n, 5^n, Fibonacci numbers, Lucas numbers, and even factorials that grow faster than exponential functions.
- dmurray 7y agoYou keep choosing N to be an integer power of 10. Make it a power of 2 or 7 or pretty much any number, and you'll see different results.
- susam 7y agoI do not see different results: import random N = 8192 counts = [0] * 10 for n in range(N): first_digit = int(str(2**n)[0]) counts[first_digit] += 1 for i, count in enumerate(counts): print('{} => {:.3f}'.format(i, counts[i] / N)) Output: 0 => 0.000 1 => 0.301 2 => 0.176 3 => 0.125 4 => 0.097 5 => 0.079 6 => 0.067 7 => 0.058 8 => 0.051 9 => 0.046 I still see results that agree with Benford's law.
- logicallee 7y agoI did something similar (except you're a better coder, haha), but when I looked up how to get a random number in Python the first thing I saw was how to get one between 0 and 1 so I went with it. Here is my comment (very similar in spirit to yours): https://news.ycombinator.com/item?id=22341416 https://news.ycombinator.com/item?id=22341416 Any comments?
- susam 7y agoReplied on your comment thread.