Menu

#35 Comment on shapiro_wilk_statistics

1.0
wont-fix
None
2017-02-23
2017-02-16
Anonymous
No

I have a comment on following peace of code in NormalityTest.java

    double range = X[n - 1] - X[0];
    if (range < 1e-19)
        throw new PrecisionException("Shapiro-Wilks error: Range too small!", range);
    double xx = X[0] / range, sx = xx, sa = -a[0], xi;

Array X must be pre-sorted, as explained in bug #29
If data is not sorted and if the last value of X is less than the first value of X, exception will be thrown.

Perhaps you could avoid sorting, if you simply find minimum and maximum value of X:

    double max = max( X ) ;
    double min = min( X ) ;

    double range = max - min ;
    if (range < 1e-19)
        throw new PrecisionException("Shapiro-Wilks error: Range too small!", range);
    double xx = min / range, sx = xx, sa = -a[0], xi;

Also, sorting is taking a lot longer than finding maximum and minimum value of X.

Discussion

  • Roby Joehanes

    Roby Joehanes - 2017-02-23

    No, the fix is not that easy. This line (for converting to approximate inverse normal transform) requires the entire dataset to be sorted:
    double val = a[i] = Normal.quantile((i + 0.625) / an25, 0, 1, true, false);

    If the data is not sorted, the value here is invalid.

     
  • Roby Joehanes

    Roby Joehanes - 2017-02-23
    • status: open --> wont-fix
     

Anonymous
Anonymous

Add attachments
Cancel