From d6ae7d8fcbc2aa7d559f2d15414be4bc9a28befb Mon Sep 17 00:00:00 2001 From: John Darrington Date: Wed, 18 Sep 2013 21:00:34 +0200 Subject: [PATCH] Correct error calculating significance of fisher exact test. The two tailed significance is the sum of the one tailed signficance and those point significances which are greater than P(N = n1) --- src/language/stats/crosstabs.q | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/language/stats/crosstabs.q b/src/language/stats/crosstabs.q index 2246d3af17..6d4ab64ea0 100644 --- a/src/language/stats/crosstabs.q +++ b/src/language/stats/crosstabs.q @@ -2131,6 +2131,7 @@ static void calc_fisher (int a, int b, int c, int d, double *fisher1, double *fisher2) { int pt; + double pn1; if (MIN (c, d) < MIN (a, b)) swap (&a, &c), swap (&b, &d); @@ -2144,13 +2145,21 @@ calc_fisher (int a, int b, int c, int d, double *fisher1, double *fisher2) swap (&a, &c), swap (&b, &d); } - *fisher1 = 0.; - for (pt = 0; pt <= a; pt++) - *fisher1 += Pr (a - pt, b + pt, c + pt, d - pt); + pn1 = Pr (a, b, c, d); + *fisher1 = pn1; + for (pt = 1; pt <= a; pt++) + { + *fisher1 += Pr (a - pt, b + pt, c + pt, d - pt); + } *fisher2 = *fisher1; + for (pt = 1; pt <= b; pt++) - *fisher2 += Pr (a + pt, b - pt, c - pt, d + pt); + { + double p = Pr (a + pt, b - pt, c - pt, d + pt); + if (p < pn1) + *fisher2 += p; + } } /* Calculates chi-squares into CHISQ. MAT is a matrix with N_COLS -- 2.30.2