Observed counts in a two-way contingency table are compared with expected counts under independence; cell contributions combine into chi-square and Cramér’s V.
Expected counts come from the table margins; cell contributions add to Pearson’s χ² statistic.
On this page

When a chi-square test of independence fits

Use a test of independence to ask whether two categorical variables are associated in a population represented by your sample. Enter a two-way table of observed frequencies: each case contributes to one cell, and the categories on each variable are mutually exclusive. The test compares the observed counts with the counts expected if the variables were independent.

This is not a chi-square goodness-of-fit test, which compares one categorical variable with a specified distribution. It also does not test a relationship between numeric measurements or a trend across ordered categories. Decide which method matches the question and sampling design before entering counts.

Supporting reading: [1] [2]

Enter a rectangular table of observed counts

Paste a matrix with one row for each category of the first variable and one column for each category of the second. Use spaces, commas, semicolons or tabs between nonnegative whole-number counts, and put each row on a new line. Every row must have the same number of columns, and each row and column needs a positive total.

The example is constructed, not study data. Its two rows and three columns represent hypothetical categories. Replace the counts with observed frequencies from your own table; do not enter percentages, expected counts, individual-level records or confidential identifiers.

How expected counts, χ² and Cramér’s V are calculated

For row i and column j, the expected frequency is the row total multiplied by the column total, divided by the grand total: Eᵢⱼ = RᵢCⱼ/N. Pearson’s statistic adds (Oᵢⱼ − Eᵢⱼ)²/Eᵢⱼ across all cells. The degrees of freedom are (rows − 1)(columns − 1); the reported p-value is the upper-tail probability from that chi-square distribution.

Cramér’s V is √(χ² / [N × min(rows − 1, columns − 1)]), using the uncorrected Pearson statistic. It summarizes association magnitude on a scale from zero to one for this table. It does not supply a direction, establish causation or tell you whether the observed association matters in context. For a 2 × 2 table, the optional Yates continuity correction reduces each absolute observed–expected difference by 0.5 before squaring; the result identifies whether that correction was applied to the test statistic.

Supporting reading: [1] [2] [3]

Check expected frequencies and the sampling design

The chi-square reference distribution is an approximation. When expected frequencies are small, its p-value may be unreliable; a commonly quoted guideline flags cells with expected counts below five, but suitability depends on the table and design. This calculator reports the smallest expected count as a prompt to review the method. For a sparse 2 × 2 table, an exact method may be appropriate; for larger tables, consider an exact or Monte Carlo procedure only when it matches the sampling plan and question.

The table must come from independent cases for the ordinary independence test. Repeated responses, matched pairs, cluster sampling, weighted survey data, structural zeros and categories chosen after inspecting results need methods that account for that design. Do not combine categories solely to make the expected counts larger; any recoding should have a defensible subject-matter reason.

Supporting reading: [1] [2]

Interpret the result without overstating it

A small p-value indicates that the observed table would be unusual under the model of independence and the test assumptions. It does not measure the probability that independence is true, show which cell caused an association, establish a causal effect or measure practical importance. Review the expected and observed values, describe the sampling process and report a separate effect-size interpretation suited to the field.

This browser tool calculates a Pearson statistic and descriptive Cramér’s V. It does not inspect raw records, check missingness, test independence, decide whether the asymptotic approximation is adequate, run post-hoc cell tests, or correct for multiple comparisons. Keep the table’s original category labels with your analysis so the numeric rows and columns remain interpretable.

Free contingency-table calculator

Test whether two categorical variables are associated

Paste observed counts as a rectangular table. Separate columns with spaces, commas, semicolons or tabs, and put each row on a new line.

Constructed example

12   8   20
8   12   20

Two rows and three columns; these counts are illustrative, not study data.

Your counts stay in this browser tab. Do not enter identifiers or confidential information; this tool needs aggregated frequencies only.

The constructed table has 2 rows, 3 columns and 80 cases. Calculate to view expected counts and the test summary.

Questions about this topic

What data do I enter?

Enter a rectangular matrix of observed nonnegative whole-number frequencies. Each row and column represents a category, and each cell is the number of cases in that combination. Do not enter percentages or expected frequencies.

What is the null hypothesis?

The null hypothesis is that the two categorical variables are independent in the population represented by the sampling design. A small p-value is evidence against that model when the test assumptions are reasonable.

What if an expected count is below five?

The asymptotic chi-square approximation may be unreliable for sparse tables. Review the table and design; an exact or Monte Carlo method may be suitable, especially for a sparse 2 × 2 table. The threshold is a diagnostic guideline, not a universal automatic rule.

Does Cramér’s V show which category is associated?

No. Cramér’s V is a direction-free summary of association magnitude. Inspect observed and expected counts and use a planned, multiplicity-aware follow-up if you need to examine cells.

Are my counts uploaded?

No. The calculation runs in this browser tab. The calculator code does not send the entered table to AI Essay.

Sources and editorial notes

The supporting reading below informs our editorial guidance. Exercises and scenarios illustrate a method; they do not report a completed product test or measured learning outcome. Read our editorial policy or send a correction with a supporting source to info@ai-essay.com.

  1. NIST Dataplot: chi-square test of independence for a two-way contingency table
  2. SciPy documentation: chi-square test of independence, expected frequencies and continuity correction
  3. NIST Dataplot: Cramér’s contingency coefficient for an R × C table