The routine may be called by the names g01ddf or nagf_stat_test_shapiro_wilk.
3Description
g01ddf calculates Shapiro and Wilk's statistic and its significance level for any sample size between and . It is an adaptation of the Applied Statistics Algorithm AS R94, see Royston (1995). The full description of the theory behind this algorithm is given in Royston (1992).
Given a set of observations sorted into either ascending or descending order (m01caf may be used to sort the data) this routine calculates the value of Shapiro and Wilk's statistic defined as:
where is the sample mean and , for , are a set of ‘weights’ whose values depend only on the sample size .
On exit, the values of , for , are only of interest should you wish to call the routine again to calculate and its significance level for a different sample of the same size.
It is recommended that the routine is used in conjunction with a Normal plot of the data. Routines g01dafandg01dbf
can be used to obtain the required Normal scores.
4References
Royston J P (1982) Algorithm AS 181: the test for normality Appl. Statist.31 176–180
Royston J P (1986) A remark on AS 181: the test for normality Appl. Statist.35 232–234
Royston J P (1992) Approximating the Shapiro–Wilk's test for non-normality Statistics & Computing2 117–119
Royston J P (1995) A remark on AS R94: A remark on Algorithm AS 181: the test for normality Appl. Statist.44(4) 547–551
5Arguments
1: – Real (Kind=nag_wp) arrayInput
On entry: the ordered sample values,
, for .
2: – IntegerInput
On entry: , the sample size.
Constraint:
.
3: – LogicalInput
On entry: must be set to .TRUE. if you wish g01ddf to calculate the elements of a.
calwts should be set to .FALSE. if you have saved the values in a from a previous call to g01ddf.
On entry: if calwts has been set to .FALSE. then before entry a must contain the weights as calculated in a previous call to g01ddf, otherwise a need not be set.
On exit: the weights required to calculate .
5: – Real (Kind=nag_wp)Output
On exit: the value of the statistic, .
6: – Real (Kind=nag_wp)Output
On exit: the significance level of .
7: – IntegerInput/Output
On entry: ifail must be set to , or to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of means that an error message is printed while a value of means that it is not.
If halting is not appropriate, the value or is recommended. If message printing is undesirable, then the value is recommended. Otherwise, the value is recommended. When the value or is used it is essential to test the value of ifail on exit.
On exit: unless the routine detects an error or a warning has been flagged (see Section 6).
6Error Indicators and Warnings
If on entry or , explanatory error messages are output on the current error message unit (as defined by x04aaf).
An unexpected error has been triggered by this routine. Please
contact NAG.
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.
7Accuracy
There may be a loss of significant figures for large .
8Parallelism and Performance
Background information to multithreading can be found in the Multithreading documentation.
g01ddf is not threaded in any implementation.
9Further Comments
The time taken by g01ddf depends roughly linearly on the value of .
For very small samples the power of the test may not be very high.
The contents of the array a should not be modified between calls to g01ddf for a given sample size, unless calwts is reset to .TRUE. before each call of g01ddf.
The Shapiro and Wilk's test is very sensitive to ties. If the data has been rounded the test can be improved by using Sheppard's correction to adjust the sum of squares about the mean. This produces an adjusted value of ,
where is the rounding width. can be compared with a standard Normal distribution, but a further approximation is given by Royston (1986).
If , a value for w and pw is returned, but its accuracy may not be acceptable. See Section 4 for more details.
10Example
This example tests the following two samples (each of size ) for Normality.
Sample
Number
Data
, , , , , , , , , , , , , , , , , , ,
, , , , , , , , , , , , , , , , , , ,
The elements of a are calculated only in the first call of g01ddf, and are re-used in the second call.