28. Chi-squared test

Summary and chapters of the recording

Author
Affiliation

Johnny van Doorn

University of Amsterdam

11 November 2026 · Recording · Slides · Handout

The chi-squared test is about the association between two categorical variables, so we work with counts. With this year’s class data (preferred way of watching the lecture, and personality) we predict the count in every cell under the null hypothesis of independence, compare those predictions with the observed counts, and add everything up into the χ² statistic and its p-value. We check the expected counts (with Fisher’s exact test as the alternative when they are small) and use the standardized residuals to see where the null model is most wrong. The effect size is the odds ratio, which we build up from conditional probabilities and odds. After the break we run the analysis in JASP, add a third variable as a layer, use the test to check whether predictors are independent, and redo the book’s dancing cats example.

Open the recording and skip to the chapter you need. The chapters come from the lecture transcript, so one may start a few seconds early or late.

Time Chapter
15:12 WelcomeThe chi-squared test is all about quantifying an association between two categorical variables, the last combination of types of variables. We can do hypothesis testing with a p-value, but we can also look at an effect size, which tells a different story.
19:29 χ² test statisticWe look at what the observed counts are on the one hand, and on the other hand what our null model predicts for these counts. The chi-squared statistic tells you the difference between what you see in the data and what you expect under the null hypothesis, and a big difference is bad news for the null hypothesis.
22:02 χ² distributionLike the t- and F-distributions, the chi-squared distribution is shaped by its degrees of freedom, the number of rows minus 1 times the number of columns minus 1. With two categories in each variable, we get a chi-squared distribution with a single degree of freedom.
23:44 AssumptionsWe want independent observations, where every person only influences their own observation, and the expected counts should not be too small. There is no normality assumption to worry about, because we are only working with categorical variables.
24:32 ExperimentLet's collect some data, with three questions that each have categorical outcomes. Can I predict whether you watch the lectures digitally or live from your self-assessed introversion versus extroversion, and from whether you are a cat, dog, or other animal lover?
27:09 The dataWith two categorical variables you can display the full data in such a table, without summarizing the data in any way. Is there an association between the two, a difference between the proportion of introverted people and of extroverted people who watch the lectures live?
28:48 Predictions under H₀If personality and lecture style are independent, the probability of somebody being extrovert and watching digitally is the probability of watching digitally times the probability of being extrovert. So we take the row total, multiply it by the column total and divide by n, which gives the expected count for that cell (10.06 extrovert digital viewers).
34:38 Error = observed − modelWe take the differences between the observed counts and the counts the null model expects, and a fancy term for these is the residuals. In a two-by-two design they are always flipped, because what we over-predict for one cell we under-predict for the other.
37:03 Calculating χ²Putting all those numbers into one formula gives a single value, our chi-squared test statistic of 2.38. Is this high or not? We don't really know until we test its significance.
37:53 Testing for significanceWith a single degree of freedom, the probability of observing this chi-squared statistic, or more extreme, is around 12%, which is not significant for our alpha of 0.005. We fail to reject the null hypothesis, so we cannot conclude that there is an association between personality and preferred lecture viewing style.
39:36 Checking expected countsThe regular chi-squared test assumes that the expected cell counts are sufficiently high. In a two-by-two design none should be below 5, and with more groups no more than 20% of the cells should have an expected count below 5.
40:27 Fisher's exact testJust as we could choose the Welch t-test, here you can choose a more robust version, Fisher's exact test, which does not make the assumption about the expected cell counts. Our lowest expected count is 10.06, so we are fine using the regular chi-squared test.
41:17 Standardized residualsThe residuals tell you for which cell in the design the null model is the most wrong, and the standardized residuals make it possible to compare them between cells. A positive or negative sign does not matter, and here the null model was the most wrong for the extrovert digital viewers.
48:10 Effect sizeThe effect size for categorical associations is a really cool one, but it does take a moment to wrap your head around. A first step is to remember the probability rules that hold when two events are independent.
49:54 Independence and conditional probabilitiesIf A and B are independent, the probability of A given B is simply the probability of A. If personality and viewing style are independent, the probability of preferring the digital lecture if you are an extrovert is the same as the probability of preferring the digital lecture.
52:26 Odds visualizedThe bar chart shows the observed proportions, and the dashed line is the probability of somebody being an extrovert in the sample, 0.44. If the two variables are independent, that probability should be 0.44 among the digital viewers and among the live viewers.
54:58 OddsThe odds express the counts within one group as a ratio, for instance 1.3 times as many extroverts as introverts among the digital viewers, and 0.58 times as many among the live viewers. If there is an association, we would expect those two odds to be different.
57:32 Odds ratioThe ratio of those odds is called the odds ratio, and it is the effect size of the chi-squared test. If there is no association the odds ratio is 1, and we observed an odds ratio of 2.25.
1:02:41 Odds, the other way aroundWe can also look at the odds of digital versus live within the extroverts (0.87) and within the introverts (0.38). The ratio of those odds is still exactly that same odds ratio of 2.25.
1:05:14 Break
1:16:28 Recap of the first partWe saw two main ways to analyze an association between categorical variables, the chi-squared test with its p-value for hypothesis testing, and the odds ratio as the effect size. JASP by default gives the log of the odds ratio, and because the log of 1 equals 0, the null value of the log odds ratio is 0.
1:19:05 Contingency tables in JASPIn the Frequencies module, Contingency Tables gives the observed counts and the chi-squared test with its p-value. In the Statistics tab you add the odds ratio (only for two-by-two designs) and Fisher's exact test, and in the Cells tab the expected counts and the Pearson (standardized) residuals.
1:26:42 A third variable as a layerAdding a third variable as a layer gives separate contingency tables, and chi-squared tests, for each group of that variable. A significant association for only the dog people would indicate an interaction, but this is more of an exploratory tool than a real test for an interaction effect.
1:31:50 Independent predictorsThe chi-squared test is the way to assess independent predictors in factorial ANOVA designs, because those predictors are categorical. The balanced design from lecture 17 gives a chi-squared statistic of exactly 0, with a p-value of 1.
1:36:09 Book example (dancing cats)The book example is about training cats to dance by offering them food or affection, and it has a fairly strong effect. The chi-squared value of 25.36 has a very low p-value, so we reject the null hypothesis, and in the food group 2.8 times as many cats danced as did not dance.
1:42:14 RecapIt's all about quantifying associations between categorical variables, with a hypothesis test (the chi-squared statistic and its p-value) and an effect size (the odds ratio). Effect sizes allow you to interpret your results in a more theoretically interesting way, rather than just saying reject or fail to reject the null.