# Compute Exact Null Distribution for Friedman Statistic

Problem Statement: If there are no ties and $$b=2,\;k=3,$$ derive the exact null distribution of $$F_r,$$ the Friedman statistic.

Note: This is Exercise 15.35 in Mathematical Statistics with Applications, 5th Ed., by Wackerly, Mendenhall, and Scheaffer.

My Work So Far: There are two equivalent formulae for the Friedman statistic, and I will use this one: $$F_r=\frac{12}{bk(k+1)}\,\sum_{i=1}^kR_i^2-3b(k+1).$$ For our situation, this simplifies down to $$F_r=\frac{1}{2}\sum_{i=1}^3R_i^2-24.$$ I wrote the following (quick and dirty) function in R to compute this statistic:

compute_Friedman_Fr = function(y)
{
0.5*(sum(y[1:2])^2+sum(y[3:4])^2+sum(y[5:6])^2)-24
}


where I am considering the first two elements of the list $$y$$ as the first treatment, the second two elements as the second treatment, and so on. The Friedman statistic is invariant to two kinds of permutations: permuting the treatments, and permuting the ranks within treatments. An example of a function call would be:

> compute_Friedman_Fr(c(1,2,3,4,5,6))
 65.5


Hence, we can construct the following table: $$\begin{array}{cc} \textbf{Rank Array} &F_r \\ \hline (1,2,3,4,5,6) &65.5\\ (1,2,3,5,4,6) &62.5\\ (1,2,3,6,4,5) &61.5\\ (1,3,2,4,5,6) &62.5\\ (1,3,2,5,4,6) &58.5\\ (1,3,2,6,4,5) &56.5\\ (1,4,2,3,5,6) &61.5\\ (1,4,2,5,3,6) &53.5\\ (1,4,2,6,3,5) &52.5\\ (1,5,2,3,4,6) &56.5\\ (1,5,2,4,3,6) &52.5\\ (1,5,2,6,3,4) &50.5\\ (1,6,2,3,4,5) &53.5\\ (1,6,2,4,3,5) &50.5\\ (1,6,2,5,3,4) &49.5 \end{array}$$

My Question: This bears absolutely no resemblance to the book's answer of \begin{align*} P(F_r=4)&=P(F_r=0)=1/6\\ P(F_r=3)&=P(F_r=1)=1/3 \end{align*} I feel like there is a category error somewhere. How could $$F_r,$$ with the formula above, possibly ever equal $$0,1,3,$$ or $$4?$$ Am I wrong? If so, why? Is the book wrong? If so, why?

So, if I understand @whuber's comment correctly, I am computing the statistic incorrectly. I should be doing this, instead (as one example): $$\begin{array}{c|ccc} B/T &1 &2 &3 \\ \hline A &1 &2 &3 \\ B &1 &2 &3 \\ \hline \text{Total} \;(R_i) &2 &4 &6 \end{array},$$ so that $$F_r=\frac12(4+16+36)-24=4.$$
Another example: $$\begin{array}{c|ccc} B/T &1 &2 &3 \\ \hline A &1 &3 &2 \\ B &1 &2 &3 \\ \hline \text{Total} \;(R_i) &2 &5 &5 \end{array},$$ so that $$F_r=\frac12(4+25+25)-24=3.$$