Statistics/Basic: Difference between revisions

Content added Content deleted
m (→‎{{header|REXX}}: added/changed comments and whitespace, used templates for the OUTPUTs, simplified some parts of the program, expanded the width of the histograms (bars).)
Line 3,278: Line 3,278:
@.j=random(0, 99999) / 100000 /*express random number as a fraction. */
@.j=random(0, 99999) / 100000 /*express random number as a fraction. */
_=substr(@.j'00', 3, 1) /*determine which bin the number is in,*/
_=substr(@.j'00', 3, 1) /*determine which bin the number is in,*/
#._=#._+1 /* ··· and bump its count. */
#._=#._ + 1 /* ··· and bump its count. */
end /*j*/
end /*j*/


do k=0 for 10; kp=k+1 /*show a histogram of the bins. */
do k=0 for 10; kp=k + 1 /*show a histogram of the bins. */
lr='0.'k ; if k==0 then lr="0 " /*adjust for the low range. */
lr='0.'k ; if k==0 then lr= "0 " /*adjust for the low range. */
hr='0.'kp ; if k==9 then hr="1 " /* " " " high range. */
hr='0.'kp ; if k==9 then hr= "1 " /* " " " high range. */
barPC=right(strip(left(format(100*#.k/size, , 2), 5)) ,5) /*compute the %. */
barPC=right( strip( left( format( 100*#.k / size, , 2), 5)), 5) /*compute the %. */
say lr"──►"hr' ' barPC copies('', format(barPC*1, , 0)) /*display histogram*/
say lr"──►"hr' ' barPC copies("", barPC * 2 % 1 ) /*show histogram.*/
end /*k*/
end /*k*/
say
say
say 'sample size = ' size; say
say 'sample size = ' size; say
Line 3,293: Line 3,293:
exit /*stick a fork in it, we're all done. */
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
mean: parse arg N; $=0; do m=1 for N; $=$+@.m; end; return $/n
mean: arg N; $=0; do m=1 for N; $=$ + @.m; end; return $/N
stdDev: parse arg N; $=0; do s=1 for N; $=$+(@.s-avg)**2; end; return sqrt($/n)
stdDev: arg N; $=0; do s=1 for N; $=$ + (@.s-avg)**2; end; return sqrt($/N) /1
/*──────────────────────────────────────────────────────────────────────────────────────*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
sqrt: procedure; parse arg x; if x=0 then return 0; d=digits(); m.=9; numeric form; h=d+6
sqrt: procedure; parse arg x; if x=0 then return 0; d=digits(); m.=9; numeric form; h=d+6
numeric digits; parse value format(x,2,1,,0) 'E0' with g 'E' _ .; g=g*.5'e'_ % 2
numeric digits; parse value format(x,2,1,,0) 'E0' with g 'E' _ .; g=g*.5'e'_ % 2
do j=0 while h>9; m.j=h; h=h%2+1; end /*j*/
do j=0 while h>9; m.j=h; h=h%2+1; end /*j*/
do k=j+5 to 0 by -1; numeric digits m.k; g=(g+x/g)*.5; end /*k*/
do k=j+5 to 0 by -1; numeric digits m.k; g=(g+x/g)*.5; end /*k*/; return g</lang>
{{out|output|text=&nbsp; when using the default input of: &nbsp; &nbsp; <tt> 100 </tt>}}
return g/1</lang>
'''output''' &nbsp; when using the default input of: &nbsp; <tt> 100 </tt>
<pre>
<pre>
0 ──►0.1 12.00 ────────────
0 ──►0.1 12.00 ────────────────────────
0.1──►0.2 9.00 ─────────
0.1──►0.2 12.00 ────────────────────────
0.2──►0.3 9.00 ─────────
0.2──►0.3 10.00 ────────────────────
0.3──►0.4 11.00 ───────────
0.3──►0.4 8.00 ────────────────
0.4──►0.5 6.00 ──────
0.4──►0.5 12.00 ────────────────────────
0.5──►0.6 9.00 ─────────
0.5──►0.6 8.00 ────────────────
0.6──►0.7 8.00 ────────
0.6──►0.7 11.00 ──────────────────────
0.7──►0.8 15.00 ───────────────
0.7──►0.8 11.00 ──────────────────────
0.8──►0.9 8.00 ────────
0.8──►0.9 6.00 ────────────
0.9──►1 13.00 ─────────────
0.9──►1 10.00 ────────────────────


sample size = 100
sample size = 100


mean = 0.5116398000
mean = 0.4711358000
stdDev = 0.3045475491
stdDev = 0.2920169478

</pre>
</pre>
'''output''' &nbsp; when using the input of: &nbsp; <tt> 1000 </tt>
{{out|output|text=&nbsp; when using the default input of: &nbsp; &nbsp; <tt> 1000 </tt>}}
<pre>
<pre>
0 ──►0.1 8.60 ─────────
0 ──►0.1 9.50 ───────────────────
0.1──►0.2 10.70 ───────────
0.1──►0.2 9.90 ───────────────────
0.2──►0.3 10.00 ──────────
0.2──►0.3 11.70 ───────────────────────
0.3──►0.4 9.40 ─────────
0.3──►0.4 8.80 ─────────────────
0.4──►0.5 10.30 ──────────
0.4──►0.5 8.40 ────────────────
0.5──►0.6 11.20 ───────────
0.5──►0.6 10.20 ────────────────────
0.6──►0.7 10.50 ───────────
0.6──►0.7 10.30 ────────────────────
0.7──►0.8 8.20 ────────
0.7──►0.8 11.40 ──────────────────────
0.8──►0.9 10.60 ───────────
0.8──►0.9 9.10 ──────────────────
0.9──►1 10.50 ───────────
0.9──►1 10.70 ─────────────────────


sample size = 1000
sample size = 1000


mean = 0.5050967300
mean = 0.5037752500
stdDev = 0.2862526217
stdDev = 0.2886365539
</pre>
</pre>
'''output''' &nbsp; when using the input of: &nbsp; <tt> 10000 </tt>
{{out|output|text=&nbsp; when using the default input of: &nbsp; &nbsp; <tt> 10000 </tt>}}
<pre>
<pre>
0 ──►0.1 10.19 ──────────
0 ──►0.1 9.61 ───────────────────
0.1──►0.2 9.95 ──────────
0.1──►0.2 10.45 ────────────────────
0.2──►0.3 10.15 ──────────
0.2──►0.3 9.96 ───────────────────
0.3──►0.4 9.51 ──────────
0.3──►0.4 10.56 ─────────────────────
0.4──►0.5 9.62 ──────────
0.4──►0.5 9.91 ───────────────────
0.5──►0.6 10.00 ──────────
0.5──►0.6 10.13 ────────────────────
0.6──►0.7 10.73 ───────────
0.6──►0.7 10.12 ────────────────────
0.7──►0.8 10.25 ──────────
0.7──►0.8 9.84 ───────────────────
0.8──►0.9 9.48 ─────────
0.8──►0.9 9.61 ───────────────────
0.9──►1 10.12 ──────────
0.9──►1 9.81 ───────────────────


sample size = 10000
sample size = 10000


mean = 0.5003715510
mean = 0.4968579550
stdDev = 0.2889881184
stdDev = 0.2863756713
</pre>
</pre>
'''output''' &nbsp; when using the input of: &nbsp; <tt> 100000 </tt>
{{out|output|text=&nbsp; when using the default input of: &nbsp; &nbsp; <tt> 100000 </tt>}}
<pre>
<pre>
0 ──►0.1 10.02 ──────────
0 ──►0.1 10.13 ────────────────────
0.1──►0.2 10.00 ──────────
0.1──►0.2 9.84 ───────────────────
0.2──►0.3 9.92 ──────────
0.2──►0.3 9.91 ───────────────────
0.3──►0.4 10.03 ──────────
0.3──►0.4 9.94 ───────────────────
0.4──►0.5 9.91 ──────────
0.4──►0.5 10.19 ────────────────────
0.5──►0.6 10.11 ──────────
0.5──►0.6 10.08 ────────────────────
0.6──►0.7 9.93 ──────────
0.6──►0.7 10.12 ────────────────────
0.7──►0.8 10.14 ──────────
0.7──►0.8 9.78 ───────────────────
0.8──►0.9 10.04 ──────────
0.8──►0.9 10.07 ────────────────────
0.9──►1 9.90 ──────────
0.9──►1 9.95 ───────────────────


sample size = 100000
sample size = 100000


mean = 0.5000565186
mean = 0.4999883642
stdDev = 0.2885638076
stdDev = 0.2884109515
</pre>
</pre>
'''output''' &nbsp; when using the input of: &nbsp; <tt> 1000000 </tt>
{{out|output|text=&nbsp; when using the default input of: &nbsp; &nbsp; <tt> 1000000 </tt>}}
<pre>
<pre>
0 ──►0.1 9.98 ──────────
0 ──►0.1 9.94 ───────────────────
0.1──►0.2 10.01 ──────────
0.1──►0.2 10.03 ────────────────────
0.2──►0.3 9.96 ──────────
0.2──►0.3 10.03 ────────────────────
0.3──►0.4 9.99 ──────────
0.3──►0.4 9.98 ───────────────────
0.4──►0.5 10.05 ──────────
0.4──►0.5 10.00 ────────────────────
0.5──►0.6 10.01 ──────────
0.5──►0.6 10.03 ────────────────────
0.6──►0.7 9.98 ──────────
0.6──►0.7 9.99 ───────────────────
0.7──►0.8 10.03 ──────────
0.7──►0.8 10.03 ────────────────────
0.8──►0.9 9.99 ──────────
0.8──►0.9 9.97 ───────────────────
0.9──►1 9.99 ──────────
0.9──►1 9.99 ───────────────────


sample size = 1000000
sample size = 1000000


mean = 0.5001575274
mean = 0.5000687045
stdDev = 0.2885531446
stdDev = 0.2885125537
</pre>
</pre>