Verify distribution uniformity/Chi-squared test: Difference between revisions
Verify distribution uniformity/Chi-squared test (view source)
Revision as of 21:08, 20 December 2022
, 1 year ago→{{header|jq}}: use recursion formula for gamma
m (spacing) |
(→{{header|jq}}: use recursion formula for gamma) |
||
Line 742:
enough for the χ2 distribution to be used.
The implementation of `Chi2_cdf`
For an industrial-strength algorithm, see
e.g. https://people.sc.fsu.edu/~jburkardt/c_src/asa239/asa239.c
Line 760:
# Cumulative density function of the chi-squared distribution with $k
# degrees of freedom
# The recursion formula for gamma is used for efficiency and robustness.
def Chi2_cdf($x; $k):
if $x == 0 then 0
elif $x > (1e3 * $k) then 1
else 1e-15 as $tol # for example
| { s: 0, m: 0, term: (1 / ((($
| until (.term|length < $tol; # length here is abs
| .m += 1
.term = (((.m * (($x/2)|log)) - (($k/2 + .m + 1)|lgamma)) | exp)▼
| .
▲ | .m += 1)
end ;
</syntaxhighlight>
Line 824 ⟶ 822:
task
</syntaxhighlight>
<pre>
Dataset: [199809,200665,199607,200270,199649]
|