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.
Last updated: August 2026

The common statistic

All chi-square count tests use the same statistic:

χ2=all cells(OiEi)2Ei\chi^2 = \sum_{\text{all cells}} \frac{(O_i - E_i)^2}{E_i}

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.

TestNull hypothesisDegrees of freedom
Goodness of fitThe data follow the specified distribution$k - 1 - m$ ($m$ = parameters estimated)
IndependenceThe two categorical variables are independent$(r-1)(c-1)$
HomogeneitySeveral 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$
1525020.08
23850-122.88
36150112.42
44950-10.02
Total20020005.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 testedParameters estimateddf
Uniform with specified proportions0$k - 1$
Poisson with $\lambda$ estimated from the data1$k - 2$
Normal with $\mu$ and $\sigma$ estimated from the data2$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:

DimensionalSurfaceAssemblyRow total
Supplier A30201060
Supplier B20402080
Supplier C10203060
Column total608060200

Expected count for each cell:

Eij=(row totali)(column totalj)grand totalE_{ij} = \frac{(\text{row total}_i)(\text{column total}_j)}{\text{grand total}}

$E_{11} = (60)(60)/200 = 18$, $E_{12} = (60)(80)/200 = 24$, $E_{13} = 18$, and so on.

DimensionalSurfaceAssembly
Supplier A182418
Supplier B243224
Supplier C182418

χ2=(3018)218+(2024)224+(1018)218+(2024)224+(4032)232+(2024)224+(1018)218+(2024)224+(3018)218\chi^2 = \frac{(30-18)^2}{18} + \frac{(20-24)^2}{24} + \frac{(10-18)^2}{18} + \frac{(20-24)^2}{24} + \frac{(40-32)^2}{32} + \frac{(20-24)^2}{24} + \frac{(10-18)^2}{18} + \frac{(20-24)^2}{24} + \frac{(30-18)^2}{18}

=8.00+0.67+3.56+0.67+2.00+0.67+3.56+0.67+8.00=27.78= 8.00 + 0.67 + 3.56 + 0.67 + 2.00 + 0.67 + 3.56 + 0.67 + 8.00 = 27.78

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

RequirementDetail
Independent observationsEach unit contributes to exactly one cell
Counts, not percentagesThe test must be run on raw frequencies; running it on percentages gives a meaningless statistic
Expected count at least 5Conventionally in at least 80% of cells, with no expected count below 1
Mutually exclusive, exhaustive categoriesEvery 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:

V=χ2nmin(r1,c1)V = \sqrt{\frac{\chi^2}{n \cdot \min(r-1,\, c-1)}}

For the example, $V = \sqrt{27.78 / (200 \times 2)} = \sqrt{0.0695} = 0.264$, a moderate association.

Test Your Knowledge

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?

A
B
C
D
Test Your Knowledge

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
B
C
D
Test Your Knowledge

A chi-square test of independence is run on a table of percentages rather than raw counts. What is the consequence?

A
B
C
D