Friedman Repeated-Measures Rank Test
Rank matched treatments and compare the result with its exact tiny null distribution.
By Riano · Published · Updated · Report a correction
Friedman Repeated-Measures Rank Test
The Friedman Repeated-Measures Rank Test is a non-parametric alternative to the one-way ANOVA with repeated measures. It is used to test for differences between treatments when samples are dependent or matched, such as multiple treatments administered to the same block (or subject). The exact conditional label-randomization p-value assumes treatment-label exchangeability within independent blocks, evaluating all possible within-block permutations.
Worked Example
Let's evaluate the "Mixed" dataset scenario with 4 blocks and 3 treatments. The values are:
| Block | T1 | T2 | T3 |
|---|---|---|---|
| 1 | 1 | 2 | 3 |
| 2 | 3 | 1 | 2 |
| 3 | 2 | 3 | 1 |
| 4 | 1 | 3 | 2 |
First, we rank the treatments within each block in ascending order (using average ranks for ties if they existed). The ranks are:
| Block | Rank 1 | Rank 2 | Rank 3 |
|---|---|---|---|
| 1 | 1 | 2 | 3 |
| 2 | 3 | 1 | 2 |
| 3 | 2 | 3 | 1 |
| 4 | 1 | 3 | 2 |
The column rank sums (Rj) for each treatment are: R1 = 7, R2 = 9, R3 = 8.
The raw statistic Q is calculated using the formula: Q = 12 / (n * k * (k + 1)) * sum(Rj^2) - 3 * n * (k + 1). For n=4 blocks and k=3 treatments: Q = 12 / (4 * 3 * 4) * (7^2 + 9^2 + 8^2) - 3 * 4 * 4 = 12 / 48 * (49 + 81 + 64) - 48 = 0.25 * 194 - 48 = 48.5 - 48 = 0.5.
Since there are no ties in this configuration, the tie correction C = 1, giving a corrected statistic of 0.5. The exact permutation p-value is calculated by examining all (3!)^4 = 1296 independent within-block permutations, computing Q for each, and finding the proportion where Q_perm >= 0.5. For this dataset, the permutation p-value is 0.9305555555555556.
Experiment
In the interactive module, you can explore the Friedman test with various dataset configurations.
- Change the Dataset to explore different levels of variation, from
Consistentwhere treatments consistently rank similarly across blocks, toAll tiedwhere there is no variation at all. - Modify the Focused block to inspect the specific ranking within an individual block.
Limitations
While exact enumeration is feasible for tiny designs (such as n=4 blocks and k=3 treatments, yielding 1296 assignments), it scales poorly as n and k increase. A chi-square approximation for Q is often used for larger sample sizes, but for the tiny n=4 design evaluated here, no chi-square approximation is used.
Additionally, if all values within every block are tied (e.g., all 2s), there is no rank variation (C=0), meaning the raw Q is 0 but the corrected statistic and exact p-value are theoretically undefined and thus unavailable.
References
The statistical definition of the Friedman chi-square test with tie corrections as implemented here matches common scientific computing environments.
SciPy Community. scipy.stats.friedmanchisquare. SciPy Documentation.
Experience it interactively
Adjust parameters, observe in real time, and build deep intuition with Riano’s interactive Friedman Repeated-Measures Rank Test module.
Try Friedman Repeated-Measures Rank Test on Riano →