Choose a method · Calculate

2 × 2 table calculator: chi-square, Fisher, Boschloo, risk difference and odds ratio

Enter events and totals for two groups. Get the expected counts, the test your plan chose, and the risk difference, relative risk and odds ratio with confidence intervals, checked against R and SciPy.

By Licklider · Published · Last reviewed · How this page was made · Markdown

Calculator

Design
Each count is
Choose the test plan before entering the counts

Whole numbers only (leading zeros are fine; no signs or separators).

Enter the counts to calculate.

    Computed in your browser; the counts and names you enter are not sent anywhere. Share links keep them after the # sign, which browsers do not send to any server.

    On this page
    1. How to use it
    2. What the result means
    3. Worked example
    4. Before you use it
    5. How it is calculated
    6. Checked against R, SciPy and statsmodels
    7. Questions a reviewer may ask
    8. Report it
    9. Cite this tool
    10. References

    Quick answer. This calculator is for one 2 × 2 table of independent animals, each counted once; if the counts are cells, wells or fields from a few animals, or animals treated together per cage or litter, a 2 × 2 test does not apply. Choose the test plan first, then enter the events and totals for each group. With the default plan, the calculator uses Pearson’s chi-square test without Yates’ correction when every expected count is at least 5 and Boschloo’s exact test otherwise, the rule explained in the chi-square vs Fisher guide. Report the risk difference with its confidence interval first, then the relative risk and odds ratio; in a case-control design, which samples animals by outcome, report only the odds ratio. If the same animals were scored twice, choose “Same animals scored twice” (McNemar’s test).

    Terms used below. A 2 × 2 table has two groups (rows) and a yes/no outcome (columns). The expected count of a cell is row total × column total ÷ grand total, the count you would see if the outcome were independent of the group. The test plan is the test you commit to before seeing the counts. Pearson’s chi-square test compares the observed with the expected counts; Yates’ correction is an adjustment that makes it more cautious. An exact test computes its p-value from every possible table rather than from an approximation: Fisher’s exact test treats both the group sizes and the outcome totals as fixed, and Boschloo’s exact test treats only the group sizes as fixed and usually has more power. McNemar’s test compares the animals that changed category when the same animals are scored twice (a paired design). α is the significance threshold, usually 0.05; a two-sided p-value counts a difference in either direction. The risk difference is the difference between the two percentages, in percentage points (80% − 30% = 50 points); the relative risk is their ratio; the odds ratio compares the odds (events ÷ non-events) of the two groups. A confidence interval (CI) is the range of values compatible with the data at the stated level. A score interval (Wilson, Newcombe, Koopman) is built from a score test rather than from estimate ± 1.96 standard errors, and an interval inverts a test when it contains exactly the values for which that test gives p above α.

    How to use it

    1. Choose the design (“Two independent groups” or “Same animals scored twice”) and answer “Each count is”: one independently treated animal, cells, wells or fields from a few animals, treatment was given per cage or litter or not sure. Only the first leads to a test; the others point to the analysis that fits.
    2. Choose the test plan before entering the counts. For two independent groups the options are “The guide’s rule” (selected when the page opens), “Boschloo’s exact test for every table (strict α)” and “Fisher’s exact test for every table”; keep the guide’s rule unless your protocol named another test. For the same animals scored twice they are the exact McNemar test (selected) and the mid-p McNemar test, chosen in advance.
    3. Name the groups and the outcome, then enter, for each group, the animals with the event and the animals in total (8 and 10 for vehicle in the example). The risk difference is group 1 minus group 2. For the same animals scored twice, enter the four counts: positive both times, positive then negative, negative then positive, and negative both times.
    4. Read the headline test and the risk difference. “All tests” shows every test, labelled so you can see which one your plan chose; choose before looking. “Other intervals” shows the intervals some software reports by default.
    5. Use the buttons under the results to copy the Methods sentence, the results sentence, and the R or Python code that reproduces the tests, the risk difference and the odds ratio (the Python code also gives the Koopman interval when no group has 0 or all events).

    What the result means

    • The headline test answers whether a difference this large would be unusual if both groups had the same risk. Every p-value is two-sided. A p-value above 0.05 is not evidence that the groups are the same.
    • The risk difference is the clearest effect for a reader: “50 percentage points more tumours with vehicle”. Its interval is Newcombe’s hybrid score interval, which Fagerland, Lydersen and Laake (2015) prefer when each group has more than 30 animals; for smaller groups their first choice is Agresti–Min’s exact unconditional interval, which this calculator does not compute, with Newcombe’s “a good alternative” that “can be somewhat liberal” (How it is calculated). With small groups, name the method when you report the interval, as the generated sentences do.
    • The relative risk uses Koopman’s score interval, which inverts the chi-square score test. Fagerland et al. do not recommend the widely used Katz log interval unless each group has at least 75 animals; it appears under “Other intervals” only for comparison with software that reports it.
    • The odds ratio is the conditional maximum-likelihood estimate with exact limits, the estimate R’s fisher.test and SciPy’s odds_ratio report (R’s limits can differ in extreme tables; see the checks). Those limits invert Fisher’s test, not Boschloo’s, so they can disagree with Boschloo’s test; the calculator says so when they do. Fagerland et al. prefer the Baptista–Pike mid-p interval and warn that this exact conditional interval “can, however, be extremely conservative”; it is reported because R and SciPy compute it, so it can be checked.
    • Above 500 animals per group Boschloo’s test is not computed. With the default plan, a table that needs an exact test then gets Fisher’s exact test, labelled as such; with “Boschloo’s exact test for every table”, no test is reported.
    • A group with 0 or all events is handled: the tests and the Newcombe and Koopman intervals are defined (the chi-square tests are not when the outcome column is empty, for example 0 events in both groups), and the exact odds-ratio limits can be 0 or infinite. Only the sample odds ratio with Woolf’s interval under “Other intervals” adds 0.5 to every cell (Haldane 1956).

    Worked example

    Tumour incidence at day 60 was 8 of 10 vehicle-treated mice and 3 of 10 drug-treated mice. The smallest expected count is 4.5, below 5, so the default plan uses Boschloo’s exact test.

    Quantity Result
    Boschloo’s exact test (the plan) p = 0.041
    Fisher’s exact test p = 0.070
    Pearson chi-square, no correction (not the plan: an expected count is below 5) p = 0.025
    Yates’ chi-square (default in R’s chisq.test and SciPy’s chi2_contingency; not used here) p = 0.072
    Risk difference (Newcombe) 50 percentage points, 95% CI 7 to 74 points
    Relative risk (Koopman) 2.7, 95% CI 1.1 to 7.7
    Odds ratio (conditional, exact limits that invert Fisher’s test) 8.15 (shown as 8.2 in the calculator), 95% CI 0.88 to 127

    Report p = 0.041, the test the plan chose; do not pick a row after seeing the numbers. The exact odds-ratio interval includes 1 although Boschloo’s test is significant: the interval inverts Fisher’s test (p = 0.070), not Boschloo’s. Report the planned test and present the interval as the range of compatible odds ratios. With 10 mice per group, the risk-difference interval is Newcombe’s, which Fagerland et al. call a good alternative to their first choice for small groups (Agresti–Min), so name the method.

    Before you use it

    • One animal, one count. Every count must come from a different, independently treated animal. Counts of cells, wells or fields from a few animals belong to what counts as n and the counts of cells section of the chi-square guide; when treatment was given per cage or litter, the cage or litter is the unit.

    • Plan first. The plan setting comes first because choosing the test with the smallest p-value after seeing the table inflates false positives.

    • Case-control designs sample by outcome, so only the odds ratio is meaningful; ignore the risk difference and relative risk.

    • Odds ratio versus relative risk. When the outcome is common, the odds ratio is further from 1 than the relative risk: larger when the relative risk is above 1, smaller when it is below 1 (Zhang & Yu 1998). With a relative risk of 2:

      Risk in the comparison group 1% 5% 10% 20% 30% 40%
      Odds ratio 2.02 2.11 2.25 2.67 3.50 6.00
    • Relabelling the outcome (counting “no tumour” as the event) leaves the tests unchanged, inverts the odds ratio and negates the risk difference, but changes the relative risk. Name the outcome you counted.

    • Larger tables, strata or many tables. This tool handles one 2 × 2 table. For larger tables use the chi-square test or Fisher’s exact test in R; for many 2 × 2 tables, adjust the p-values with the correction calculator.

    How it is calculated

    • Expected counts are row total × column total ÷ N; the rule “at least 5” is checked in whole numbers (row total × column total ≥ 5N).
    • Chi-square: X² = N(ad − bc)² / (n₁n₂m₁m₀), with a and b the event and non-event counts in group 1, c and d those in group 2, and m₁, m₀ the outcome totals. The calculator’s headline uses this version; the “N − 1” version, which multiplies X² by (N − 1)/N (Campbell 2007), is listed under “All tests”. Yates’ version subtracts 0.5 from each |observed − expected| as R does.
    • Fisher’s exact test: conditional on all margins; the two-sided p adds the probabilities of every table no more likely than the observed one, with R’s relative tolerance of 1 + 10⁻⁷. Probabilities use Loader’s saddle-point method, as R’s dhyper does, so they stay accurate at large N.
    • Boschloo’s exact test: group sizes fixed. In each direction the statistic is Fisher’s one-sided p; the one-sided Boschloo p is the largest probability, over a common risk π from 0 to 1, of all tables at least as extreme. The calculator searches a 401-point grid of π and refines the three best intervals by golden-section search. The two-sided p is twice the smaller one-sided p, SciPy’s definition. It is computed for up to 500 animals per group.
    • Proportions: Wilson score intervals. Risk difference: Newcombe’s hybrid score interval (method 10). Relative risk: Koopman’s score interval, with the constrained estimates on the closed parameter space so that tables with a full group are handled. Odds ratio: conditional maximum-likelihood estimate and exact conditional limits, solved to 10⁻¹³; the sample odds ratio with Woolf’s interval is shown for comparison, with 0.5 added to every cell when a cell is zero (Haldane 1956). Fagerland, Lydersen and Laake (2015) recommend Agresti–Min’s exact unconditional interval for the risk difference in small samples and the Baptista–Pike mid-p interval for the odds ratio at all sample sizes; neither is implemented here, because SciPy, statsmodels and the R packages used for checking have no implementation to verify them against.
    • Paired design: the exact McNemar test is a two-sided binomial test on the animals that changed category; the mid-p version is available as a plan chosen in advance (Fagerland, Lydersen & Laake 2013). The odds ratio b/c has an exact interval derived from the Clopper–Pearson interval for b/(b + c).

    Checked against R, SciPy and statsmodels

    77 tables of two independent groups (1 to 50,000 per group; zeros, full groups, an expected count of exactly 5, and very unbalanced groups) and 21 paired tables, compared with SciPy 1.18.1, statsmodels 0.15.0, R version 4.3.3 (2024-02-29) with exact2x2 1.7.0, mpmath 1.4.1 and a brute-force Boschloo maximisation (20,001-point grid plus refinement, written separately from the calculator). A failing check blocks publication.

    Reference Quantity Cases Values Largest relative difference Tolerance
    Brute force Boschloo one-sided and two-sided p 76 228 1.2 × 10⁻¹⁴ 10⁻¹²
    SciPy Boschloo p (n = 256) 60 60 2.1 × 10⁻¹³ 10⁻⁹
    SciPy Clopper–Pearson limits (paired odds ratio) 19 38 6.4 × 10⁻¹⁵ 10⁻⁹
    SciPy Conditional odds ratio and exact limits 75 225 3.8 × 10⁻¹¹ 10⁻⁹
    SciPy Expected counts 75 300 identical 10⁻¹²
    SciPy Fisher p 77 77 9.5 × 10⁻¹⁵ 10⁻¹²
    SciPy McNemar mid-p 19 19 6.3 × 10⁻¹⁵ 10⁻¹²
    SciPy Pearson and Yates chi-square 75 300 8.6 × 10⁻¹⁴ 10⁻¹²
    SciPy Relative risk, Katz limits 66 198 2.4 × 10⁻¹⁶ 10⁻¹²
    SciPy Sample odds ratio, Woolf limits 58 174 1.0 × 10⁻¹⁵ 10⁻¹²
    statsmodels Exact McNemar 19 19 9.6 × 10⁻¹⁵ 10⁻¹²
    statsmodels Koopman limits (interior tables) 58 116 6.8 × 10⁻¹¹ 10⁻⁹
    statsmodels Newcombe limits 77 154 8.2 × 10⁻¹⁵ 10⁻¹²
    statsmodels Wilson limits 77 308 3.1 × 10⁻¹⁵ 10⁻¹²
    R Boschloo p (rounded statistic, 1,000-point grid) 60 60 8.5 × 10⁻⁶ 10⁻⁵
    R Conditional odds ratio and exact limits 75 225 1.3 × 10⁻¹ 0.2
    R Exact and mid-p McNemar 19 38 2.1 × 10⁻¹⁴ 10⁻¹²
    R Fisher p 77 77 4.1 × 10⁻¹⁵ 10⁻¹²
    R Koopman limits 76 152 2.2 × 10⁻⁸ 10⁻⁷
    R Newcombe limits 77 154 1.4 × 10⁻¹⁴ 10⁻¹²
    R Paired odds ratio and exact limits 19 57 6.4 × 10⁻¹⁵ 10⁻⁹
    R Pearson and Yates chi-square 75 300 7.6 × 10⁻¹⁴ 10⁻¹²
    mpmath Conditional odds ratio and exact limits 26 78 1.8 × 10⁻¹⁴ 10⁻⁹
    mpmath Exact and mid-p McNemar 19 38 1.1 × 10⁻¹⁴ 10⁻¹²
    mpmath Fisher p 29 29 9.3 × 10⁻¹⁵ 10⁻¹²
    mpmath Koopman limits 28 56 1.8 × 10⁻¹³ 10⁻⁹

    Every quantity matched its binding reference within the tolerance shown. The one wide row, R’s conditional odds-ratio interval (tolerance 0.2), reflects R’s root finder stopping early in extreme tables: R’s fisher.test finds the conditional odds ratio and its interval with uniroot at its default tolerance. It usually agrees to about 10⁻⁴, but in very unbalanced or extreme tables its limits were up to 13% away from the 40-digit mpmath values, which this calculator matches; the binding references for that quantity are mpmath and SciPy. The R Koopman reference uses optimize and uniroot, whose tolerances set agreement at about 10⁻⁸. R’s Boschloo value uses exact2x2’s unconditional test on a 1,000-point grid with the Fisher statistic rounded to 12 significant figures (exact2x2’s own boschloo() can drop tied tables). statsmodels’ score interval for the ratio is compared only for tables without a zero or a full group. Runs in Node.js (V8) on every change and in headless Chromium; Firefox and Safari were unavailable in the test environment.

    Questions a reviewer may ask

    Why not Yates’ correction? It makes the chi-square test as cautious as Fisher’s test or more, without being exact; the guide shows the false-positive rates.

    Why Boschloo rather than Fisher for small tables? Boschloo’s test keeps the false-positive rate at or below α and generally has more power than Fisher’s test for small and moderate samples (Lydersen et al. 2009).

    Why does R’s exact2x2::boschloo() give a different p-value? In exact2x2 1.7.0 it compares Fisher p-values for exact equality, so a table that ties with the observed one in theory but differs in the last binary digits can be dropped. In the worked example, with vehicle entered first, it gives 0.033 instead of 0.041 (entered the other way round, or with tsmethod = "minlike", 0.041); our Engineering note shows why. With the statistic rounded first (the R code from the calculator), it agrees with SciPy and this calculator. Note also that SciPy’s boschloo_exact reads each column as one group: pass the groups as columns.

    Which odds ratio is this? The conditional maximum-likelihood estimate (8.15 in the example, as R prints it; the calculator shows 8.2), the one R’s fisher.test reports; SciPy’s fisher_exact reports the sample odds ratio ad/bc (9.3).

    Why does my relative-risk interval differ from SciPy’s? SciPy’s relative_risk uses the Katz log interval (0.98 to 7.2 in the example), shown in the calculator under “Other intervals”; this calculator reports Koopman’s interval.

    Is the p-value one- or two-sided? Two-sided for every test. For Boschloo’s test it is twice the smaller one-sided p, SciPy’s definition.

    The test is significant but the odds-ratio interval includes 1. The exact limits invert Fisher’s test, not Boschloo’s; report the planned test.

    Report it

    The calculator writes both sentences for your counts, naming the plan, the test and the interval methods. For the worked example:

    Methods sentence:

    Proportions were compared with Boschloo’s exact test (two-sided; chosen in advance: Pearson’s chi-square test without continuity correction if every expected count was at least 5, otherwise Boschloo’s exact test). Boschloo’s two-sided p-value was twice the smaller one-sided p-value (the SciPy definition), with group sizes fixed. The risk difference is reported with a 95% Newcombe hybrid-score confidence interval, the relative risk with a Koopman score interval and the odds ratio as the conditional maximum-likelihood estimate with exact limits (Licklider 2 × 2 table calculator, version 1.0, https://www.licklider.ai/tools/two-by-two-table-calculator/, accessed [date]).

    Results sentence:

    Tumour occurred in 8 of 10 vehicle and 3 of 10 drug subjects (80% vs 30%; difference 50 percentage points, 95% CI 7 to 74; relative risk 2.7, 95% CI 1.1 to 7.7; conditional odds ratio 8.2, 95% CI 0.88 to 127, Boschloo’s exact test, p = 0.041).

    The Methods sentence names Newcombe’s interval, so a reader can judge it; with fewer than 30 animals per group, Fagerland et al. prefer Agresti–Min’s interval for the risk difference (not computed here) and call Newcombe’s a good alternative. For the same animals scored twice, the calculator writes the McNemar version of both sentences.

    Cite this tool

    Licklider. 2 × 2 table calculator, version 1.0 (2026). https://www.licklider.ai/tools/two-by-two-table-calculator/

    Changelog: version 1.0 (10 November 2026), first release.

    References

    • Boschloo RD (1970). Raised conditional level of significance for the 2 × 2-table when testing the equality of two probabilities. Statistica Neerlandica 24:1–9. doi:10.1111/j.1467-9574.1970.tb00104.x
    • Campbell I (2007). Chi-squared and Fisher–Irwin tests of two-by-two tables with small sample recommendations. Statistics in Medicine 26:3661–3675. doi:10.1002/sim.2832
    • Fagerland MW, Lydersen S, Laake P (2013). The McNemar test for binary matched-pairs data: mid-p and asymptotic are better than exact conditional. BMC Medical Research Methodology 13:91. doi:10.1186/1471-2288-13-91
    • Fagerland MW, Lydersen S, Laake P (2015). Recommended confidence intervals for two independent binomial proportions. Statistical Methods in Medical Research 24:224–254. doi:10.1177/0962280211415469
    • Haldane JBS (1956). The estimation and significance of the logarithm of a ratio of frequencies. Annals of Human Genetics 20:309–311. doi:10.1111/j.1469-1809.1955.tb01285.x
    • Katz D, Baptista J, Azen SP, Pike MC (1978). Obtaining confidence intervals for the risk ratio in cohort studies. Biometrics 34:469. doi:10.2307/2530610
    • Koopman PAR (1984). Confidence intervals for the ratio of two binomial proportions. Biometrics 40:513. doi:10.2307/2531405
    • Lydersen S, Fagerland MW, Laake P (2009). Recommended tests for association in 2 × 2 tables. Statistics in Medicine 28:1159–1175. doi:10.1002/sim.3531
    • McNemar Q (1947). Note on the sampling error of the difference between correlated proportions or percentages. Psychometrika 12:153–157. doi:10.1007/BF02295996
    • Newcombe RG (1998). Interval estimation for the difference between independent proportions: comparison of eleven methods. Statistics in Medicine 17:873–890. doi:10.1002/(SICI)1097-0258(19980430)17:8<873::AID-SIM779>3.0.CO;2-I
    • Wilson EB (1927). Probable inference, the law of succession, and statistical inference. Journal of the American Statistical Association 22:209–212. doi:10.1080/01621459.1927.10502953
    • Woolf B (1955). On estimating the relation between blood group and disease. Annals of Human Genetics 19:251–253. doi:10.1111/j.1469-1809.1955.tb01348.x
    • Zhang J, Yu KF (1998). What’s the relative risk? JAMA 280:1690–1691. doi:10.1001/jama.280.19.1690
    • Software: R 4.3.3 fisher.test and chisq.test; exact2x2 1.7.0; SciPy 1.18.1 boschloo_exact, fisher_exact, chi2_contingency, contingency.odds_ratio and relative_risk; statsmodels 0.15.0.

    How this page was made

    • Built and published by Licklider. Each test and interval follows its original paper or the recommendation of Fagerland, Lydersen and Laake (2015) for two independent proportions, listed under References.
    • Every release is checked automatically against SciPy 1.18.1, statsmodels 0.15.0, R 4.3.3 with exact2x2 1.7.0, high-precision mpmath values and a separately written brute-force Boschloo calculation (see 'Checked against R, SciPy and statsmodels'); a failing check blocks publication.
    • The specification and the finished calculator were each reviewed independently before publication, and the DOIs and links are checked with a script.