Equivalence of formulations for Friedman Test? 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?
 A: [Note that the R help gives Hollander and Wolfe [1] as a reference so that would be one place to look for more details.]
Each set of block-ranks contains the numbers $1$ to $k$, so the average rank, $\bar{r}$ in each block will be $(k+1)/2$  (ties within a block won't change that average either, but I will work on a "no ties" basis, since it will affect later calculations). Consequently, the average rank across all blocks will also be $(k+1)/2$.
Similarly, $SS_e$, is purely a function of $n$ and $k$. For a particular block, $i$,
$$\sum_{j=1}^k\left(r_{i,j}-\bar{r}\right)^2=k(k-1)(k+1)/12$$
Hence the double sum in $SS_e$ is $nk(k-1)(k+1)/12$ and so $SS_e$ itself is $k(k+1)/12$
What remains then is to show that $\frac{1}{n}\sum_{j=1}^k\left(R_j - \frac{n(k+1)}2\right)^2=n \sum_{j = 1}^n \left(\bar{r}_j -\frac{(k+1)}{2}\right)^2$.
Taking the RHS
\begin{eqnarray}
n\sum_{j = 1}^n \left(\bar{r}_j -\frac{(k+1)}{2}\right)^2&=&n\sum_{j = 1}^n \left(\frac{1}{n}R_j -\frac{1}{n}\frac{n(k+1)}{2}\right)^2\\
&=&n(\frac{1}{n})^2\sum_{j = 1}^n \left(R_j -\frac{n(k+1)}{2}\right)^2\\
&=&\frac{1}{n}\sum_{j = 1}^n \left(R_j -\frac{n(k+1)}{2}\right)^2\end{eqnarray}
So when there are no ties the two formulas are algebraically identical.
[1] Myles Hollander and Douglas A. Wolfe (1973),
Nonparametric Statistical Methods.
New York: John Wiley & Sons.  Pages 139-146.
