The tests so far compare means. A great many questions are about counts: how many households fall in each category, and whether that pattern is what a theory predicts or what independence would produce. One statistic handles both. This lesson shows where it comes from, why the degrees of freedom are what they are, and why a significant chi-square can still mean a weak association.
Ashanagar is an invented district. The statistics lessons use it for every worked example, so you meet the same households again as the ideas build: first as a list of numbers, then as a spread, then as a population to sample from.
It has 60 households, each with a monthly income in rupees. Unless a page says otherwise, those 60 are the whole population, and a “sample” means a few of them drawn at random. Where a page needs two variables, it uses a smaller set of 12 households with the head’s years of schooling beside income.
The figures are illustrative, made up once and fixed. They are not official statistics.
Suppose you count how many items fall into each of k categories. A theory, or the assumption of independence, tells you how many should fall in each: the expected counts E. The chi-square statistic measures the total disagreement between what you observed, O, and what you expected, in a way that treats every cell fairly.
Three features are worth noticing at once. It is never negative. It is zero only when every observed count equals its expectation. And each cell’s gap is divided by E, because being 5 off in a cell that expected 20 is a serious miss and being 5 off in a cell that expected 2,000 is nothing. Two uses cover almost every exam question: goodness of fit (one variable against a stated distribution) and independence (two variables in a table).
The null hypothesis names the probability of each category, so the expected count is E = n × p for each. The statistic is compared with a chi-square distribution on k − 1 degrees of freedom, where k is the number of categories (CUET 2019 asks which parameter fixes the shape of the chi-square distribution: it is the degrees of freedom).
The die is fair, yet the counts are not all 20: that scatter is exactly what chance produces. The statistic 4.7 falls well inside the bulk of what a fair die gives. The gold bars, built by actually rolling fair dice, trace the chi-square curve.
The lab is the die of the opening question. With the die fair, press Roll the die again many times and watch the black line wander about inside the gold bars: those 2,000 gold bars are fair-die statistics, and they follow the blue curve. A statistic beyond the red 5% line happens about one time in twenty even when nothing is wrong. Then load the die towards six and raise n: a bias that no one could see at 30 rolls is rejected at 600.
A coin is tossed n times and X heads appear. The two categories are heads and tails, with observed counts X and n − X and expected counts np and n(1 − p), where p is the chance of heads under H₀. A fair coin tossed 100 times has expected counts 50 and 50. Suppose 60 heads and 40 tails appear. The statistic is
Because the counts must add to n, the shortfall in one cell is exactly the excess in the other: O₂ − E₂ = −(O₁ − E₁). Both squared deviations are the same number d² = (X − np)². Then
X has mean np and variance np(1 − p), so (X − np) ÷ √(np(1 − p)) is approximately standard normal for large n. Our two-cell statistic is the square of it. Here z = (60 − 50) ÷ 5 = 2 and z² = 4. A squared standard normal is a chi-square with one degree of freedom (the chi-square derivation). Two categories, one degree of freedom: k − 1.
A check on the bookkeeping for k categories: the count in cell i has variance npi(1 − pi) = Ei(1 − pi), so each term (Oi − Ei)² ÷ Ei has expected value 1 − pi. Adding over the cells gives Σ(1 − pi) = k − 1, the mean of a chi-square with k − 1 degrees of freedom. A fair die has k = 6, so the statistic averages 5.
Each standardised deviation (Oi − Ei) ÷ √Ei is roughly normal. If the k of them were independent, the sum of their squares would be a chi-square with k degrees of freedom. They are not: the counts add to n, so the deviations add to zero, which ties the last one to the others. One linear constraint takes away one degree of freedom, leaving k − 1. Each parameter you estimate from the same data, such as a Poisson mean, fits the expected counts to the observed ones and takes away one more.
A theory does not always name the probabilities. “The number of power cuts per week is Poisson” leaves the mean open. In Ashanagar, 100 weeks give 19, 36, 24, 13, 6 and 2 weeks with 0, 1, 2, 3, 4 and 5 cuts. The mean is 1.57 cuts a week, and the Poisson probabilities for that mean give expected counts of 20.8, 32.66, 25.64, 13.42, 7.47 for 0, 1, 2, 3 and “4 or more”. The last two observed cells (4 and 5 cuts) were joined because their expected counts were below 5. The statistic is 0.653.
Now the degrees of freedom. There are 5 categories, so k − 1 = 4, but the mean was estimated from the same data, which takes one more: 5 − 1 − 1 = 3. The 5% critical value is 7.815, and 0.65 is far inside it, so a Poisson fits well. Forgetting the extra degree of freedom makes you compare with 9.49 instead of 7.81 and accept fits that should be questioned.
For two categorical variables arranged in a table of counts, the null hypothesis is that they are unrelated. If they are, each cell should hold the count E = (row total × column total) ÷ grand total. Compute the statistic cell by cell, and compare it with a chi-square on (r − 1)(c − 1) degrees of freedom, where r and c count the rows and the columns (Hyderabad 2015 asks it outright: the chi-square test is the one for association between attributes).
Households by head’s schooling and whether the household holds a bank account (invented). Type any counts.
| Has an account | No account | Total | |
|---|---|---|---|
| No schooling | expected 21contributes 3.86 | expected 29contributes 2.79 | 50 |
| Primary | expected 21contributes 0.05 | expected 29contributes 0.03 | 50 |
| Secondary or more | expected 21contributes 4.76 | expected 29contributes 3.45 | 50 |
| Total | 63 | 87 | 150 |
χ² = 14.94 exceeds 5.99, so at the 5% level we reject independence: schooling and account-holding are associated. The shaded cells, with the longest bars, are where the table departs most from what independence predicts. Account-holding rises with schooling, far more than chance would explain.
If the row variable and the column variable are unrelated, the chance that a household lands in cell (i, j) is the chance of row i times the chance of column j: P(i, j) = P(i) × P(j). This is the same product rule as independent events in the conditional probability lesson.
We do not know P(i) or P(j), but the table’s margins estimate them: P(i) ≈ Ri ÷ N and P(j) ≈ Cj ÷ N, where Ri is the row total, Cj the column total and N the grand total. The expected count is N times the cell probability:
In a table with row totals 50 and 50, column totals 50 and 50 and N = 100, every cell expects 50 × 50 ÷ 100 = 25. The observed table 30, 20, 20, 30 gives a statistic of 4 × 25 ÷ 25 = 4.
The table has rc cells, but the expected counts were built from the data, so the observed counts are tied to them. The N total is fixed, which removes one. The row margins are fixed, but they add to N already, so they remove another r − 1. The column margins remove c − 1. What is free:
Equivalently, we estimated r − 1 row chances and c − 1 column chances, and the previous derivation takes one degree of freedom off for each estimated parameter. For a 3 × 2 table that is 2 × 1 = 2, and for a 2 × 2 table it is 1.
For the table [[a, b], [c, d]] the statistic collapses to
With 30, 20, 20, 30: 100 × (900 − 400)² ÷ (50 × 50 × 50 × 50) = 4, the same 4. The quantity ad − bc is zero exactly when the rows are proportional, which is independence.
Two designs give the same arithmetic. In a test of independence one sample is classified two ways (households by schooling and by account-holding). In a test of homogeneity separate samples are drawn from each group (500 men and 500 women), and the question is whether the groups share one distribution. The expected counts, the statistic and the degrees of freedom are identical. For a 2 × 2 table the statistic is the square of the two-proportion z of Lesson 9, which is why the two tests always agree.
The statistic grows in proportion to the sample size. Hold the shares in a table fixed and multiply every count by ten, and the statistic multiplies by ten. So with enough households any association, however faint, becomes “significant”. To measure how strong an association is, rescale the statistic by the sample size. For a table with r rows and c columns,
| Has an account | No account | Total | |
|---|---|---|---|
| Schooled | 52 | 48 | 100 |
| Not schooled | 48 | 52 | 100 |
With 200 households the statistic 0.32 is below the cut-off, so independence is not rejected, although the association in the table is exactly the same, V = 0.04. Slide N upward: the chi-square statistic grows in proportion, and V does not move.
In the lab, schooled households hold an account at a rate of 52% against 48% for the unschooled, whatever N is. At N = 200 the statistic is 0.32, nowhere near 3.84, and the test finds nothing. At N = 5,000 the statistic is 8.00 and the p-value is below 0.005, yet V is 0.04 throughout, a very weak association. Report the effect size alongside the p-value.
One more caution on assumptions. The chi-square approximation needs every expected count to be at least about 5. In a 2 × 2 table with small counts, statisticians apply Yates’ continuity correction, or use Fisher’s exact test, which does not rely on the approximation. Entrance papers rarely go beyond naming the rule.
The same distribution tests a single variance. For a normal sample, (n − 1)s² ÷ σ² follows a chi-square with n − 1 degrees of freedom (the result behind the interval of Lesson 6). To test H₀: σ² = σ₀², plug in the claimed value. A machine is meant to produce items with variance 20, and 16 items give s² = 30. The statistic is 15 × 30 ÷ 20 = 22.5, on 15 degrees of freedom. The two-sided 5% acceptance band is 6.26 to 27.49, so a variance of 30 against 20 is not rejected here (p = 0.191).
Do not confuse this with the F test of Lesson 9. A chi-square tests one variance against a number. Two variances against each other make a ratio of chi-squares, which is an F.
Definitions and one-step calculations. Most CUET and Hyderabad questions sit here.
Joint tables, standard errors and statement questions, up to JNU and IIT JAM level.
This topic’s hardest questions, from the DSE entrance, are worked through in Lesson 13: Tests on means and proportions.
These are questions from the TestStop bank. A free account answers 10 a day, each with its worked solution; All-Access opens every set with no daily limit.