The Chi-Squared Test is a statistical hypothesis test designed for analyzing contingency tables to determine if two categorical variables are independent of one another.
Data analysts and statisticians who work with large sample sizes and categorical data consult this test when they need to assess the relationship between different variables.
External context
This test is specifically used in the analysis of contingency tables when dealing with sufficiently large samples. It helps users determine whether two distinct categorical variables are independent, meaning one variable does not influence the other. Understanding its application allows you to correctly measure dependency within your data sets.
Chi-squared test Wikipedia contributors, “Chi-squared test”, en.wikipedia.orgLicence01What it is and how it works
The test starts with a contingency table of observed frequencies O_i for each category. Expected frequencies E_i are calculated from the null hypothesis (often assuming equal proportions or independence). The chi‑squared statistic is Σ (O_i − E_i)^2 / E_i. Under the null, this statistic follows a chi‑squared distribution with k − 1 degrees of freedom, where k is the number of categories. A large statistic yields a small p‑value, suggesting the observed pattern is unlikely due to random variation alone.
It checks if the numbers you see match what you would expect by chance.
02What to do about it
First, gather categorical data and build a contingency table. Verify that each expected count is at least five; if not, consider merging categories or using an exact test. Compute the chi‑squared statistic using a spreadsheet function like CHISQ.TEST or a statistical package (R, Python’s scipy.stats.chisquare). Compare the resulting p‑value to your chosen alpha (commonly 0.05). If p < alpha, reject the null and look at standardized residuals to see which cells drive the difference. Document the degrees of freedom, statistic value, and p‑value in your report.
03How it is measured or noticed
Software outputs typically include the chi‑squared statistic, degrees of freedom, and p‑value. In a spreadsheet, the formula =CHISQ.TEST(observed_range, expected_range) returns the p‑value directly. Statistical packages print a table with χ², df, and p. You can also notice the test by looking at a contingency table where the observed counts deviate noticeably from the expected counts; the larger the deviations, the larger the χ² value. Diagnostic plots such as a mosaic plot can visualise these discrepancies.
How the record puts it
A chi-squared test is a statistical hypothesis test used in the analysis of contingency tables when the sample sizes are large.
04Common mistakes
- Using the test when any expected frequency is below five, which inflates Type I error.
- Applying chi‑squared to ordinal data as if it were nominal, losing information about order.
- Ignoring multiple comparisons when testing many tables without adjusting alpha.
- Interpreting a significant result as proof of causation rather than mere association.
- Failing to set an explicit alpha level before looking at the p‑value.
- Treating the chi‑squared statistic as a measure of effect size; it depends on sample size.
- Using the test on paired or matched data without accounting for the dependency.
- Confusing the chi‑squared test of independence with the goodness‑of‑fit test when the hypotheses differ.
05Limits
The chi‑squared approximation breaks down with small sample sizes or sparse tables; in those cases Fisher’s exact test (for 2×2) or Monte‑Carlo simulation is preferable. It is not suitable for continuous measurements; a t‑test or ANOVA would be used instead. The test is often confused with the likelihood‑ratio chi‑squared, which uses a different formula but similar distribution. Additionally, a significant chi‑squared does not indicate the direction or magnitude of the difference; post‑hoc residuals are needed for that interpretation.
06Worked example
"Suppose you survey 200 people about brand preference (A, B, C). Observed counts: A=70, B=80, C=50. Expected if no preference: 66.7 each. Chi‑squared = (70-66.7)^2/66.7 + (80-66.7)^2/66.7 + (50-66.7)^2/66.7 ≈ 2.0. With df=2, p≈0.37, so no significant preference."
The entry above is written by GetLoopLoop. What follows is what independent catalogues hold about the same term — none of it is the source of this page.
- Also called
- chi-squared test, chi square test, χ2 test
- Kind of thing
- statistical test
The same term on Wikipedia
Catalogued in 40 languagesFrequently asked questions
What is the difference between a chi-squared test and a t-test?
A chi-squared test compares counts in categories against an expected distribution, while a t-test compares the means of a continuous variable between two groups. If your data are frequencies in a contingency table, use chi-squared; if they are numeric measurements, use a t-test. Confusing the two produces meaningless p-values because the underlying assumptions are different.
When should I not use a chi-squared test?
Avoid it when expected cell counts fall below about 5, or when the table is sparse with many low-frequency cells, because the chi-squared distribution is no longer a good approximation. In those cases switch to Fisher's exact test (for 2x2 tables) or a Monte-Carlo simulation. The symptom of misuse is a reported p-value that does not match what resampling the data actually produces.
What does the chi-squared statistic actually measure?
It sums the squared differences between observed and expected counts, each divided by the expected count: Σ (O_i − E_i)² / E_i. A larger value means observed counts deviate further from what the null hypothesis predicts. The p-value is then derived from a chi-squared distribution with degrees of freedom based on the table's dimensions.
How do I know the right number of degrees of freedom?
For a standard contingency table, degrees of freedom equal (rows − 1) × (columns − 1). For a goodness-of-fit test against a known distribution, use (categories − 1) minus any parameters estimated from the data. Getting this wrong shifts the entire p-value, so always check the software's reported df against your table shape.
Does a small p-value mean my categories are related?
It means the observed pattern is unlikely under the assumption that the categories are independent, but it does not measure the strength of the relationship. For a 2x2 table, look at the odds ratio; for larger tables, consider Cramér's V or phi. A significant chi-squared test with a tiny effect size can arise simply from a large sample.
Can I run a chi-squared test on a 2x2 table by hand?
Yes, but with a correction. For 2x2 tables, apply Yates' continuity correction, or better, use Fisher's exact test which is exact rather than approximate. The uncorrected chi-squared can overstate significance in small samples.
Wikimedia Commons
Related visuals with source and licence credit


Asked out loud
spoken, not typedThe same term in the words somebody uses speaking to an assistant rather than typing into a box — written from the situation, which is why each one carries the situation it came from.
No, that result is unreliable. When expected cell counts drop below about five, the chi-squared distribution stops being a good approximation and your p-value drifts. Recompute with Fisher's exact test for 2x2 tables, or use a Monte-Carlo simulation for larger sparse tables.
Probably not, but you answered the wrong question. Chi-squared tests for independence, not strength, and a large sample can produce a small p-value from a trivial association. Report a measure of effect size, like Cramér's V, alongside the p-value to show how meaningful the difference actually is.
The tools are likely using different defaults, such as Yates' continuity correction, or different expected-count thresholds for warnings. Check whether each is applying a correction, and confirm both are using the same degrees of freedom formula. Once the settings match, the statistics should match too.