Quick Answer
The chi-square statistic is χ² = Σ (O − E)² ÷ E. For the 2 × 2 table 20, 30 / 30, 20, every expected count is 25, so χ² = 4 × 25 ÷ 25 = 4 with 1 degree of freedom, giving p ≈ 0.0455, which is significant at 0.05.
Embed this calculator
Adjust the size if needed, then copy the code below into your page or blog. The calculator will load in an iframe and stay updated automatically.
Table of Contents
- Chi-Square Calculator
- Quick Answer
- Related Calculators
- How This Chi-Square Calculator Works
- How to Use the Chi-Square Calculator
- Core Formulas
- Key Terms
- Worked Example
- Real-Life Examples
- Chi-Square vs T-Test
- Chi-Square Critical Values
- When to Use Chi-Square
- Common Mistakes to Avoid
- Frequently Asked Questions
- References & Sources
How This Chi-Square Calculator Works
For a test of independence, type your table of counts, one row per line. The calculator finds each expected count from the row and column totals, adds up (O − E)² ÷ E over every cell, and finds the p-value from the chi-square distribution with (rows − 1) × (columns − 1) degrees of freedom. For goodness of fit, enter the observed counts and the expected counts or proportions, and it tests whether the data match.
Quick explanation: chi-square measures how far observed counts are from what you would expect.
- Large χ²: big differences from expected.
- Small p-value: the differences are unlikely to be due to chance.
- Counts only: use frequencies, not percentages or averages.
How to Use the Chi-Square Calculator
- Choose a test of independence or goodness of fit.
- Enter the table of counts, or the observed and expected counts.
- Enter the significance level.
- Press Calculate.
- Read χ², df, the p-value and the expected counts.
Core Formulas
- Chi-square: χ² = Σ (O − E)² ÷ E
- Independence expected count: E = row total × column total ÷ grand total
- Independence df: (rows − 1) × (columns − 1)
- Goodness-of-fit df: number of categories − 1
- Cramér’s V: √(χ² ÷ (N × (min(rows, columns) − 1)))
Key Terms
- Observed count (O): the count you recorded.
- Expected count (E): the count you would expect if the null hypothesis is true.
- Contingency table: a table of counts for two categorical variables.
- Degrees of freedom: the number of values free to vary, which sets the χ² curve.
- Cramér’s V: an effect size from 0 (no link) to 1 (strong link).
Worked Example
A die is rolled 60 times: 5, 8, 9, 8, 10, 20. Is it fair?
- Expected: 10 for each face
- χ² = (25 + 4 + 1 + 4 + 0 + 100) ÷ 10 = 13.4
- With 5 df, p ≈ 0.020, so at α = 0.05 the die looks unfair
Real-Life Examples
- Marketing: do preferences differ between age groups?
- Genetics: do offspring match a 3:1 ratio? Enter expected as 3, 1.
- Quality control: are defects spread evenly across shifts?
- Surveys: is the answer to one question related to another?
Chi-Square vs T-Test
- Chi-square: for counts in categories.
- T-test: for comparing means of numeric data.
- Choose by data type: categories use chi-square, measurements use t-tests.
Chi-Square Critical Values
If your χ² is above the value for your df and α, the result is significant.
| df | α = 0.10 | α = 0.05 | α = 0.01 |
|---|---|---|---|
| 1 | 2.706 | 3.841 | 6.635 |
| 2 | 4.605 | 5.991 | 9.210 |
| 3 | 6.251 | 7.815 | 11.345 |
| 4 | 7.779 | 9.488 | 13.277 |
| 5 | 9.236 | 11.070 | 15.086 |
| 6 | 10.645 | 12.592 | 16.812 |
| 8 | 13.362 | 15.507 | 20.090 |
| 10 | 15.987 | 18.307 | 23.209 |
When to Use Chi-Square
- Independence: is there a link between two categories, such as gender and product choice?
- Goodness of fit: do counts match a claimed distribution?
- Expected counts: should mostly be 5 or more.
- Independent observations: each subject should be counted once.
After a significant result, compare the observed and expected tables cell by cell. The cells where the observed count is much higher or lower than expected show where the relationship comes from. For example, if more younger customers than expected chose product A, that cell adds a lot to χ². A significant test tells you there is a link, and this comparison tells you what the link looks like.
Common Mistakes to Avoid
- Using percentages. Enter raw counts.
- Small expected counts. Combine categories or use Fisher’s exact test for tiny samples.
- Counting people twice. Each observation must fall in one cell only.
- Reading significance as strength. Use Cramér’s V for the size of the effect.
- Mismatched lists. Observed and expected must line up in the same order.
Frequently Asked Questions
Sum (O − E)² ÷ E over every cell or category.
(rows − 1) × (columns − 1) for independence, and categories − 1 for goodness of fit.
The chance of a χ² this large or larger if there is really no relationship or the claimed distribution is right.
No. Use the actual counts.
The test may be less reliable. Combine categories or use an exact test.
Type one row per line, with numbers separated by spaces or commas.
Yes. For goodness of fit, they are scaled to your total.
A test of independence with two rows and two columns, with 1 degree of freedom.
The test uses the upper tail of the chi-square distribution.
A measure of how strong the association is, from 0 to 1.
No. It reports Pearson’s chi-square without continuity correction.
Enough that most expected counts are at least 5.
References & Sources
| Source | Used For | Link |
|---|---|---|
| Wikipedia, Pearson’s chi-squared test | Goodness of fit and independence tests. | https://en.wikipedia.org/wiki/Pearson%27s_chi-squared_test |
| NIST/SEMATECH e-Handbook, Chi-Square Goodness-of-Fit Test | Formula and assumptions. | https://www.itl.nist.gov/div898/handbook/eda/section3/eda35f.htm |