Contingency table as an array of rows (at least 2 x 2).
See FisherTestOptions.
The test result; see FisherTestResult.
const r = fisherTest([[3, 1], [1, 3]]);
r.pValue; // 0.4857142857142857
r.estimate; // 6.408319658199675 (conditional MLE of the odds ratio; R: 6.408309)
r.confInt; // [0.2117355954465785, 626.2435305888127] (R: 0.2117329, 621.93)
const m = fisherTest([[3, 1], [1, 3]], { midp: true });
m.pValue; // 0.2571428571428571
m.confInt; // [0.31005488171907974, 308.5567715811547] (exact2x2: 0.3100451, 311.4363)
Fisher's exact test for count data. Equivalent to R's
fisher.test().Tests independence in an r x c contingency table with fixed margins. For 2 x 2 tables it also returns the conditional MLE of the odds ratio and its confidence interval, reproducing R's numbers (including R's root-finding tolerance). The two-sided p-value sums the probabilities of tables no more likely than the observed one (relative tolerance
1e-7, as in R). Non-integer counts are rounded to the nearest integer (ties to even), with R's warning ("'x' has been rounded to integer: Mean relative difference: 0.0625", the text of R'sall.equalof the counts and the rounded counts; none where they differ by less than about 1.5e-8).With
simulatePValue: true, the p-value of a table larger than 2 x 2 is computed fromBrandom tables with the observed margins, drawn from the random stream of setSeed exactly as in R.With
midp: true(2 x 2 only), the mid-p version of exact2x2'sfisher.exact(): the p-value and the interval come from the mid-p tails (two-sided: the central test, twice the smaller tail, at most 1), the limits are the roots of the mid-p tails to the precision of the doubles (exact2x2's search stops up to 1% from them), andmethodis"Central Fisher's Exact Test (mid-p version)"or"One-sided Fisher's Exact Test (mid-p version)".Not implemented: R's
hybridoption.