What is the chi-square test?
The chi-square test (written as χ² test) is one of the most widely used statistical hypothesis tests. It evaluates whether observed categorical data matches what you would expect under a specific hypothesis. Unlike tests for means or proportions, the chi-square test works with counts of observations falling into distinct categories.
There are two main types of chi-square tests:
**Goodness-of-fit test:** Tests whether a single categorical variable follows a hypothesized distribution. For example, does a six-sided die produce each face roughly equally often? Or does the distribution of blood types in a sample match the known population percentages?
**Test of independence:** Tests whether two categorical variables are associated with each other. For example, is there a relationship between smoking status and lung disease? Is customer satisfaction independent of store location? This version uses a contingency table showing counts for each combination of categories.
How the chi-square statistic is calculated
Both test types share the same core formula:
\`\`\` χ² = Σ (O - E)² / E \`\`\`
Where: - O = observed frequency in a category - E = expected frequency under the null hypothesis - Σ = sum over all categories
The larger the difference between what you observed and what you expected, the larger the chi-square statistic, and the more evidence you have against the null hypothesis.
**Degrees of freedom** determine the shape of the chi-square distribution used to find the p-value: - Goodness-of-fit: df = number of categories − 1 - Independence test: df = (number of rows − 1) × (number of columns − 1)
**Expected frequencies for the independence test** are calculated assuming independence: \`\`\` E(row r, col c) = (row total × column total) / grand total \`\`\`
How to interpret the p-value
The p-value is the probability of observing a chi-square statistic at least as large as yours if the null hypothesis were true.
Common significance thresholds: - **p < 0.05**: Statistically significant. Reject the null hypothesis at the 5% level. - **p < 0.01**: Highly significant. Reject the null hypothesis at the 1% level. - **p ≥ 0.05**: Not significant. You do not have enough evidence to reject the null hypothesis.
A significant result does not prove the alternative is true. It means the data are inconsistent with the null hypothesis at your chosen significance level.
**Effect size matters too.** A very large sample can produce a tiny p-value even when the actual association is negligible. Always consider the magnitude of differences alongside statistical significance.
Assumptions and when chi-square may not apply
The chi-square test rests on several assumptions. Violating them can make results unreliable.
1. **Expected cell counts of 5 or more.** If any expected count is below 5, the chi-square approximation becomes inaccurate. The calculator flags these cells with a warning. Options include combining categories or using Fisher's exact test.
2. **Independent observations.** Each person or unit should appear in only one cell. Repeated-measures or paired data require different tests.
3. **Sufficient sample size.** Very small total sample sizes make chi-square unreliable regardless of cell counts.
4. **Categorical data only.** Chi-square is designed for counts of categories. For continuous data, use t-tests, ANOVA, or correlation tests.
5. **Random sampling.** Observations should be randomly drawn from the population of interest for the test to generalize.
How to use
1. Choose a test mode: **Goodness-of-Fit** for one variable tested against a distribution, or **Independence Test** for the relationship between two variables. 2. **Goodness-of-Fit:** Enter your observed counts as comma-separated numbers (e.g. 10, 20, 30). Check the box for equal expected frequencies (uniform distribution) or enter your own expected frequencies. 3. **Independence Test:** Select the table size (2×2, 2×3, 3×2, or 3×3) and fill in the observed counts for each cell of your contingency table. 4. Click **Calculate Chi-Square** to see the test statistic, degrees of freedom, p-value, and interpretation. 5. Review the observed-vs-expected breakdown or expected frequency table. Cells with expected counts below 5 are flagged automatically.
FAQs
Q: What is the null hypothesis in each test? A: For the goodness-of-fit test, the null hypothesis is that the observed data follow the specified distribution. For the independence test, the null hypothesis is that the two categorical variables are independent of each other (no association).
Q: What does a chi-square statistic of zero mean? A: A value of zero means the observed frequencies exactly match the expected frequencies. This indicates perfect agreement with the null hypothesis, so p = 1.
Q: Why is an expected frequency of less than 5 a problem? A: The chi-square distribution is a mathematical approximation for the distribution of the test statistic. That approximation breaks down when expected cell counts are very small, potentially leading to inaccurate p-values. Fisher's exact test is preferred for 2×2 tables with small counts.
Q: Can I use this for more than three rows or columns? A: This calculator supports tables up to 3×3. For larger tables, the same formula applies. You can extend the calculation manually: df = (rows − 1) × (cols − 1), and the chi-square statistic is still the sum of (O − E)² / E over all cells.
Q: What is the difference between a one-tailed and two-tailed chi-square test? A: The chi-square test is always one-tailed in the sense that the test statistic is always non-negative and large values always indicate departure from the null hypothesis. There is no concept of direction for chi-square tests.
Q: What if my expected frequencies do not sum to the same total as observed? A: This calculator automatically scales your expected frequencies to match the observed total, which is the standard approach when you specify expected proportions rather than exact counts.
Q: How do I know which chi-square test to use? A: Use the goodness-of-fit test when you have one categorical variable and want to compare its distribution to a theoretical one. Use the independence test when you have two categorical variables and want to know whether they are related.
Explore Similar Tools
Explore more tools like this one:
- A/B Test Calculator — Determine the statistical significance of your... - ANOVA Calculator — One-way and two-way analysis of variance with... - A/B Test Significance Calculator — Enter visitors and conversions for two variations to... - Quartile Calculator – IQR Calculator — Calculate quartiles (Q1, Q2, Q3) and interquartile range... - T-Test Calculator — Perform a T-test to compare the means of two groups and...