Menu

#28 NormalityTest,shapiro_wilk_pvalue works incorrectly?

1.0
closed
None
2022-12-29
2016-04-20
Anonymous
No

Hi,
I just started to use JDistlib to calculate normality.
It calculates W with NormalityTest.shapiro_wilk_statistic(x) as it is supposed to.
But when I try to calculate p-value using NormalityTest,shapiro_wilk_pvalue(w,x.length) the result is different than I expected.
E.g. for n=10 and W=0.842 p-value should be around 0.05 (according to S-W tables like http://www.real-statistics.com/wp-content/uploads/2012/12/image3742.png)
but
NormalityTest.shapiro_wilk_pvalue(0.842, 10) returns p=3.3858759941785735E-48
Interestingly for n=10:
w=0.90 p=9.366645710023918E-12
w=0.95 p=0.9999199643824663

Could you explain how it works (if it is not a bug)?
Thanks in advance - BTW I find your library very helpful and simple to use,

Discussion

  • Roby Joehanes

    Roby Joehanes - 2016-04-20

    Hi there. Thanks! Could you please give me an example dataset?

     
  • Roby Joehanes

    Roby Joehanes - 2016-04-21

    Perhaps to give you more information, I translated the algorithm from R directly. R used algorithm AS R94 (See Royston 1995):

    https://stat.ethz.ch/R-manual/R-devel/library/stats/html/shapiro.test.html

    I did a quick check on how it performs and the output matches exactly with R. If you suspect that there is a bug, then it could very well be R's bug. This is why I need the exact example dataset so that I can report back to R maintainers.

    The table you referenced might be taken from an older algorithm.

     
  • Roby Joehanes

    Roby Joehanes - 2016-04-21

    Forget about what I just said. It is indeed a bug. Fixed in version 0.4.4. Thank you so much!

     
  • Roby Joehanes

    Roby Joehanes - 2016-04-21
    • status: open --> closed
     
  • Roby Joehanes

    Roby Joehanes - 2016-04-21

    Test case JDistlib:

    double[] n2 = c(0.139, 0.157, 0.175, 0.256, 0.344, 0.413, 0.503, 0.577, 0.614, 0.655, 0.954, 1.392, 1.557, 1.648, 1.690, 1.994, 2.174, 2.206, 3.245, 3.510, 3.571, 4.354, 4.980, 6.084, 8.351);
    w = NormalityTest.shapiro_wilk_statistic(n2);
    p = NormalityTest.shapiro_wilk_pvalue(w, n2.length);
    System.out.println(w + " -- " + p);
    

    Test case R:

    n2 <- c(0.139, 0.157, 0.175, 0.256, 0.344, 0.413, 0.503, 0.577, 0.614, 0.655, 0.954,
     1.392, 1.557, 1.648, 1.690, 1.994, 2.174, 2.206, 3.245, 3.510, 3.571, 4.354,
     4.980, 6.084, 8.351)
      sw <- shapiro.test(n2);
      sw$statistic;
      sw$p.value;
    

    Correct w = 0.8346663
    Correct p-value = 0.0009134905

     
  • Anonymous

    Anonymous - 2016-05-06

    Thank you! Now it works perfectly :)

     

Anonymous
Anonymous

Add attachments
Cancel