← All calculators

Chi-Square Contingency Tables

2×2 tables with odds ratio and relative risk + 95% CI, and up to 4×4 contingency tables with expected counts. The same math as the Excel workbook, live in your browser.

What this is for: Tests of independence for 2×2 tables (with odds ratio and relative risk + 95% CIs) and tables up to 4×4, with expected counts shown.

The formula: χ² = Σ (observed − expected)² ÷ expected; expected = row total × column total ÷ grand total

How to use:

  1. For a 2×2 comparison, enter the four observed counts a, b, c and d in Section A as labelled.
  2. Read the expected counts, χ², df and p-value, then the odds ratio and relative risk with their 95% CIs and the row proportions.
  3. For a larger table, paste the counts in Section B, one row per line with counts separated by spaces or commas (up to 4 rows × 4 columns), leaving unused rows and columns blank.
  4. Read that table's χ², df and p-value; if any expected count is below 5, prefer Fisher's exact test instead, as the workbook notes.

A. 2×2 Table — with odds ratio & relative risk (95% CI)

Observed counts. Expected counts, chi-square, df and p are computed from the table.

Row totals (Treated / Control) /
Column totals (YES / NO) /
Expected (Treated YES / NO) /
Expected (Control YES / NO) /
Chi-square statistic
df
p-value
Significance
Odds ratio (OR)
OR 95% CI –
Relative risk (RR)
RR 95% CI –
Treated proportion YES / NO /
Control proportion YES / NO /

B. Up to 4×4 Table

One row per line, counts separated by spaces or commas (up to 4 rows × 4 columns). Leave unused rows/columns blank — as in the workbook, the worked example is a 3×3 table inside the 4×4 grid.

Chi-square statistic (table)
df
p-value
Significance
Grand total
Prefer to work offline or keep a copy? The download link is right below.
Download the Chi-Square Contingency Tables workbook (.xlsx)
Notes & limits (from the workbook): For any expected count < 5, prefer Fisher's exact test. The chi-square here is the uncorrected Pearson statistic (Excel CHIDIST p-value), exactly as in the workbook. The 4×4 section's df counts only rows and columns with a positive total, matching the workbook formulas.