Chip Foundry Services Request Assessment

Chi-Square Test

The chi-square test asks whether counts in categories differ from what a stated hypothesis predicts. In a table of counts, it tests whether two categorical variables are independent: for example, whether the share of passing, marginal and failing wafers depends on which tool processed them. It works by comparing the observed count in each cell with the count expected if there were no relationship.

From a table to a decision:

Table of observed counts
two categorical variables, counted per cell
Build the statisticsame steps for every table size
Expected count per cell
row total x column total / grand total
Cell contribution
(observed - expected)^2 / expected
Add all contributions
chi-square statistic
Compare with the chi-square curve
df = (rows - 1) x (columns - 1), upper tail only
Small p-value
association is unlikely to be luck; inspect the residuals
Large p-value
no evidence that the variables are related

The statistic. For a table with $r$ rows and $c$ columns, the expected count in cell $(i,j)$ under independence is the row total times the column total divided by the grand total $N$. The Pearson statistic sums the standardized squared gaps over every cell, and its null distribution is approximately chi-square:

$$E_{ij}=\frac{R_iC_j}{N},\qquad \chi^2=\sum_{i,j}\frac{(O_{ij}-E_{ij})^2}{E_{ij}},\qquad \nu=(r-1)(c-1)$$

Large values mean observed counts sit far from the expected ones, so only the upper tail of the chi-square distribution counts as evidence. A value near its degrees of freedom is what chance alone would produce, because the mean of a chi-square variable equals $\nu$.

Worked example. Two etch tools each process $100$ wafers, and every wafer is graded pass, marginal or fail. Tool A gives $60,\,25,\,15$ and tool B gives $40,\,35,\,25$. The column totals are $100,\,60,\,40$, so the expected counts are $50,\,30,\,20$ for each tool. The cell contributions are $(60-50)^2/50=2$, $(25-30)^2/30\approx0.833$ and $(15-20)^2/20=1.25$ for tool A, and the same three numbers for tool B. Adding them gives $\chi^2=49/6\approx8.167$ on $\nu=(2-1)(3-1)=2$ degrees of freedom. The $5\%$ critical value is $5.991$ and the p-value is $0.0169$, so the outcome mix depends on the tool. The result matches scipy's contingency-table test.

Where the chi-square comes from observed counts vs the counts expected if tool and outcome were unrelated (200 wafers) 0 20 40 60 60 2.00 Tool A 40 2.00 Tool B Pass expected 50 per tool (dashed) 25 0.83 Tool A 35 0.83 Tool B Marginal expected 30 per tool (dashed) 15 1.25 Tool A 25 1.25 Tool B Fail expected 20 per tool (dashed) number at the foot of each bar = that cell's share of chi-square: (observed - expected)^2 / expected total chi-square = 2 + 0.83 + 1.25 + 2 + 0.83 + 1.25 = 8.17 on 2 df, p = 0.0169

Finding where the difference is. A significant test only says the variables are related. To see how, compare observed and expected counts cell by cell, using the Pearson residual $(O-E)/\sqrt{E}$. Tool A has $+1.41$ in the pass cell and $-1.12$ in the fail cell, so it passes more and fails less than independence predicts. Tool B has the mirror image, since both tools processed the same number of wafers.

Strength of association. The p-value shrinks as the sample grows, so also report an effect size. Cramér's $V$ rescales the statistic to the range from $0$ to $1$:

$$V=\sqrt{\frac{\chi^2}{N\,(\min(r,c)-1)}}=\sqrt{\frac{8.167}{200\cdot1}}\approx0.202$$

That is a modest association: the tool matters, but most wafer-to-wafer variation is not explained by it.

Checks before trusting the p-value.

  • Counts, not rates: use raw counts of independent observations. Percentages or repeated measurements on the same wafers break the test.
  • Expected counts: the chi-square approximation is reliable when nearly all expected counts are at least $5$; here the smallest is $20$. For small $2\times2$ tables, use Fisher's exact test instead.
  • Independence: each unit appears in exactly one cell. Before-and-after counts on the same units need McNemar's test.
  • Sample size: doubling every count doubles $\chi^2$ without changing the proportions, so a huge sample can make a trivial difference look significant. Read $V$ and the residuals together with the p-value.
  • Goodness of fit: the same statistic also tests one variable against a stated distribution; that case has its own degrees-of-freedom rule.

Read the chi-square test as a count of how far the table sits from a no-relationship table, measured in noise units: the bigger the total gap relative to its degrees of freedom, the harder it is to blame chance.