Package jline.api.sim

Class Sim_shapirowilk

java.lang.Object
jline.api.sim.Sim_shapirowilk

public final class Sim_shapirowilk extends Object
Shapiro-Wilk test for univariate normality, Royston's AS R94 algorithm.

The statistic is

   W = (sum_i a_i x_(i))^2 / sum_i (x_i - xbar)^2,
 

with x_(i) the order statistics and a the antisymmetric weight vector obtained by correcting the normalized expected normal order statistics m_i = Phi^{-1}((i-3/8)/(n+1/4)) in their two extreme components. Small W means departure from normality, so the test is one-sided in W and the p-value is an upper normal tail after Royston's normalizing transform, which has three branches: n = 3 exact, 4 <= n <= 11, and n >= 12. Valid for 3 <= n <= 5000.

Port of MATLAB sim_shapirowilk.m. W and the p-value agree with scipy.stats.shapiro to 5e-10 and 1.5e-7 respectively over n up to 2000.

Reference: J. P. Royston, "Approximating the Shapiro-Wilk W-test for Non-normality", Statistics and Computing 2, 1992; J. P. Royston, "Remark AS R94", Applied Statistics 44(4), 1995.

Since:
LINE 3.1.0
  • Method Details

    • sim_shapirowilk

      public static HypothesisTestResult sim_shapirowilk(double[] x)
      Tests a sample for normality at the 5% level.
      Parameters:
      x - the sample, 3 to 5000 finite and not all equal values
      Returns:
      the test outcome
    • sim_shapirowilk

      public static HypothesisTestResult sim_shapirowilk(double[] x, double alpha)
      Tests a sample for normality.
      Parameters:
      x - the sample, 3 to 5000 finite and not all equal values
      alpha - significance level in (0,1)
      Returns:
      the test outcome
    • weights

      public static double[] weights(int n)
      Royston AS R94 antisymmetric weight vector, a[n-1-i] = -a[i].
      Parameters:
      n - sample size, at least 3
      Returns:
      the weight vector, ascending with the order statistics