Talk:Verify distribution uniformity/Chi-squared test: Difference between revisions

(Is the Wikibooks Python example good enough?)
 
(11 intermediate revisions by 4 users not shown)
Line 7:
== Is the Wikibooks Python example good enough? ==
Assuming that the licenses are compatable, is this [http://en.wikibooks.org/wiki/Algorithm_Implementation/Pseudorandom_Numbers/Chi-Square_Test#Python wikibooks Python example] good enough? --[[User:Paddy3118|Paddy3118]] 04:45, 31 October 2009 (UTC)
 
== Incomplete gamma ==
 
It seems computing the the incomplete gamma function is non-trivial and the technique of numerical integration used by some of the examples here has limitations. I tried a data set with 100 categories and [my Go code anyway] failed miserably. Following links on WP I found the continued fraction expansion and tried it. It worked beautifully for my 100 category test case, but then failed for the second test case used by many of the examples here, the one with strongly non-uniform distribution. Digging more on the web I found quite a variety of algorithms, and no consensus on the good way to compute this. The most sensible techniques I saw incorporated multiple algorithms and selected between them based on different ranges of inputs. —[[User:Sonia|Sonia]] 17:33, 7 May 2011 (UTC)
 
:I am not completely sure what "the incomplete gamma function" is, but here's the J implementation:
 
:<lang j>4 :0
(1 H. (1+x) % x&((* ^) * (^ -)~)) y
)</lang>
 
:So, for example if x is 1.5 and y is 4.1
 
:<lang j> (1 H. (1+1.5) % 1.5&((* ^) * (^ -)~)) 4.1
0.848957</lang>
 
:The right argument to H. is:
 
:<lang j> ((1+1.5) % 1.5&((* ^) * (^ -)~)) 4.1
0.229307</lang>
 
:In other words, 2.5 divided by 10.9024:
 
:<lang j> ( 1.5&((* ^) * (^ -)~)) 4.1
10.9024</lang>
 
:In other words (1.5 * ^ 4.1) * 4.1 ^ -1.5. (^y with no left argument is e^y).
 
:And H. is the primitive documented at http://www.jsoftware.com/help/dictionary/dhcapdot.htm
 
:I do not know if this helps, though.
 
:--[[User:Rdm|Rdm]] 22:28, 7 May 2011 (UTC)
 
== possible error ==
 
In the Ruby version of gammaInc_Q, near the end there is a few lines
 
 
 
(n-1).step(0, -1) do |j|
t = h * j
sum += f0[t] + hh * df0[t]
end
 
The last iteration produces a value of j of 0, which means t is zero but df0[t] is not a number
as it requires the calculation of 0**a2. I just changed the enumerator to (n-1).step(1, -1)|
and it seems to give the correct result.
Anonymous user