Friedman test

The Friedman test is a non-parametric statistical test developed by the U.S. economist Milton Friedman. The procedure involves ranking each row (or block) together, then considering the values of ranks by columns.

Method

 * 1) Given data $$\{x_{ij}\}_{m\times n}$$, that is, a tableau with $$m$$ rows (the blocks), $$n$$ columns (the treatments) and a single observation at the intersection of each block and treatment, calculate the ranks within each block. Replace the data with a new tableau $$\{r_{ij}\}_{m \times n}$$ where the entry $$r_{ij}$$ is the rank of $$x_{ij}$$ within block $$i$$.
 * 2) Find the values:
 * 3) *$$SS_t = n\sum_{j=1}^n (\bar{r}_{j} - \bar{r})^2$$,
 * 4) *$$SS_e = \frac{1}{m(n-1)} \sum_{i=1}^m \sum_{j=1}^n (r_{ij} - \bar{r})^2$$
 * 5) *$$\bar{r}_{j} = \frac{1}{m} \sum_{i=1}^m {r_{ij}}$$
 * 6) *$$\bar{r} = \frac{1}{mn}\sum_{i=1}^m \sum_{j=1}^n r_{ij}$$
 * 7) The test statistic is given by $$Q = \frac{SS_t}{SS_e}$$.
 * 8) Finally, the p-value is given by $$\mathbf{P}(\chi^2_{n-1} \ge Q)$$.