Commit 5b2db384 authored by Philippe Veber's avatar Philippe Veber
Browse files

tk/Multinomial_test.chisq: heuristic for sparse counts

parent a90765e5
......@@ -66,16 +66,20 @@ module Chisq = struct
and n2 = isum d.x2 in
let n = float (n1 + n2) in
let p_hat = Array.init d.k ~f:(fun j -> float (d.x1.(j) + d.x2.(j)) /. n) in
let nz = Array.map p_hat ~f:Float.(fun p_hat_i -> p_hat_i > 0.) in
sum 0 d.k (fun j ->
if nz.(j) then
let e_hat_1j = p_hat.(j) *. float n1
and e_hat_2j = p_hat.(j) *. float n2 in
((float d.x1.(j) -. e_hat_1j) ** 2.) /. e_hat_1j +.
((float d.x2.(j) -. e_hat_2j) ** 2.) /. e_hat_2j
else 0.
)
let test d =
let _T_ = statistic d in
let nu = float (d.k - 1) in
let nz = data_nz d in
let nu = float (nz - 1) in
let pvalue = Gsl.Cdf.chisq_Q ~x:_T_ ~nu in
{ _T_ ; pvalue }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment