/* copyright 2007 by Robert Dodier
 * I release this file under the terms of the GNU General Public License.
 */

wilcoxon (X, C) := block ([X1, X0, X10, R, n1, n0, Rsum, W],

    X1 : X [C = 1, 1],
    X0 : X [C = 0, 1],
    n1 : nrows (X1),
    n0 : nrows (X0),
    if n1 = 0 or n0 = 0
        then 1/2
        else
           (X10 : append (elements (X1), elements (X0)),
            R : ranks (X10),
            Rsum : sum (R[i], i, 1, n1),
            W : (Rsum - n1 * (n1 + 1) / 2) / (n1 * n0)));

