swilk
public static void swilk(boolean[] init,
double[] x,
int n,
int n1,
int n2,
double[] a,
double[] w,
double[] pw,
int[] ifault)
ALGORITHM AS R94 APPL. STATIST. (1995) VOL.44, NO.4
Calculates Shapiro-Wilk normality test and P-value for sample sizes 3 <= n <= 5000 . Handles censored or uncensored data.
Corrects AS 181, which was found to be inaccurate for n > 50.
NOTE: Semi-strange porting kludge alert. FORTRAN allows subroutine arguments to be modified by the called routine (passed by
reference, not value), and the original code for this routine makes use of that feature to return multiple results. To avoid
changing the code any more than necessary, I've used Java arrays to simulate this pass-by-reference feature. Specifically,
in the original code w, pw, and ifault are output results, not input parameters. Pass in double[1] arrays for w and pw, and
an int[1] array for ifault, and extract the computed values from the [0] element on return. The argument init is both input
and output; use a boolean[1] array and initialize [0] to false before the first call. The routine will update the value to
true to record that initialization has been performed, to speed up subsequent calls on the same data set. Note that although
the contents of a[] will be computed by the routine on the first call, the caller must still allocate the array space and
pass the unfilled array in to the subroutine. The routine will set the contents but not allocate the space.
As described above with the constants, the data arrays x[] and a[] are referenced with a base element of 1 (like FORTRAN)
instead of 0 (like Java) to avoid screwing up the algorithm. To pass in 100 data points, declare x[101] and fill elements
x[1] through x[100] with data. x[0] will be ignored.
You might want to eliminate the ifault parameter completely, and throw Java exceptions instead. I didn't want to change the
code that much.
- Parameters:
init - Input & output; pass in boolean[1], initialize to false before first call, routine will set to truex - Input; Data set to analyze; 100 points go in x[101] array from x[1] through x[100]n - Input; Number of data points in xn1 - Input; dunnon2 - Input; dunno eithera - Output when init[0] == false, Input when init[0] == true; holds computed test coefficientsw - Output; pass in double[1], will contain result in w[0] on returnpw - Output; pass in double[1], will contain result in pw[0] on returnifault - Output; pass in int[1], will contain error code (0 == good) in ifault[0] on return