Example 2: Wilcoxon Rank Sum Test

The following example uses the same data as in example 1. Now, all the statistics are displayed.

import java.text.*;
import com.imsl.*;
import com.imsl.stat.*;
import com.imsl.math.PrintMatrix;

public class WilcoxonRankSumEx2 {
    public static void main(String args[]) {
        double[] x = {7.3, 6.9, 7.2, 7.8, 7.2};
        double[] y = {7.4, 6.8, 6.9, 6.7, 7.1};
        String[] labels = {
            "Wilcoxon W statistic ......................",
            "2*E(W) - W ................................",
            "p-value ................................... ",
            "Adjusted Wilcoxon statistic ...............",
            "Adjusted 2*E(W) - W .......................",
            "Adjusted p-value .......................... ",
            "W statistics for averaged ranks............",
            "Standard error of W (averaged ranks) ...... ",
            "Standard normal score of W (averaged ranks) ",
            "Two-sided p-value of W (averaged ranks) ... "
        };
        
        WilcoxonRankSum wilcoxon = new WilcoxonRankSum(x, y);
        NumberFormat nf = NumberFormat.getInstance();
        nf.setMinimumFractionDigits(3);
        
        // Trun off printing of warning messages.
        Warning.setOut(null);
        wilcoxon.compute();
        double[] stat = wilcoxon.getStatistics();
        
        for (int i = 0; i < 10; i++) {
            System.out.println(labels[i] + " " + nf.format(stat[i]));
        }
    }
}

Output

Wilcoxon W statistic ...................... 34.000
2*E(W) - W ................................ 21.000
p-value ...................................  0.110
Adjusted Wilcoxon statistic ............... 35.000
Adjusted 2*E(W) - W ....................... 20.000
Adjusted p-value ..........................  0.075
W statistics for averaged ranks............ 34.500
Standard error of W (averaged ranks) ......  4.758
Standard normal score of W (averaged ranks)  1.471
Two-sided p-value of W (averaged ranks) ...  0.141
Link to Java source.