DEN Discussion List Archive
[Date Prev][Date Next][Date Index]
[Thread Index]
[Author Index]
recalc Benford's law2
- Subject: recalc Benford's law2
- From: Myron Tribus <mtribus@home.com>
- Date: Sat, 2 Dec 2000 09:29:05 -0800
I thought about Benford's law again and this time used the product of
three random numbers. Again, in True BASIC
DIM Calc(9), Meas(9),pct(9),p(9)
FOR i = 1 to 1000
LET x = rnd
LET x = x * rnd
LET x = 100000* x * rnd ! product of 3 random numbers
DO
IF x < 1 then LET x = 10 * x ! if x too small
IF x > 1 then EXIT DO ! move leading digit
LOOP
LET x$ = str$(x) ! convert to string
LET D1 = val(x$(1:1)) ! extract leading digit
LET Meas(D1) = Meas(D1) + 1 ! record nbr of occurrences
NEXT i
FOR i = 1 to 9
LET pct(i) = Meas(i)/10 ! convert to %
LET p(i) = 100 * log10(1 + 1/i) ! Benford's law
NEXT i
! Now create output
print "pct(i) = ";
FOR i = 1 to 9
PRINT using "##.# ": pct(i); ! observed %
NEXT i
PRINT
print "p(i) = ";
FOR i = 1 to 9
PRINT using "##.# ": p(i); ! 100 * computed probability
NEXT I
PRINT
END
!====== result == observed pct vs computed p
pct(i) = 29.6 18.2 13.6 10.5 7.9 6.3 5.1 4.1 4.7
p(i) = 30.1 17.6 12.5 9.7 7.9 6.7 5.8 5.1 4.6
Surprising, isn't it??
Myron Tribus, 350 Britto Terrace, Fremont, CA 94539
Ph:510 651 3641 Fax: 510 656 9875 e-mail: mtribus@home.com
(Quality Consultant's Prayer) Dear Lord, grant me patience. RIGHT NOW!
DEN Home |
Main Index |
Thread Index |
Author Index