# Friedman test

The Friedman test is a non-parametric statistical test developed by Milton Friedman.[1][2][3] Similar to the parametric repeated measures ANOVA, it is used to detect differences in treatments across multiple test attempts. The procedure involves ranking each row (or block) together, then considering the values of ranks by columns. Applicable to complete block designs, it is thus a special case of the Durbin test.

Classic examples of use are:

• n wine judges each rate k different wines. Are any of the k wines ranked consistently higher or lower than the others?
• n welders each use k welding torches, and the ensuing welds were rated on quality. Do any of the k torches produce consistently better or worse welds?

The Friedman test is used for one-way repeated measures analysis of variance by ranks. In its use of ranks it is similar to the Kruskal–Wallis one-way analysis of variance by ranks.

Friedman test is widely supported by many statistical software packages.

## Method

1. Given data ${\displaystyle \{x_{ij}\}_{n\times k}}$, that is, a matrix with ${\displaystyle n}$ rows (the blocks), ${\displaystyle k}$ columns (the treatments) and a single observation at the intersection of each block and treatment, calculate the ranks within each block. If there are tied values, assign to each tied value the average of the ranks that would have been assigned without ties. Replace the data with a new matrix ${\displaystyle \{r_{ij}\}_{n\times k}}$ where the entry ${\displaystyle r_{ij}}$ is the rank of ${\displaystyle x_{ij}}$ within block ${\displaystyle i}$.
2. Find the values:
• ${\displaystyle {\bar {r}}_{\cdot j}={\frac {1}{n}}\sum _{i=1}^{n}{r_{ij}}}$
• ${\displaystyle {\bar {r}}={\frac {1}{nk}}\sum _{i=1}^{n}\sum _{j=1}^{k}r_{ij}}$
• ${\displaystyle SS_{t}=n\sum _{j=1}^{k}({\bar {r}}_{\cdot j}-{\bar {r}})^{2}}$,
• ${\displaystyle SS_{e}={\frac {1}{n(k-1)}}\sum _{i=1}^{n}\sum _{j=1}^{k}(r_{ij}-{\bar {r}})^{2}}$
3. The test statistic is given by ${\displaystyle Q={\frac {SS_{t}}{SS_{e}}}}$. Note that the value of Q as computed above does not need to be adjusted for tied values in the data.
4. Finally, when n or k is large (i.e. n > 15 or k > 4), the probability distribution of Q can be approximated by that of a chi-squared distribution. In this case the p-value is given by ${\displaystyle \mathbf {P} (\chi _{k-1}^{2}\geq Q)}$. If n or k is small, the approximation to chi-square becomes poor and the p-value should be obtained from tables of Q specially prepared for the Friedman test. If the p-value is significant, appropriate post-hoc multiple comparisons tests would be performed.