Chi-Square Calculator
The chi-square statistic adds up (observed − expected)² ÷ expected across every category or table cell. Compare it with the critical value for your degrees of freedom: categories − 1 for goodness of fit, or (rows − 1) × (columns − 1) for a table. Enter your counts to get χ² and a decision.
Last updated by Ultra Calculator
Chi-Square Test
How to calculate it
χ² = Σ (O − E)² ÷ E Expected count in a table: E = row total × column total ÷ grand total
- χ²
- the chi-square statistic
- O
- the observed count in a category or cell
- E
- the expected count if the null hypothesis is true
- Σ
- add up the result for every category or cell
Degrees of freedom are k − 1 for goodness of fit with k categories (when no parameters are estimated from the data), and (r − 1) × (c − 1) for a table with r rows and c columns. Cramér's V = √(χ² ÷ (n × (the smaller of r and c, minus 1))) measures the strength of association. In Excel, =CHISQ.TEST(observed range, expected range) returns the p-value.
In Excel or Google Sheets: =CHISQ.TEST(A2:A7,B2:B7)
Worked example
Is a die fair?
Rolls of 18, 22, 16, 25, 19 and 20 against an expected 20 for each face give χ² = 2.5 with 5 degrees of freedom. The p-value is 0.7765, far above 0.05, and χ² is well below the 5% critical value of 11.07, so the test gives no evidence the die is biased.
| Test Type | Goodness of fit (one set of counts) |
|---|---|
| Significance Level (α) | 0.05 (5%) |
| Observed Counts | 18, 22, 16, 25, 19, 20 |
| Test | Chi-Square Goodness of Fit Test |
|---|---|
| Chi-Square Statistic (χ²) | 2.5 |
| P-Value | 0.7765 |
| Significant? | No |
| Conclusion | Do not reject the null hypothesis at the 5% level: no evidence against the expected distribution |
| Degrees of Freedom | 5 |
| Critical Value | 11.07 |
| Significance Level (α) | 0.05 (5%) |
| Total Count | 120 |
| Observed Counts | 18, 22, 16, 25, 19, 20 |
| Expected Counts | 20, 20, 20, 20, 20, 20 |
How to use this calculator
- Choose the Test Type and the Significance Level (α).
- Goodness of fit: enter the Observed Counts, and the Expected Counts if the categories should not all be equal.
- 2×2 table: enter the four counts in Cell A to Cell D.
- Larger table: enter the Number of Rows and Number of Columns, then the Table Counts row by row.
- Read the Chi-Square Statistic, the P-Value and the Conclusion. If an expected count is below 5, or the table doesn't match the size you gave, a message says what to change.
Frequently asked questions
How do you calculate chi-square?
For each category or cell, subtract the expected count from the observed count, square it and divide by the expected count. Add these up. For observed counts of 18 and 22 against 20 each, χ² = 4 ÷ 20 + 4 ÷ 20 = 0.4.
What is the difference between goodness of fit and a test of independence?
Goodness of fit compares one set of counts with an expected pattern, such as equal counts for every face of a die. A test of independence uses a table of two categorical variables, such as treatment and outcome, and checks whether they are related.
How are expected counts worked out for a table?
Multiply the row total by the column total and divide by the grand total. In the 2×2 example, row 1 totals 50 and column 1 totals 45 out of 100, so cell A expects 50 × 45 ÷ 100 = 22.5.
What if some expected counts are below 5?
The chi-square approximation becomes unreliable, so this calculator stops and tells you the smallest expected count. Combine small categories where that makes sense, collect more data, or for a 2×2 table use Fisher's exact test.
How do I check the p-value in Excel?
Use =CHISQ.DIST.RT(χ², df) with the statistic and degrees of freedom shown here, or =CHISQ.TEST on your observed and expected ranges. Both give the same p-value as this calculator, because all three use the chi-square distribution. That is an approximation, so for small counts in a 2×2 table Fisher's exact test is the better choice.
Does it apply Yates' continuity correction?
No. The 2×2 test uses the plain Pearson statistic, the same as Excel's CHISQ.TEST. Yates' correction generally gives a smaller χ² and a larger p-value.
Learn more
Observed against expected
Each term (O − E)² ÷ E measures how far a count is from what the null hypothesis predicts, scaled by the size of the prediction. A difference of 10 contributes more when 20 were expected than when 200 were.
Degrees of freedom
Once the totals are fixed, only some counts can vary freely. With k categories, k − 1 are free. In a table, (r − 1) × (c − 1) cells are free and the rest follow from the row and column totals.
Cramér's V for strength
A significant χ² says the variables are related, not how strongly. Cramér's V runs from 0 (no association) to 1 (complete association). For a 2×2 table it equals the size of the phi coefficient, and on the usual guidelines a value of about 0.1 counts as small, 0.3 as medium and 0.5 as large. For bigger tables, what counts as large depends on the table size.
- Testing whether a die, a spinner or a random draw looks fair
- Checking whether customer choices differ between regions or age groups
- Testing whether survey answers depend on a respondent group
- Comparing observed genetic ratios with the expected 3:1 or 9:3:3:1
- Statistics coursework at A-level or university
Entering percentages instead of counts
The test needs raw counts. Percentages hide the sample size, so 60% of 10 and 60% of 1,000 would look the same despite carrying very different amounts of evidence.
Expected counts that don't add up to the observed total
Custom expected counts must sum to the same total as the observed counts. The calculator allows 1% for rounding and scales them to match, but a bigger gap is refused. If you have expected proportions, multiply each by the observed total first.
Reading "do not reject" as proof of a good fit
A non-significant result means the data are compatible with the null hypothesis, not that it is true. That is why the conclusion says "no evidence against" the expected distribution rather than that the data fit it.
Typing decimals as counts
The test works on whole counts, so a decimal such as 12.7 among the observed counts or table counts is rejected with a message. Expected counts can be decimals.
- Each expected count needs to be 5 or more. The calculator checks this and tells you the smallest one if it falls short.
- Report χ², the degrees of freedom, the sample size and the p-value together, for example χ²(1, n = 100) = 9.09, p = 0.0026.
- For comparing means rather than counts, use the t-test calculator.
Methodology and sources
χ² is the sum of (O − E)² ÷ E. For goodness of fit with no expected counts entered, every category expects the total divided by the number of categories, and expected counts you enter must add up to the observed total to within 1%. They are then scaled to exactly that total, keeping their proportions, so rounding in the figures you type doesn't count as a difference. Lists can be separated by commas, spaces or semicolons. Observed counts must be whole numbers, and any expected count below 5 stops the test. No continuity correction is applied to 2×2 tables. The p-value is the upper tail of the chi-square distribution, worked out with the regularised incomplete gamma function, and the critical value is the matching quantile for your α and degrees of freedom. Both are accurate to well beyond the decimals shown. The goodness-of-fit degrees of freedom assume no parameters were estimated from the data.