Wilcoxon signed-rank test (source code)

= Wilcoxon signed-rank test
{c}
{title2=$W_+=\sum_{D_i>0}\operatorname{rank}(|D_i|)$}
{wiki}

For independent paired observations, form differences $D_i=U_i-V_i$. Assume the differences are identically distributed, continuous and symmetric about a location $\delta$. Under the zero-location <null hypothesis>, the signs are independent fair signs conditional on their absolute values. Rank the absolute differences and add ranks with positive signs. A negative-location alternative rejects for small $W_+$. Its exact conditional distribution is that of a sum of an independently selected subset of ranks, each of the $2^n$ subsets equally likely. Thus its mean is $n(n+1)/4$ and its variance is $n(n+1)(2n+1)/24$. Symmetry is essential: a zero <median> alone does not justify this signed-rank null law. Zero differences are omitted in the usual version, and tied absolute differences receive average ranks.