Chi-Square Test: Definition, Formula, and When to Use It
In the experimental workflow: for how the chi-square test is used when designing and running experiments, see Inference.
The chi-square test (χ² test) is an inferential statistical test that compares observed frequencies with expected frequencies to answer two common questions:
- Goodness of fit — does a sample distribution match an expected theoretical distribution?
- Independence (or homogeneity) — are two categorical variables related, or do they occur independently?
It is one of the most widely used non-parametric tests in psychology and the social sciences because it works with categorical (nominal) data — counts of people, responses, or events in categories.
Table of Contents
- What Is a Chi-Square Test?
- Types of Chi-Square Tests
- The Chi-Square Formula
- Worked Example: Test of Independence
- Degrees of Freedom and the Chi-Square Table
- Assumptions and Limitations
- How to Run a Chi-Square Test
- Frequently Asked Questions
- Key Takeaways
What Is a Chi-Square Test?
A chi-square test asks: how likely is it that the differences between what we observed and what we expected are due to chance?
- If the difference between observed and expected frequencies is large, the chi-square statistic is large, the p-value is small, and we conclude the variables are related (or the distribution differs from expectation).
- If the difference is small, the chi-square statistic is small, and the data are consistent with the null hypothesis of no relationship.
Because it deals with counts rather than means, chi-square tests are the natural choice for survey responses, experimental group counts, and categorical outcomes (yes/no, category labels).
Types of Chi-Square Tests
| Test | Question it answers | Example |
|---|---|---|
| Goodness of fit | Does one categorical variable fit an expected distribution? | Are birth months evenly distributed in a class? |
| Test of independence | Are two categorical variables related? | Is gender associated with voting preference? |
| Test of homogeneity | Do different groups have the same distribution of a category? | Do three age groups differ in exercise frequency? |
All three use the same chi-square statistic; they differ in how the expected frequencies are calculated.
The Chi-Square Formula
For each category, compute:
χ² = Σ ( (Observed − Expected)² / Expected )
Steps:
- Build a contingency table of observed counts (rows = one variable, columns = the other).
- Compute expected counts for each cell:
- Goodness of fit: expected = total × hypothesized proportion
- Independence/homogeneity: expected = (row total × column total) / grand total
- For each cell, calculate (Observed − Expected)² / Expected.
- Sum across all cells to get χ².
- Compare χ² to the critical value from a chi-square distribution table at the chosen significance level (usually 0.05) and the correct degrees of freedom.
Worked Example: Test of Independence
Question: Is gender associated with choosing "indoor" vs "outdoor" leisure?
| Indoor | Outdoor | Row total | |
|---|---|---|---|
| Female | 30 | 20 | 50 |
| Male | 18 | 32 | 50 |
| Column total | 48 | 52 | 100 |
Expected frequency for each cell = (row total × column total) / grand total.
- Female–Indoor expected: (50 × 48) / 100 = 24
- Female–Outdoor expected: (50 × 52) / 100 = 26
- Male–Indoor expected: (50 × 48) / 100 = 24
- Male–Outdoor expected: (50 × 52) / 100 = 26
Chi-square contributions:
- Female–Indoor: (30 − 24)² / 24 = 1.50
- Female–Outdoor: (20 − 26)² / 26 = 1.38
- Male–Indoor: (18 − 24)² / 24 = 1.50
- Male–Outdoor: (32 − 26)² / 26 = 1.38
χ² = 5.76. Degrees of freedom = (rows − 1) × (columns − 1) = 1. At α = 0.05, the critical value is 3.84. Since 5.76 > 3.84, we reject the null hypothesis and conclude gender and leisure choice are associated.
Degrees of Freedom and the Chi-Square Table
- Goodness of fit: df = k − 1 (k = number of categories)
- Independence/homogeneity: df = (r − 1) × (c − 1) (r rows, c columns)
The chi-square distribution changes shape with df. To interpret a result, find the critical value at your df and significance level in a chi-square table, or use statistical software that reports the exact p-value. Note that the chi-square distribution is not the standard normal distribution; unlike a z-test, chi-square p-values cannot be read from a z-score table.
Assumptions and Limitations
Chi-square tests require:
- Categorical data — counts in categories, not means or ranks
- Independent observations — each case counted once; no paired or repeated measurements in the same test
- Adequate expected frequencies — the rule of thumb is no more than 20% of cells with expected count < 5, and none below 1; otherwise combine categories or use Fisher's exact test
- Random sampling — data should represent the population of interest
Limitations:
- The test says whether a relationship exists, not how strong it is — use Cramér's V or phi for effect size
- Large samples can make trivial differences statistically significant
- It does not reveal which categories differ — follow with residual analysis or post-hoc tests
How to Run a Chi-Square Test
- State the null hypothesis (no association / fits distribution) and alternative hypothesis.
- Build the contingency table and calculate expected frequencies.
- Compute χ² with the formula above.
- Determine df and find the critical value or p-value.
- Compare and draw a conclusion; report effect size for meaningfulness.
For quick calculation, you can standardize your data with the z-score table tool and explore related concepts in inferential statistics.
Frequently Asked Questions
What is a chi-square test used for?
It tests whether observed categorical frequencies differ from expected frequencies — used for goodness-of-fit tests and tests of independence/homogeneity between categorical variables.
What is the chi-square formula?
χ² = Σ ((Observed − Expected)² / Expected), summed across all cells.
When should you not use a chi-square test?
Do not use it with continuous data (use t-tests or ANOVA), small expected frequencies (combine categories or use Fisher's exact test), or dependent/repeated observations.
What does a significant chi-square mean?
It means the observed data are unlikely under the null hypothesis — there is evidence of an association between the variables (or a deviation from the expected distribution). It does not indicate the strength or direction of the association.
What is the difference between chi-square and t-test?
A t-test compares means of continuous data; a chi-square test compares frequencies of categorical data.
Key Takeaways
- The chi-square test compares observed and expected frequencies for categorical data.
- Three applications: goodness of fit, independence, and homogeneity.
- Formula: χ² = Σ ((Observed − Expected)² / Expected).
- Degrees of freedom: (rows − 1) × (columns − 1) for contingency tables; k − 1 for goodness of fit.
- Check assumptions — independent observations and adequate expected frequencies — and report effect size alongside significance.
Related Resources
- Inferential Statistics — the family of tests chi-square belongs to
- Correlation Analysis — measuring relationships between variables
- Experimental Design — where categorical outcomes come from
- Z-Score Table Tool — standardizing scores and reading statistical tables
- Chi-Square Calculator — compute χ², degrees of freedom, and the p-value from your contingency table
- Research Methods Home — the full statistical toolkit
Methodology
Methodology: This topic is part of the experimental workflow covered in Experimentology. For the relevant methods and how they are evaluated in real experiments, see Inference and Models.
References
- Pearson, K. (1900). On the criterion that a given system of deviations is due to chance. Philosophical Magazine, 50(302), 157-175.