# 17.5.8.2 Algorithms (Friedman ANOVA)

The procedure below draws on NAG algorithms.

The scores in each column are ranked,$r_{ij}\,\!$ denoting the rank within block $j\,\!$ of the observation in treatment$j\,\!$$i\,\!$. Average ranks are assigned to tie scores.

1. The ranks are summed over each treatment to give rank sums $t_i=\sum_{j=1}^n r_{ij}$, for $i=1,2,...,k\,\!$
2. Friedman test statistic $FR\,\!$is calculated as $FR=\frac{12}{nk(k+1)}\sum_{i=1}^k\left\{t_i-\frac{1}{2}n(k+1)\right\}^2$

The significance level is compared to the $x^2\,\!$ distribution with $k-1\,\!$ degrees of freedom, where k is the total number of samples

For more details of the algorithm, please refer to nag_friedman_test (g08aec)