Example: Shapiro-Wilk W Test

The following example is taken from Conover (1980, pp. 195, 364). The data consists of 50 two-digit numbers taken from a telephone book. The W test fails to reject the null hypothesis of normality at the .05 level of significance.

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

public class NormalityTestEx1 {
    public static void main(String args[]) throws Exception {
        double x[] = {23.0, 36.0, 54.0, 61.0, 73.0, 23.0, 37.0, 54.0, 61.0,
        73.0, 24.0, 40.0, 56.0, 62.0, 74.0, 27.0, 42.0, 57.0, 63.0, 75.0, 29.0,
        43.0, 57.0, 64.0, 77.0, 31.0, 43.0, 58.0, 65.0, 81.0, 32.0, 44.0, 58.0,
        66.0, 87.0, 33.0, 45.0, 58.0, 68.0, 89.0, 33.0, 48.0, 58.0, 68.0, 93.0,
        35.0, 48.0, 59.0, 70.0, 97.0};
        
        NormalityTest nt = new NormalityTest(x);
        NumberFormat nf = NumberFormat.getInstance();
        nf.setMaximumFractionDigits(4);
        
        System.out.println("p-value = " + nf.format(nt.ShapiroWilkWTest()));
        System.out.println("Shapiro Wilk W Statistic = " +
        nf.format(nt.getShapiroWilkW()));
    }
}

Output

p-value = 0.2309
Shapiro Wilk W Statistic = 0.9642
Link to Java source.