Hi all
I am looking at the source of Random module
I found that it is tested via chi-square test, here is the test code inside:
(* Return the sum of the squares of v[i0,i1[ *)
let rec sumsq v i0 i1 =
if i0 >= i1 then 0.0
else if i1 = i0 + 1 then Pervasives.float v.(i0) *. Pervasives.float v.(i0)
else sumsq v i0 ((i0+i1)/2) +. sumsq v ((i0+i1)/2) i1
;;
let chisquare g n r =
if n <= 10 * r then invalid_arg "chisquare";
let f = Array.make r 0 in
for i = 1 to n do
let t = g r in
f.(t) <- f.(t) + 1
done;
let t = sumsq f 0 r
and r = Pervasives.float r
and n = Pervasives.float n in
let sr = 2.0 *. sqrt r in
(r -. sr, (r *. t /. n) -. n, r +. sr)
;;
I understand how the chi-square is calculated there.
What I don't understand is this comment:
(* Test functions. Not included in the library.
The [chisquare] function should be called with n > 10r.
It returns a triple (low, actual, high).
If low <= actual <= high, the [g] function passed the test,
otherwise it failed.
*)
From my knowledge, if I get a chi-square value, I should check it against a table with the degree of freedom and then decide whether the null hypothesis fails or not.
Why (r -. sr, (r *. t /. n) -. n, r +. sr) can be used to check? What's the theory behind?
thanks
Dan