Jump to content

Statistics/Basic: Difference between revisions

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).
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:
@.j=random(0, 99999) / 100000 /*express random number as a fraction. */
_=substr(@.j'00', 3, 1) /*determine which bin the number is in,*/
#._=#._ +1 1 /* ··· and bump its count. */
end /*j*/
 
do k=0 for 10; kp=k +1 1 /*show a histogram of the bins. */
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. */
barPC=right( strip( left( format( 100*#.k / size, , 2), 5)) , 5) /*compute the %. */
say lr"──►"hr' ' barPC copies('"'", format(barPC *1, ,2 % 1 0)) /*displayshow histogram.*/
end /*k*/
say
say 'sample size = ' size; say
Line 3,293:
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
mean: parse arg N; $=0; do m=1 for N; $=$ + @.m; end; return return $/nN
stdDev: parse arg N; $=0; do s=1 for N; $=$ + (@.s-avg)**2; end; return sqrt($/nN) /1
/*──────────────────────────────────────────────────────────────────────────────────────*/
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
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*/; 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>
0 ──►0.1 12.00 ────────────────────────────────────
0.1──►0.2 912.00 ─────────────────────────────────
0.2──►0.3 910.00 ─────────────────────────────
0.3──►0.4 11 8.00 ───────────────────────────
0.4──►0.5 612.00 ──────────────────────────────
0.5──►0.6 98.00 ─────────────────────────
0.6──►0.7 811.00 ──────────────────────────────
0.7──►0.8 1511.00 ─────────────────────────────────────
0.8──►0.9 86.00 ────────────────────
0.9──►1 1310.00 ─────────────────────────────────
 
sample size = 100
 
mean = 0.51163980004711358000
stdDev = 0.30454754912920169478
 
</pre>
'''{{out|output''' |text=&nbsp; when using the default input of: &nbsp; &nbsp; <tt> 1000 </tt>}}
<pre>
0 ──►0.1 89.6050 ────────────────────────────
0.1──►0.2 10 9.7090 ──────────────────────────────
0.2──►0.3 1011.0070 ─────────────────────────────────
0.3──►0.4 98.4080 ──────────────────────────
0.4──►0.5 10 8.3040 ──────────────────────────
0.5──►0.6 1110.20 ───────────────────────────────
0.6──►0.7 10.5030 ───────────────────────────────
0.7──►0.8 811.2040 ──────────────────────────────
0.8──►0.9 10 9.6010 ─────────────────────────────
0.9──►1 10.5070 ────────────────────────────────
 
sample size = 1000
 
mean = 0.50509673005037752500
stdDev = 0.28625262172886365539
</pre>
'''{{out|output''' |text=&nbsp; when using the default input of: &nbsp; &nbsp; <tt> 10000 </tt>}}
<pre>
0 ──►0.1 10 9.1961 ─────────────────────────────
0.1──►0.2 910.9545 ──────────────────────────────
0.2──►0.3 10 9.1596 ─────────────────────────────
0.3──►0.4 910.5156 ───────────────────────────────
0.4──►0.5 9.6291 ─────────────────────────────
0.5──►0.6 10.0013 ──────────────────────────────
0.6──►0.7 10.7312 ───────────────────────────────
0.7──►0.8 10 9.2584 ─────────────────────────────
0.8──►0.9 9.4861 ────────────────────────────
0.9──►1 10 9.1281 ─────────────────────────────
 
sample size = 10000
 
mean = 0.50037155104968579550
stdDev = 0.28898811842863756713
</pre>
'''{{out|output''' |text=&nbsp; when using the default input of: &nbsp; &nbsp; <tt> 100000 </tt>}}
<pre>
0 ──►0.1 10.0213 ──────────────────────────────
0.1──►0.2 10 9.0084 ─────────────────────────────
0.2──►0.3 9.9291 ─────────────────────────────
0.3──►0.4 10 9.0394 ─────────────────────────────
0.4──►0.5 910.9119 ──────────────────────────────
0.5──►0.6 10.1108 ──────────────────────────────
0.6──►0.7 910.9312 ──────────────────────────────
0.7──►0.8 10 9.1478 ─────────────────────────────
0.8──►0.9 10.0407 ──────────────────────────────
0.9──►1 9.9095 ─────────────────────────────
 
sample size = 100000
 
mean = 0.50005651864999883642
stdDev = 0.28856380762884109515
</pre>
'''{{out|output''' |text=&nbsp; when using the default input of: &nbsp; &nbsp; <tt> 1000000 </tt>}}
<pre>
0 ──►0.1 9.9894 ─────────────────────────────
0.1──►0.2 10.0103 ──────────────────────────────
0.2──►0.3 910.9603 ──────────────────────────────
0.3──►0.4 9.9998 ─────────────────────────────
0.4──►0.5 10.0500 ──────────────────────────────
0.5──►0.6 10.0103 ──────────────────────────────
0.6──►0.7 9.9899 ─────────────────────────────
0.7──►0.8 10.03 ──────────────────────────────
0.8──►0.9 9.9997 ─────────────────────────────
0.9──►1 9.99 ─────────────────────────────
 
sample size = 1000000
 
mean = 0.50015752745000687045
stdDev = 0.28855314462885125537
</pre>
 
Cookies help us deliver our services. By using our services, you agree to our use of cookies.