The following example uses the same data as in example 1. Here, all the statistics are displayed.
import java.text.*;
import com.imsl.*;
import com.imsl.stat.*;
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) . ",
"Approximate Two-sided p-value of W .......... "
};
WilcoxonRankSum wilcoxon = new WilcoxonRankSum(x, y);
NumberFormat nf = NumberFormat.getInstance();
nf.setMinimumFractionDigits(3);
// Turn off printing of warning messages.
Warning.setOut(null);
double[] exact = wilcoxon.computeExactPValues();
double[] stat = wilcoxon.getStatistics();
for (int i = 0; i < 7; i++) {
System.out.println(labels[i] + " " + nf.format(stat[i]));
}
System.out.println("Mann-Whitney statistic ............"
+ ".......... " + nf.format(wilcoxon.getMannWhitney()));
for (int i = 7; i < 10; i++) {
System.out.println(labels[i] + " " + nf.format(stat[i]));
}
System.out.println("Exact Left-Tailed p-value ............"
+ "....... " + nf.format(exact[0]));
System.out.println("Exact Right-Tailed p-value ..........."
+ "....... " + nf.format(exact[1]));
System.out.println("Exact Two-sided p-value .............."
+ "....... " + nf.format(exact[2]));
}
}
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 Mann-Whitney statistic ...................... 19.500 Standard error of W (averaged ranks) ........ 4.758 Standard normal score of W (averaged ranks) . 1.471 Approximate Two-sided p-value of W .......... 0.141 Exact Left-Tailed p-value ................... 0.937 Exact Right-Tailed p-value .................. 0.079 Exact Two-sided p-value ..................... 0.159Link to Java source.