Skip to content

Chi-Square Calculator — Step-by-Step Solutions

The Chi-Square Calculator performs chi-square goodness of fit tests, tests of independence on contingency tables, computes p-values from chi-square statistics, and looks up critical values for any degrees of freedom and significance level.

Enter your observed and expected frequencies or contingency table data to get instant results with step-by-step working, including the chi-square statistic, degrees of freedom, p-value, and significance conclusion.

Your calculations will appear here

How to Use the Chi-Square Calculator

  1. Select Goodness of Fit to test whether observed counts match an expected distribution, Test of Independence to test whether two categorical variables are related, P-Value from Chi-Square if you already have the statistic, or Critical Value to look up the cut-off for a given alpha.
  2. Goodness of Fit: type the observed counts and the expected counts as comma-separated lists of the same length. Counts must be actual frequencies, not percentages. The expected counts should add up to the same total as the observed ones.
  3. Test of Independence: enter the contingency table with one row per line and the cells separated by commas, for example 30, 10 on the first line and 20, 40 on the second. The calculator works out the expected counts from the row and column totals.
  4. Set alpha (0.05 by default). The result shows the chi-square statistic, degrees of freedom, p-value and whether the result is significant, with each cell contribution in the working.

Formula and Theory

The chi-square statistic compares what you counted with what you would expect if the null hypothesis were true. Each cell contributes (observed - expected)^2 / expected, and the contributions are added up. A large total means the data sit far from the expectation.

In a goodness-of-fit test the expected counts come from the distribution you are testing against, for instance equal numbers for a fair die. The degrees of freedom are the number of categories minus 1. In a test of independence the expected count in each cell is (row total x column total) / grand total, and the degrees of freedom are (rows - 1) x (columns - 1).

The p-value is the area to the right of the statistic under the chi-square curve with those degrees of freedom. The test is always one-sided, because only large values of the statistic count as evidence against the null hypothesis.

The method is an approximation that works well when the expected counts are not tiny. A common rule is that every expected count should be at least 5; if not, combine categories or use an exact test.

Worked Examples

Example 1: Goodness of fit for a die

Problem: A die is rolled 60 times, giving counts of 8, 12, 9, 11, 6, 14 for faces 1 to 6. Is it fair at alpha = 0.05?

Solution: A fair die gives an expected count of 60 / 6 = 10 per face. Contributions: (8-10)^2/10 = 0.4, (12-10)^2/10 = 0.4, (9-10)^2/10 = 0.1, (11-10)^2/10 = 0.1, (6-10)^2/10 = 1.6, (14-10)^2/10 = 1.6. Sum = 4.2. Degrees of freedom = 6 - 1 = 5. The p-value for 4.2 with 5 degrees of freedom is 0.5210.

Answer: chi-square = 4.2, df = 5, p = 0.5210 (no evidence the die is unfair)

Example 2: Test of independence, 2 x 2 table

Problem: Of 100 customers, 50 saw an offer and 50 did not. Rows are bought / did not buy and columns are saw offer / did not: 30, 10 on the first line and 20, 40 on the second. Are buying and seeing the offer related?

Solution: Row totals 40 and 60, column totals 50 and 50, grand total 100. Expected counts: 40 x 50 / 100 = 20, 20, 60 x 50 / 100 = 30, 30. Contributions: 100/20 + 100/20 + 100/30 + 100/30 = 5 + 5 + 3.3333 + 3.3333 = 16.667. Degrees of freedom = (2-1)(2-1) = 1.

Answer: chi-square = 16.667, df = 1, p = 0.0000446 (significant)

Example 3: Test of independence, 2 x 3 table

Problem: Table rows: [20, 30, 50] and [30, 30, 40]. Test independence at alpha = 0.05.

Solution: Row totals 100 and 100; column totals 50, 60, 90; grand total 200. Expected counts for both rows: 25, 30, 45. Contributions: 25/25 = 1, 0/30 = 0, 25/45 = 0.5556 in the first row, and 25/25 = 1, 0, 0.5556 in the second. Sum = 3.1111. Degrees of freedom = (2-1)(3-1) = 2.

Answer: chi-square = 3.111, df = 2, p = 0.2111 (not significant)

Example 4: Critical value

Problem: What chi-square value must be exceeded for significance at alpha = 0.05 with 3 degrees of freedom?

Solution: Use Critical Value mode with alpha = 0.05 and df = 3. The value that leaves 5% in the upper tail is 7.815.

Answer: Critical value = 7.815

Frequently Asked Questions

When should I use a chi-square test?
Use it when your data are counts in categories. The goodness-of-fit version asks whether one categorical variable follows a proposed distribution. The independence version asks whether two categorical variables are associated. It is not for means or continuous measurements.
Can I enter percentages instead of counts?
No. The statistic depends on the real number of observations, so percentages give wrong results. Convert percentages back to counts first; for a goodness-of-fit test the expected counts must sum to the observed total.
What are the degrees of freedom?
For goodness of fit it is the number of categories minus 1. For a contingency table it is (rows - 1) x (columns - 1). A 3 x 4 table has 6 degrees of freedom.
What if an expected count is below 5?
The chi-square approximation becomes unreliable. Merge neighbouring categories so each expected count is at least 5, collect more data, or use Fisher exact test for a 2 x 2 table.
Does a significant result show which cells differ?
Not directly. It says the overall pattern differs from expectation. Look at the cell contributions in the working: the cells with the largest (O - E)^2 / E are the ones driving the result.
Does chi-square show cause and effect?
No. A significant association only shows the variables are related in your data. It does not show that one causes the other, and the strength of the link is not measured by the p-value.

Related Statistics Calculators

Related Articles