Statistics/Basic: Difference between revisions

Content added Content deleted
m (→‎{{header|R}}: Remove vanity tags)
(→‎{{header|VBA}}: using the built-in Excel worksheetfunction.frequency)
Line 4,132: Line 4,132:
As can be seen, increasing the sample size reduces the variation between the buckets, showing that the <code>rand()</code> function at least approximates a uniform distribution. (Because Tcl 8.5 supports arbitrary precision integer arithmetic there is no reason in principle why the details for a trillion numbers couldn't be calculated, but it would take quite a while.)
As can be seen, increasing the sample size reduces the variation between the buckets, showing that the <code>rand()</code> function at least approximates a uniform distribution. (Because Tcl 8.5 supports arbitrary precision integer arithmetic there is no reason in principle why the details for a trillion numbers couldn't be calculated, but it would take quite a while.)


=={{header|VBA}}==
<lang vb>Option Base 1
Private Function mean(s() As Variant) As Double
mean = WorksheetFunction.Average(s)
End Function
Private Function standard_deviation(s() As Variant) As Double
standard_deviation = WorksheetFunction.StDev(s)
End Function
Public Sub basic_statistics()
Dim s() As Variant
For e = 2 To 4
ReDim s(10 ^ e)
For i = 1 To 10 ^ e
s(i) = Rnd()
Next i
Debug.Print "sample size"; UBound(s), "mean"; mean(s), "standard deviation"; standard_deviation(s)
t = WorksheetFunction.Frequency(s, [{0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0}])
For i = 1 To 10
Debug.Print Format((i - 1) / 10, "0.00");
Debug.Print "-"; Format(i / 10, "0.00"),
Debug.Print String$(t(i, 1) / (10 ^ (e - 2)), "X");
Debug.Print
Next i
Debug.Print
Next e
End Sub</lang>{{out}}
<pre>sample size 100 mean 0,472405961751938 standard deviation 0,260463885857138
0,00-0,10 XXXXXX
0,10-0,20 XXXXXXXXX
0,20-0,30 XXXXXXXXXXXXXXX
0,30-0,40 XXXXXXXXXXXXXXX
0,40-0,50 XXXXXXXXXXXXXX
0,50-0,60 XXXXXXX
0,60-0,70 XXXXXXXXXXX
0,70-0,80 XXXXXXXX
0,80-0,90 XXXXXXXXXX
0,90-1,00 XXXXX

sample size 1000 mean 0,500459910154343 standard deviation 0,278991757028358
0,00-0,10 XXXXXXXX
0,10-0,20 XXXXXXXXXX
0,20-0,30 XXXXXXXXXX
0,30-0,40 XXXXXXXXXX
0,40-0,50 XXXXXXXXXX
0,50-0,60 XXXXXXXXXXXX
0,60-0,70 XXXXXXXXXXX
0,70-0,80 XXXXXXXXX
0,80-0,90 XXXXXXXXX
0,90-1,00 XXXXXXXXXX

sample size 10000 mean 0,496753623914719 standard deviation 0,28740805585887
0,00-0,10 XXXXXXXXXX
0,10-0,20 XXXXXXXXXX
0,20-0,30 XXXXXXXXXX
0,30-0,40 XXXXXXXXXX
0,40-0,50 XXXXXXXXXX
0,50-0,60 XXXXXXXXXX
0,60-0,70 XXXXXXXXXX
0,70-0,80 XXXXXXXXXX
0,80-0,90 XXXXXXXXXX
0,90-1,00 XXXXXXXXXX</pre>
=={{header|zkl}}==
=={{header|zkl}}==
<lang zkl>fcn mean(ns) { ns.sum(0.0)/ns.len() }
<lang zkl>fcn mean(ns) { ns.sum(0.0)/ns.len() }