Skip to content

Chi-Square Test Calculator

χ² test of independence for a contingency table (up to 6 × 6) or goodness of fit, with p-value, expected counts and Cramér’s V.

Your details

Test
Contingency table (observed counts)

One row per category of the first variable, one column per category of the second. Leave unused columns blank.

%

Results update as you type

Chi-square statistic χ²

23.8314

p-value
6.7 × 10⁻⁶
Decision
Reject H₀ at α = 5%
Degrees of freedom
2
Critical value χ²(α)
5.9915
Cramér’s V (effect size)
0.2729
Smallest expected count
25.78
Total count n
320

Step-by-step solution
  1. E_ij = (row total × column total) / n ; n = 320
  2. χ² = Σ (O − E)² / E = 23.8314
  3. df = (r − 1)(c − 1) = (2 − 1)(3 − 1) = 2
  4. V = √(χ² / (n · 1)) = 0.2729
  5. p = P(χ²(2) ≥ 23.8314) = 6.7 × 10⁻⁶

Observed and expected counts per cell

The chi-square (χ²) test compares the counts you observed with the counts you would expect if a hypothesis were true. It is the standard tool for categorical data — answers to a survey question, blood groups, colours of sweets in a bag, outcomes of a die — and comes in two forms, both handled here.

  • Test of independence: you cross two categorical variables in a contingency table (up to 6 rows × 6 columns), for example home zone × commute mode. The null hypothesis is that the two variables are unrelated.
  • Goodness of fit: you have one categorical variable and a theoretical distribution — equal shares, a genetic ratio such as 9:3:3:1, published market shares — and you test whether the observed counts fit it.

For each test the calculator reports the χ² statistic, the degrees of freedom, the p-value (exact upper tail of the chi-square distribution), the decision at your significance level, the critical value, a table of expected counts with each cell's contribution, and, for tables, Cramér's V to measure the strength of the association. It warns you when expected counts are too small for the test to be trusted.

How to use this calculator

Test of independence

  1. Keep "Independence (table)" selected.
  2. Type the observed counts: one row per category of the first variable, one column per category of the second. Leave unused columns blank; add rows up to 6.
  3. Set the significance level α (5 % by default) and read χ², the p-value and the decision.

Goodness of fit

  1. Select "Goodness of fit".
  2. For each category, enter the observed count and, in the second column, the expected proportion (a ratio like 9, 3, 3, 1, percentages or decimals all work), or the expected counts — tell the calculator which in the menu. Choose "all categories equally likely" to test a uniform distribution.
  3. If you estimated parameters of the theoretical distribution from the same data, enter how many: each one removes a degree of freedom.

Always enter counts, never percentages, in the observed column: the test depends on the sample size.

The formula

Both tests use Pearson's statistic, summed over every cell or category:

χ2=∑(O−E)2E\chi^2 = \sum \frac{(O - E)^2}{E}

Independence. For the cell in row ii and column jj, the expected count under independence is

Eij=Ri×CjnE_{ij} = \frac{R_i \times C_j}{n}

with RiR_i and CjC_j the row and column totals. The degrees of freedom are (r−1)(c−1)(r - 1)(c - 1) and the effect size is Cramér's V=χ2/(n (min⁡(r,c)−1))V = \sqrt{\chi^2 / \big(n\,(\min(r, c) - 1)\big)}, between 0 and 1.

Goodness of fit. With kk categories and expected proportions pip_i, Ei=n piE_i = n\,p_i and df=k−1−m\text{df} = k - 1 - m, where mm is the number of estimated parameters.

The p-value is the upper tail P(χdf2≥χ2)P(\chi^2_{\text{df}} \ge \chi^2), computed from the regularized incomplete gamma function Q(df/2, χ2/2)Q(\text{df}/2,\ \chi^2/2). The approximation is reliable when every expected count is at least 5.

Worked example

Independence. A town surveys 320 commuters by home zone and usual mode of transport:

Car Bike Public transport
Centre 40 35 75
Suburbs 90 20 60

The centre has 150 people and the car column 130, so E11=150×130/320=60.94E_{11} = 150 \times 130 / 320 = 60.94; likewise E12=25.78E_{12} = 25.78 and E22=29.22E_{22} = 29.22. Summing the six contributions gives χ2=23.83\chi^2 = 23.83 with (2−1)(3−1)=2(2-1)(3-1) = 2 degrees of freedom, and a p-value of 6.7 × 10⁻⁶. Commute mode clearly depends on the zone. Cramér's V=0.273V = 0.273 points to a weak-to-moderate association.

Goodness of fit. In one of his pea experiments Mendel counted 315 round-yellow, 101 wrinkled-yellow, 108 round-green and 32 wrinkled-green seeds (556 in all). The 9:3:3:1 ratio predicts 312.75, 104.25, 104.25 and 34.75. Then χ2=0.47\chi^2 = 0.47 with 3 degrees of freedom and p = 0.9254: the data fit the theory very well.

Reading the result and checking the conditions

A small p-value (below α) means the observed counts are too far from the expected ones to be put down to chance: you reject independence, or reject the theoretical distribution. A large p-value does not prove the hypothesis; it only means the data are compatible with it.

The test is valid when the observations are independent (each person or item counted once), the data are counts and the expected counts are large enough. The usual rule asks for all expected counts ≥ 5; a more lenient version (Cochran) accepts up to 20 % of cells below 5 provided none is below 1. The calculator flags both situations. When they fail, merge sparse categories, collect more data or, for a 2 × 2 table, use Fisher's exact test.

Effect size, critical value and related tools

With a large sample even a trivial association becomes significant, so look at Cramér's V as well: as a rough guide, about 0.1 is weak, 0.3 moderate and 0.5 or more strong (for tables with 2 columns or rows). The critical value is the χ² above which you reject at level α; comparing it with your statistic gives the same decision as comparing p with α. To look up other χ² tail areas or quantiles, use the p-value calculator and the critical value calculator; for the degrees of freedom of other tests, see the degrees of freedom calculator.

Frequently asked questions

When should I use a chi-square test?

When your data are counts in categories. Use the test of independence to see whether two categorical variables are related (for example gender and voting intention), and the goodness-of-fit test to compare one variable with a theoretical distribution (for example whether a die is fair).

How are expected frequencies calculated?

In a contingency table, multiply the row total by the column total and divide by the grand total. In a goodness-of-fit test, multiply the total count by the expected proportion of each category. The calculator lists every expected count in the table under the result.

What if some expected counts are below 5?

The chi-square approximation becomes unreliable and the p-value may be too small. Merge neighbouring categories, gather more data, or switch to an exact test. The calculator warns you and shows the smallest expected count.

Can I enter percentages instead of counts?

Not for the observed values. χ² grows with the sample size, so the same percentages give very different results for 50 and 5,000 people. Percentages or ratios are fine for the expected proportions in the goodness-of-fit mode.

What is the difference between the chi-square test of independence and homogeneity?

The arithmetic is identical. Independence uses one sample classified by two variables; homogeneity compares the distribution of one variable across several separately sampled groups. You can use the independence mode for both.

Sources

Last updated:

More Statistics calculators

People also use