I'm trying to implement a Friedman test, and came across two sites giving methods for its implementation, namely, Wikipedia (perma-linking for posterity) and the NIST. At first glance, the general setup of the methods listed appears the same -- computing the ranks of each block-by-block row and combining them with a sort of distance statistic.
Upon closer inspection, though, I am not seeing how to reconcile the two given methods.
Wikipedia
$X$ : data matrix ($n\times k$), $R$ : corresponding within-row rank matrix, then $\bar{r}_j$, vector of column means and $\bar{r}$, overall matrix mean given by:
$$\bar{r}_j = \frac1n \sum_{i = 1}^n r_{i,j}$$
$$\bar{r} = \frac1{nk} \sum_{i = 1}^n \sum_{j = 1}^k r_{i,j}$$
Then the test statistic $Q$ is given by $Q = \frac{SS_t}{SS_e}$, where:
$$SS_t = n \sum_{j = 1}^n \left(\bar{r}_j -\bar{r}\right)^2$$
$$SS_e = \frac1{n(k-1)}\sum_{i=1}^n\sum_{j=1}^k\left(r_{i,j}-\bar{r}\right)^2$$
NIST
$R$ is again the matrix of ranks. $R_j$ is the vector of column sums.
The test statistic is $T_1$ given by:
$$\frac{12}{nk(k+1)}\sum_{j=1}^k\left(R_j - \frac{n(k+1)}2\right)^2$$
(and an adjustment is given for the case of ties).
These formulas look wildly different, in particular in the fraction on the outside of the sum: $n^2(k-1)$ for the Wikipedia approach, but $\frac{12}{nk(k+1)}$ for the NIST approach. The latter appears closer (at a glance) to the formulas used in the original paper of Friedman, so I'm inclined to trust that, but there do appear to be some creeping typos on that page.
The NIST formula also looks similar to that used in the R
implementation (stats:::friedman.test.default
):
STATISTIC <- ((12 * sum((colSums(r) - n * (k + 1)/2)^2))/(n *
k * (k + 1) - (sum(unlist(lapply(TIES, function(u) {
u^3 - u
Is the Wikipedia page wrong? Or is there an equivalence I'm just missing?