7.10 Chi-Square Goodness-of-Fit and Tests of Independence
Key Takeaways
- The chi-square statistic is the sum over cells of observed minus expected, squared, divided by expected.
- Goodness-of-fit degrees of freedom are the number of categories minus one, minus one for each parameter estimated from the data.
- For a contingency table, expected cell count is the row total times the column total divided by the grand total, with degrees of freedom of (r-1)(c-1).
- The test requires expected counts of at least 5 in most cells; sparse tables must be collapsed or tested with Fisher's exact test.
- Chi-square is always a right-tailed test, and it detects association without indicating direction or causation.
The common statistic
All chi-square count tests use the same statistic:
where $O$ is the observed count and $E$ the expected count under the null hypothesis. Large values mean observed counts are far from expectation, so the test is always right-tailed regardless of the direction of any difference.
Three applications appear in the Body of Knowledge and on the exam.
| Test | Null hypothesis | Degrees of freedom |
|---|---|---|
| Goodness of fit | The data follow the specified distribution | $k - 1 - m$ ($m$ = parameters estimated) |
| Independence | The two categorical variables are independent | $(r-1)(c-1)$ |
| Homogeneity | Several populations share the same distribution | $(r-1)(c-1)$ |
Independence and homogeneity use identical arithmetic and differ only in how the data was sampled: one sample cross-classified two ways gives independence; several fixed-size samples from different populations gives homogeneity.
Goodness of fit
Tests whether observed frequencies match those expected from a hypothesized distribution.
Worked example. A team believes defects are equally likely across four shifts. Observed counts over a month: 52, 38, 61, 49, total 200. Under equal likelihood each expected count is $200/4 = 50$.
| Shift | $O$ | $E$ | $O - E$ | $(O-E)^2/E$ |
|---|---|---|---|---|
| 1 | 52 | 50 | 2 | 0.08 |
| 2 | 38 | 50 | -12 | 2.88 |
| 3 | 61 | 50 | 11 | 2.42 |
| 4 | 49 | 50 | -1 | 0.02 |
| Total | 200 | 200 | 0 | 5.40 |
Degrees of freedom: $k - 1 = 3$ (no parameters were estimated, because the equal-proportions hypothesis was specified in advance). $\chi^2_{0.05,3} = 7.815$. Since $5.40 < 7.815$, do not reject: the data are consistent with defects being uniformly distributed across shifts.
Note the practical reading. Shift 3 has 61 defects against 49 on shift 4, a difference that looks substantial, but with these counts it is within what random variation produces. Acting on the apparent shift-3 problem would be chasing noise.
Degrees of freedom when parameters are estimated
Each parameter estimated from the same data costs one degree of freedom:
| Distribution tested | Parameters estimated | df |
|---|---|---|
| Uniform with specified proportions | 0 | $k - 1$ |
| Poisson with $\lambda$ estimated from the data | 1 | $k - 2$ |
| Normal with $\mu$ and $\sigma$ estimated from the data | 2 | $k - 3$ |
Forgetting this correction inflates the degrees of freedom, understates the critical value, and makes rejection too easy.
Chi-square versus other normality tests
For testing normality specifically, the chi-square goodness-of-fit test is available but weak: it requires binning continuous data, and the result depends on the arbitrary bin choice. The Anderson-Darling, Shapiro-Wilk, and Kolmogorov-Smirnov tests work on the raw data and have substantially more power. Chi-square goodness of fit is the right tool for genuinely categorical data and for count distributions such as the Poisson.
Test of independence
Tests whether two categorical variables are associated.
Worked example. Defect type by supplier:
| Dimensional | Surface | Assembly | Row total | |
|---|---|---|---|---|
| Supplier A | 30 | 20 | 10 | 60 |
| Supplier B | 20 | 40 | 20 | 80 |
| Supplier C | 10 | 20 | 30 | 60 |
| Column total | 60 | 80 | 60 | 200 |
Expected count for each cell:
$E_{11} = (60)(60)/200 = 18$, $E_{12} = (60)(80)/200 = 24$, $E_{13} = 18$, and so on.
| Dimensional | Surface | Assembly | |
|---|---|---|---|
| Supplier A | 18 | 24 | 18 |
| Supplier B | 24 | 32 | 24 |
| Supplier C | 18 | 24 | 18 |
Degrees of freedom $= (3-1)(3-1) = 4$, and $\chi^2_{0.05,4} = 9.488$. Since $27.78 > 9.488$, reject independence: defect type is associated with supplier.
Reading the cell contributions is where the practical value lies. The largest contributions come from Supplier A / dimensional (8.00) and Supplier C / assembly (8.00), so those are the specific supplier-defect combinations driving the association and the ones to investigate.
Assumptions and limits
| Requirement | Detail |
|---|---|
| Independent observations | Each unit contributes to exactly one cell |
| Counts, not percentages | The test must be run on raw frequencies; running it on percentages gives a meaningless statistic |
| Expected count at least 5 | Conventionally in at least 80% of cells, with no expected count below 1 |
| Mutually exclusive, exhaustive categories | Every observation is classified exactly once |
When expected counts are too small, either collapse adjacent categories into meaningful groups or use Fisher's exact test, which computes the exact probability without a large-sample approximation and is the standard choice for 2x2 tables with small counts.
Interpretation cautions
- Association is not causation. A significant result says defect type and supplier are related; it does not say the supplier causes the defect. Both could depend on the material grade each supplier happens to be assigned.
- A significant result does not identify which cells matter. Inspect the individual $(O-E)^2/E$ contributions, or standardized residuals $(O-E)/\sqrt{E}$, to find them.
- Large samples make trivial associations significant. Chi-square grows in proportion to sample size, so pair the test with an effect size measure such as Cramer's V:
For the example, $V = \sqrt{27.78 / (200 \times 2)} = \sqrt{0.0695} = 0.264$, a moderate association.
A team tests whether defects are uniformly distributed across four shifts using observed counts of 52, 38, 61, and 49 out of 200. What are the degrees of freedom, and what is the chi-square statistic?
In a 3 by 3 contingency table with a grand total of 200, a row total of 60 and a column total of 80, what is the expected count for that cell?
A chi-square test of independence is run on a table of percentages rather than raw counts. What is the consequence?