When researchers collect survey data, they often end up with answers sorted into categories rather than neat numbers. Did a respondent use the digital library or not? Are they male or female? Do they prefer print or e-books? These are categorical variables, and ordinary tools like averages and correlation coefficients simply do not work on them. To find out whether two such variables are connected, researchers turn to a pair of closely linked tools: the contingency table and the chi-square test. Together, they let you answer a deceptively simple question with statistical confidence: are these two things related, or is the pattern I am seeing just chance?
Table of Contents
- What is a contingency table?
- Why not just use correlation?
- The chi-square test explained
- Calculating expected frequencies
- The chi-square formula
- Assumptions you cannot ignore
- Interpreting the results
- Finding the degrees of freedom
- Comparing against the critical value
- Reading the p-value
- What the test does and does not tell you
What is a contingency table?
A contingency table is a grid that organises data according to two categorical variables at the same time. It is also called a cross-tabulation, crosstab, or two-way table. The categories of one variable run along the rows, while the categories of the other run along the columns, and each cell shows the count of cases that fall into that particular combination.
Suppose a library researcher surveys 200 students and records two things about each one: their gender, and whether they use the institution’s digital library. Gender has two categories (male, female) and usage has two categories (yes, no). The result is a 2×2 table with four cells, where each cell holds the number of students matching that pairing. A study at Nepal Open University did exactly this and found a significant link between gender and digital resource access, but no strong association with education level or region.
The table also carries marginal totals: the sum of each row, the sum of each column, and the grand total of the whole sample. These margins are not decoration. As you will see, they are the raw ingredients for working out what the data should look like if the two variables had no relationship at all.
Why not just use correlation?
Correlation measures how two continuous, numeric variables move together. Categorical data has no such continuum; “male” and “female” cannot be ranked on a scale, and neither can “uses library” versus “does not.” Because the categories do not form an ordered numeric line, a correlation coefficient cannot capture the pattern in this kind of data. This is precisely the gap the chi-square test fills. It is a nonparametric test, meaning it does not assume the data follows a normal distribution, which makes it usable in a wide range of research situations.
The chi-square test explained
The chi-square test of independence checks whether two categorical variables are associated or whether they vary independently of each other. The null hypothesis states that the two variables are independent, and the alternative hypothesis states that they are related. The test works by comparing what you actually observed against what you would expect to see if the variables truly had nothing to do with each other.
This gives us two sets of numbers for every cell. The observed frequency (O) is the actual count you recorded in your survey. The expected frequency (E) is the count you would predict under the assumption of independence. When the two variables are unrelated, the observed and expected values stay close together. When they are related, the gaps between them widen.
Calculating expected frequencies
Expected frequencies are built directly from the marginal totals of the contingency table. For any single cell, the formula is straightforward:
Expected frequency = (Row total × Column total) ÷ Grand total
Imagine our 200 students break down so that 80 use the digital library overall and 120 are female. The expected count for the “female and uses library” cell would be (120 × 80) ÷ 200 = 48. You repeat this for every cell. These expected counts are computed separately for each level of one variable at each level of the other, always pulling from the row and column totals rather than the individual observed counts. This is the step that encodes the idea of independence into actual numbers.
The chi-square formula
Once you have both the observed and expected frequencies, the test statistic is calculated with Karl Pearson’s chi-square formula:
χ² = Σ (O − E)² ÷ E
You take the difference between observed and expected for each cell, square it so negatives do not cancel positives, divide by the expected value to scale it, and then add up the results across all cells. This sum measures how far the observed frequencies deviate from what independence would predict. A small total means the data closely matches the independence assumption. A large total means the observed pattern is pulling away from it, hinting at a real relationship.
Assumptions you cannot ignore
The chi-square test is forgiving, but it is not assumption-free. The data must come from random sampling, the variables must be genuinely categorical, and each observation must fall into exactly one cell. There is also a sample-size condition. The chi-square distribution is only a good approximation when the data is in the form of actual counts, not percentages, and each expected frequency is reasonably large, generally at least 5. If too many cells have tiny expected counts, the test becomes unreliable, and for very small samples in a 2×2 table, researchers often switch to Fisher’s exact test instead.
Interpreting the results
A chi-square value on its own tells you nothing. To make sense of it, you need two more pieces: the degrees of freedom and a significance level. These let you compare your calculated statistic against a benchmark and decide whether the relationship you see is statistically meaningful.
Finding the degrees of freedom
Degrees of freedom describe how many cell values are free to vary once the marginal totals are fixed. For a contingency table, the formula is:
df = (number of rows − 1) × (number of columns − 1)
For our 2×2 library table, that is (2 − 1) × (2 − 1) = 1. A larger table, say 4 rows by 2 columns, would give (4 − 1) × (2 − 1) = 3 degrees of freedom. The bigger the table, the more degrees of freedom, and the higher the chi-square value needs to be before it counts as significant.
Comparing against the critical value
With the degrees of freedom and a chosen significance level (commonly α = 0.05), you look up the critical value in a chi-square distribution table. If your calculated chi-square value is greater than the critical value, you reject the null hypothesis and conclude the variables are related. If it is smaller, you do not have enough evidence to claim an association.
A worked example makes this concrete. In one analysis of movie type versus snack purchases, the calculated statistic was 65.03 with 3 degrees of freedom. The critical value at α = 0.05 was 7.815, and because 65.03 was far larger, the researchers rejected independence and concluded the two variables were associated.
Reading the p-value
Most statistical software, such as SPSS, reports a p-value alongside the chi-square statistic, which is often more convenient than comparing critical values by hand. The p-value indicates how probable it is that the relationship observed in the data is merely the result of sampling error. If the p-value falls below your significance level (for example, below 0.05), the association is considered statistically significant.
What the test does and does not tell you
This is where many researchers stumble. A significant chi-square result tells you that an association exists, but it says nothing about how strong that association is or in which direction it runs. The test is frequently over-interpreted, with researchers reading more into the result than the analysis can support. To gauge the strength of a relationship, you need additional measures of association such as Cramér’s V or the phi coefficient. The chi-square test is also a tool for the sample in front of you; because it works on coarser categorical data than parametric tests, it reports whether groups differ but does not on its own let you generalise to the wider population.
For students in library and information science, this toolkit is everywhere in real research. Studies on print versus digital resource use, on knowledge-management education across LIS schools, and on user behaviour by demographic group all lean on contingency tables and chi-square tests to turn raw survey counts into defensible conclusions.
What do you think? If a chi-square test on your own survey data showed a significant association between two variables, what would your very next analytical step be to make sure you were not over-interpreting the result? And how might a low expected frequency in just one or two cells change the way you report your findings?
References
- https://libguides.library.kent.edu/spss/chisquare
- https://www.sciencepublishinggroup.com/article/10.11648/j.ijsdr.20251101.14
- https://www.simplypsychology.org/chi-square.html
- https://stats.libretexts.org/Courses/Kennesaw_State_University/Statistical_Applications_in_Psychological_Sciences_with_Multimedia/15:_Chi-square/15.02:_Chi-Square_Test_of_Independence
- https://arxiv.org/pdf/2008.03662
- https://arxiv.org/pdf/2411.01928
- https://arxiv.org/pdf/2505.06318
- https://www.vedantu.com/jee-main/maths-chi-square-formula
- https://www.graphpad.com/quickcalcs/contingency1/
- https://www.jmp.com/en/statistics-knowledge-portal/chi-square-test/chi-square-test-of-independence
- https://methods.sagepub.com/reference/encyclopedia-of-survey-research-methods/n64.xml
- https://www.researchgate.net/publication/391234856_Chi_Square_Test_Analysis_in_Use_of_Digital_Library_on_the_Basis_Gender_Education_Levels_and_Regional_Differences
- https://methods.sagepub.com/reference/encyc-of-research-design/n48.xml

Leave a Reply