The Friedman test compares three or more conditions measured on the same units, or on matched blocks, using ranks. It is the rank-based counterpart of repeated-measures ANOVA and an extension of the Wilcoxon signed-rank test beyond two conditions. By ranking within each unit, it removes unit-to-unit differences, so each wafer, lot or operator acts as its own control.
The sequence:
The statistic. With $b$ blocks and $k$ conditions, rank the $k$ values within each block from $1$ to $k$, and let $R_j$ be the sum of the ranks of condition $j$ across all blocks. If the conditions do not differ, every condition has the same expected rank sum, $b(k+1)/2$. The Friedman statistic measures how far the rank sums stray from it:
For reasonably many blocks, $Q$ is approximately chi-square with $k-1$ degrees of freedom under the null hypothesis. Ties within a block share average ranks, and software applies a correction.
Worked example. Six wafers are each measured under three chamber conditions, and the picture shows each wafer's ranks. In every wafer but one, condition 1 is lowest, condition 2 is in the middle and condition 3 is highest. Wafer 3 swaps the first two. The rank sums are $R_1=7$, $R_2=11$, $R_3=18$, against an expected $12$ each, and they add up to $36=bk(k+1)/2$. Then:
On $k-1=2$ degrees of freedom the $5\%$ critical value is $5.991$ and the chi-square approximation gives $p=0.0057$, matching scipy.
Exact p-value for small samples. With only six blocks the approximation is rough. Each block can be ranked in $3!=6$ ways, so there are $6^6=46{,}656$ equally likely rank tables under the null. Exactly $78$ of them give $Q\ge10.33$, so the exact p-value is $78/46656\approx0.0017$, smaller than the approximate $0.0057$. Use an exact or permutation version when $b$ is small.
Agreement and effect size. Kendall's coefficient of concordance rescales the statistic to the range from $0$ to $1$, where $1$ means every block ranks the conditions identically:
A value of $0.861$ says the wafers agree strongly on the ordering of the conditions, not just that one condition is higher on average.
After a significant result. Friedman reports that some condition differs. To locate it, compare pairs of conditions with the Wilcoxon signed-rank test, or Nemenyi's test, and adjust for the number of comparisons with Holm or Bonferroni. In this example condition 3 is highest in all six wafers.
Reading the result.
- Blocking matters: the test is valid only when the same unit or a matched block provides the value for every condition. Independent groups need Kruskal-Wallis.
- Complete blocks: every block needs a value for every condition. A missing value usually means dropping the block or using a model for incomplete data.
- What it detects: consistent differences in ordering within blocks. It ignores how large the differences are, so it can miss a shift that is real but inconsistent across blocks.
- Power: when the data are close to normal, repeated-measures ANOVA is more powerful. Friedman is the safer choice with outliers, ordinal ratings or small samples.
- Two conditions: with $k=2$ it reduces to the sign test, which is why the Wilcoxon signed-rank test, using sizes too, is preferred for pairs.
Read the Friedman test as a ranking tally in which each unit votes on the order of the conditions: the more uniformly the votes agree, the larger $Q$ becomes.