Chi-Square Calculator

Test whether two categorical variables are related, or whether counts match expected proportions. Type the observed counts into the table and get the chi-square statistic, degrees of freedom, p-value, expected counts, adjusted residuals and the effect size, ready to report.

Test

Are two categorical variables related? Enter counts in a contingency table.

Observed counts
Total
50
50
Total4555100
Yates’ continuity correction (2 × 2 only)

Off matches most textbooks and SPSS’s Pearson row; on matches R’s chisq.test default.

Load a worked example

Chi-square test of independence (2 × 2)

0.0026p-value

χ²(1, N = 100) = 9.091. The variables are significantly associated at α = 0.05.

Pearson χ²
9.0909
Degrees of freedom
1
p-value
0.0026
Phi (φ)
0.302
medium
Smallest expected count
22.50
Cells with expected < 5
0 of 4

Expected counts and adjusted residuals

Expected = row total × column total ÷ N. A residual beyond ±1.96 marks a cell that contributes to the association.

Expected counts with adjusted standardized residuals
ImprovedNot improved
Treatment22.5 (+3.02)27.5 (−3.02)
Control22.5 (−3.02)27.5 (+3.02)

Report it like this

A chi-square test of independence showed a statistically significant association between the row variable (Treatment, Control) and the column variable (Improved, Not improved), χ²(1, N = 100) = 9.09, p = .003, φ = .30.

How to use the calculator

  1. Choose the test. Independence compares two variables in a contingency table; goodness of fit compares one variable with expected shares.
  2. Enter counts, not percentages. Each cell is the number of people or items in that combination. Rename rows and columns by typing over their labels, and add rows or columns up to 6 × 6.
  3. Read the result. The p-value, χ², degrees of freedom and effect size update as you type. Check the expected counts and the warnings before you report.

The chi-square test needs raw counts. If you only have percentages, multiply each one by its group size to get the counts first.

The chi-square formula

The statistic adds up, over every cell, how far the observed count is from the count expected if the variables were unrelated:

χ² = Σ (O − E)² / E,   E = (row total × column total) / N

The degrees of freedom are (rows − 1) × (columns − 1) for a contingency table and (categories − 1) for goodness of fit. The p-value is the upper tail of the chi-square distribution with those degrees of freedom.

Yates’ correction subtracts 0.5 from each |O − E| in a 2 × 2 table. It makes the test more conservative; many statisticians now prefer the uncorrected test, or Fisher’s exact test when counts are small (Campbell 2007).

Effect size. Phi (φ) = (ad − bc) / √(row and column totals multiplied) for a 2 × 2 table. Cramér’s V = √(χ² / [N × (k − 1)]), where k is the smaller of the number of rows and columns. Cohen’s benchmarks for a 2 × 2 table are 0.1 small, 0.3 medium and 0.5 large; for bigger tables divide them by √(k − 1).

Adjusted residuals (Haberman 1973) show which cells drive a significant result: values beyond ±1.96 differ from independence at about the 5% level.

Worked example

In a trial, 30 of 50 patients improved with treatment and 15 of 50 with control (the calculator’s default table).

  • 45 of 100 improved overall, so each group of 50 is expected to have 22.5 improved and 27.5 not improved.
  • χ² = (30 − 22.5)²/22.5 + (20 − 27.5)²/27.5 + (15 − 22.5)²/22.5 + (35 − 27.5)²/27.5 = 9.09
  • df = (2 − 1)(2 − 1) = 1, so p = .003; φ = .30, a medium association.
  • With Yates’ correction, χ² = 7.92 and p = .005.

The 3 × 3 example (diet by activity level, N = 140) gives χ²(4) = 17.13, p = .002, Cramér’s V = .25, and the goodness-of-fit example (50, 30 and 20 against shares of 2 : 1 : 1) gives χ²(2) = 2.00, p = .368.

How to report a chi-square test in APA style

Give the degrees of freedom and the sample size in brackets, χ² to two decimals, the exact p-value and an effect size:

A chi-square test of independence showed a statistically significant association between treatment group and improvement, χ²(1, N = 100) = 9.09, p = .003, φ = .30. Improvement was more common with treatment (60%) than with control (30%).

Report the percentages as well, so readers can see the direction of the association. For 2 × 2 tables in medical papers, journals often prefer an odds ratio or relative risk with its confidence interval; the odds ratio calculator gives both from the same four counts.

Assumptions and small counts

  • Independent observations: each person or item is counted once, in one cell. Before-and-after counts on the same people need McNemar’s test instead.
  • Large enough expected counts: Cochran’s rule asks for no expected count below 1 and no more than 20% below 5. The calculator checks this for you.
  • Counts, not percentages or means.

When a 2 × 2 table has an expected count below 5, use the Fisher’s exact test calculator. For larger sparse tables, combine categories that make sense together or use an exact test in statistical software.

To plan the sample size for a chi-square test, use the chi-square option in the power analysis calculator.

Questions

How do I calculate a chi-square test?
Enter the observed counts in a contingency table. For each cell the expected count is the row total times the column total divided by the grand total. Add up (observed − expected)² ÷ expected over all cells to get χ², use (rows − 1) × (columns − 1) degrees of freedom, and read the p-value from the chi-square distribution. The calculator does each step and shows the expected counts.
What is the difference between the chi-square test of independence and goodness of fit?
The test of independence uses a table of two variables and asks whether they are related, for example treatment group and outcome. The goodness-of-fit test uses one variable and asks whether its counts match expected proportions, for example whether 100 births are spread evenly over the four seasons.
When should I use Fisher’s exact test instead of chi-square?
Use Fisher’s exact test for a 2 × 2 table when any expected count is below 5. The chi-square p-value is an approximation that becomes unreliable with small expected counts, while Fisher’s test computes the exact probability.
Should I use Yates’ continuity correction?
It is optional and only applies to 2 × 2 tables. Yates’ correction makes the chi-square test more conservative, often too conservative. Many statisticians report the uncorrected Pearson chi-square for adequate counts and Fisher’s exact test for small counts. R applies the correction by default; SPSS shows both.
How do I calculate degrees of freedom for a chi-square test?
For a test of independence, df = (number of rows − 1) × (number of columns − 1), so a 2 × 2 table has 1 and a 3 × 4 table has 6. For goodness of fit, df = number of categories − 1, minus one more for each parameter estimated from the data.
What does a significant chi-square result mean?
It means the observed counts would be unlikely if the two variables were independent, so the variables are associated. It does not tell you how strong the association is (look at phi or Cramér’s V) or which cells differ (look at the adjusted residuals), and it does not show cause and effect.
Can I use percentages in a chi-square test?
No. The test needs raw counts because its result depends on the sample size: 60% vs 30% is highly significant with 1,000 people per group but not with 10. Convert percentages back to counts by multiplying by each group’s size.

Sources