The chi-square (ฯยฒ) test is one of the most versatile tools in statistical analysis. Unlike the t-test or ANOVA, which compare averages of continuous variables, the chi-square test is designed specifically for categorical data – data that falls into named groups or classes rather than numerical values. Whether you’re a researcher in psychology, a biologist checking genetic ratios, or a market analyst studying consumer behavior, the chi-square test has direct, practical relevance. It serves three distinct purposes: testing goodness of fit, testing independence, and testing homogeneity. Each application addresses a different type of research question, yet all three rely on the same core formula and logic.
Table of Contents
- The core formula: what all three tests share
- Test of goodness of fit
- What the hypotheses look like
- A practical example
- Degrees of freedom and interpretation
- Test of independence
- The role of the contingency table
- A practical example
- Degrees of freedom and interpretation
- Test of homogeneity
- What the hypotheses look like
- A practical example
- Degrees of freedom and the shared formula
- Putting it all together: choosing the right chi-square test
The core formula: what all three tests share
Before diving into each application, it helps to understand what ties them together. All three uses of the chi-square test rely on the same fundamental formula:
ฯยฒ = ฮฃ [(O โ E)ยฒ / E]
Here, O represents the observed frequency – what you actually count in your data – and E represents the expected frequency – what you would theoretically expect if the null hypothesis were true. The formula squares the difference between observed and expected values, then divides by the expected value, and sums these across all categories. The larger the ฯยฒ value, the greater the mismatch between what was observed and what was expected – and the more likely it is that the null hypothesis should be rejected.
One important condition applies across all three tests: the sample must be randomly selected, and all expected cell counts should be 5 or greater for the chi-square approximation to be reliable.
Test of goodness of fit
The goodness of fit test is the simplest of the three applications. It examines a single categorical variable and asks: does the distribution of my observed data match a theoretical or expected distribution? The chi-square goodness of fit test allows us to assess whether sample data from a categorical variable fits the pattern of expected probabilities based on a prior theory or known distribution.
What the hypotheses look like
The null hypothesis (Hโ) states that the population fits the given distribution, while the alternative hypothesis (Hโ) states that it does not. In other words, you’re testing whether any deviation from expectation is simply due to chance, or whether something more systematic is going on.
A practical example
Consider a classic application from genetics. Gregor Mendel’s work on pea seed shape predicted a 3:1 phenotypic ratio of smooth to wrinkled seeds in the F2 generation. A researcher can use the chi-square goodness of fit test to verify whether Mendel’s observed seed counts actually conform to this predicted ratio. The expected frequencies are calculated by multiplying the total sample size by the theoretically expected proportions (3/4 and 1/4). If the resulting ฯยฒ value is small and the p-value exceeds the significance level (typically 0.05), there is no reason to reject the idea that Mendel’s data fits a 3:1 ratio.
Another example: a psychology faculty member might believe that student absences follow a specific distribution across a semester. A goodness of fit test can compare the actual absenteeism counts recorded for 300 students against the distribution the faculty assumed – revealing whether their perception matches reality.
Degrees of freedom and interpretation
For a goodness of fit test, the degrees of freedom equal the number of categories minus the number of parameters estimated from the data. In the simplest case – where no parameters are estimated – this is simply k โ 1, where k is the number of categories. The chi-square statistic is then compared to a critical value from the chi-square distribution table. Because any difference from expectation inflates the statistic, this test is always right-tailed.
Test of independence
The test of independence moves beyond a single variable. It examines whether two categorical variables are related to each other within a single population. A test of independence assesses whether observations on two variables – expressed in a contingency table – are independent of each other. Think of it this way: if you surveyed people from different countries on a political topic, this test would tell you whether nationality is related to the response.
The role of the contingency table
Data for this test is arranged in a contingency table (also called a cross-tabulation), where rows represent one variable and columns represent another. The expected frequency for each cell is calculated as: (Row Total ร Column Total) / Grand Total. This formula derives the count you would expect in each cell if the two variables were truly unrelated.
A practical example
Suppose a researcher wants to know whether gender and preference for a therapy type (cognitive-behavioral vs. mindfulness-based) are independent in a clinical population. A random sample of 200 participants is drawn, their gender and therapy preference are recorded, and a 2ร2 contingency table is constructed. The null hypothesis here would be: “Gender and therapy preference are independent.” The alternative hypothesis states there is some association between them. If the computed ฯยฒ exceeds the critical value at the chosen significance level, the researcher concludes that gender and therapy preference are not independent – in other words, they are statistically associated.
An e-commerce parallel also illustrates this well: a company studying whether product category preferences are related to payment method choice would use a test of independence, constructing a contingency table of product categories against payment options and testing whether one’s preference in products is associated with how they pay.
Degrees of freedom and interpretation
For the test of independence, the degrees of freedom are calculated as (rows โ 1) ร (columns โ 1). A p-value at or below 0.05 is conventionally taken as sufficient evidence to reject the null hypothesis of independence, suggesting the two variables are related. It’s important to note that a statistically significant result tells you that an association exists – it does not tell you the strength or direction of that relationship.
Test of homogeneity
The test of homogeneity is often confused with the test of independence because they use the same formula and produce a chi-square statistic in the same way. The key difference lies in the study design. In the test of independence, observational units are collected at random from one population and two categorical variables are observed. In the test of homogeneity, the data are collected by randomly sampling from each of several populations separately, and then a single categorical variable is compared across those groups.
What the hypotheses look like
The null hypothesis for homogeneity states that the proportions of the variable being tested are the same across all groups. The alternative hypothesis states that at least one group differs. You are essentially asking: do these populations look the same when it comes to this one categorical outcome?
A practical example
A national study might examine whether steroid use rates differ across three divisions of college athletics. Researchers draw separate random samples from Division I, Division II, and Division III athletes and record whether each athlete reports steroid use or not. The null hypothesis is that each division shares the same distribution of steroid use; the alternative is that steroid use differs across divisions. Expected counts are calculated assuming equal rates across groups, and the chi-square statistic measures how far the actual distribution strays from that assumption. If the p-value is large (as in a real NCAA-based example where p = 0.4561), the data does not provide sufficient evidence to conclude that steroid use varies by division.
Another example: the test of homogeneity can determine whether people of different racial or educational backgrounds share the same proportions of smokers versus non-smokers – a question with clear implications for public health policy.
Degrees of freedom and the shared formula
For both the test of independence and the test of homogeneity, the degrees of freedom are (r โ 1)(c โ 1), where r is the number of rows and c is the number of columns in the contingency table. Both tests calculate the test statistic the same way and require all expected values to be 5 or greater. The distinction is purely conceptual – it is about how the data were gathered and what question is being asked.
Putting it all together: choosing the right chi-square test
Selecting the correct chi-square application depends on your data structure and research question. The goodness of fit test is used when you want to compare an observed distribution to a theoretical one; the test of independence is for determining whether two variables within one population are related; and the test of homogeneity is for comparing the distribution of a single variable across multiple distinct populations.
Here is a quick reference:
- Goodness of fit: One variable, one sample, compared to a known or theoretical distribution. Degrees of freedom = k โ 1.
- Test of independence: Two variables, one population, organized in a contingency table. Degrees of freedom = (r โ 1)(c โ 1).
- Test of homogeneity: One variable, multiple populations sampled separately. Degrees of freedom = (r โ 1)(c โ 1).
In all three cases, the chi-square statistic grows larger when observed frequencies deviate substantially from expected ones, and the p-value tells you whether that deviation is statistically meaningful. Pearson’s chi-squared test is used to determine whether there is a statistically significant difference between expected and observed frequencies – a deceptively simple idea that underpins a remarkable range of real-world analyses, from genetics and psychology to market research and public health.
What do you think? If you were designing a study to examine whether stress management technique preferences differ across age groups, which chi-square application would you use – and how would your sampling strategy change the answer? When your data points to a statistically significant association between two variables, what additional steps would you take before drawing conclusions about cause and effect?
References
- https://en.wikipedia.org/wiki/Pearson%27s_chi-squared_test
- https://bookdown.org/blazej_kochanski/statistics2/chisq-tests.html
- https://courses.lumenlearning.com/wm-concepts-statistics/chapter/test-of-homogeneity/
- https://ecampusontario.pressbooks.pub/introstats/chapter/10-4-the-goodness-of-fit-test/
- https://courses.lumenlearning.com/introstats1/chapter/comparison-of-the-chi-square-tests/
- https://psfaculty.plantsciences.ucdavis.edu/PLS120/PLS120Book/docs/chChisq.html
- https://medium.com/@sabourinleandre/chi-square-test-explained-goodness-of-fit-and-test-of-independence-41e3daa893db
- https://medium.com/nerd-for-tech/understanding-the-chi-square-test-applications-and-real-world-examples-956e005a7104
- https://rinterested.github.io/statistics/chi_square_test_independence_homogeneity.html
- https://www.savemyexams.com/ap/statistics/college-board/20/revision-notes/inference/independence-and-homogeneity-chi-square/tests-for-homogeneity/
- https://rinterested.github.io/statistics/chi_square_GOF.html
- https://stats.libretexts.org/Courses/Las_Positas_College/Math_40:_Statistics_and_Probability/11:_Chi-Square_and_Analysis_of_Variance_(ANOVA)/11.02:_Tests_Using_Contingency_tables/11.2.03:_Comparison_of_the_Chi-Square_Tests
- https://en.wikipedia.org/wiki/Chi-squared_test
Leave a Reply