NAG Library Routine Document
G01DDF calculates Shapiro and Wilk's statistic and its significance level for testing Normality.
||X(N), A(N), W, PW
G01DDF calculates Shapiro and Wilk's
statistic and its significance level for any sample size between
. 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:
is the sample mean and
, 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 G01DAF
can be used to obtain the required Normal scores.
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 & Computing 2 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
- 1: X(N) – REAL (KIND=nag_wp) arrayInput
On entry: the ordered sample values,
, for .
- 2: N – INTEGERInput
On entry: , the sample size.
- 3: CALWTS – LOGICALInput
: must be set to .TRUE. if you wish G01DDF to calculate the elements of A
should be set to .FALSE. if you have saved the values in A
from a previous call to G01DDF.
If in doubt, set CALWTS
equal to .TRUE..
- 4: A(N) – REAL (KIND=nag_wp) arrayInput/Output
: 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: W – REAL (KIND=nag_wp)Output
On exit: the value of the statistic, .
- 6: PW – REAL (KIND=nag_wp)Output
On exit: the significance level of .
- 7: IFAIL – INTEGERInput/Output
must be set to
. If you are unfamiliar with this parameter you should refer to Section 3.3
in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value
is recommended. If the output of error messages is undesirable, then the value
is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is
. When the value is used it is essential to test the value of IFAIL on exit.
unless the routine detects an error or a warning has been flagged (see Section 6
6 Error Indicators and Warnings
If on entry
, explanatory error messages are output on the current error message unit (as defined by X04AAF
Errors or warnings detected by the routine:
|On entry,||the elements in X are not in ascending or descending order or are all equal.|
There may be a loss of significant figures for large .
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
is the rounding width.
can be compared with a standard Normal distribution, but a further approximation is given by Royston (1986)
, a value for W
is returned, but its accuracy may not be acceptable. See Section 4
for more details.
This example tests the following two samples (each of size ) for Normality.
||, , , , , , , , , , , , , , , , , , ,
||, , , , , , , , , , , , , , , , , , ,
The elements of A
are calculated only in the first call of G01DDF, and are re-used in the second call.
9.1 Program Text
Program Text (g01ddfe.f90)
9.2 Program Data
Program Data (g01ddfe.d)
9.3 Program Results
Program Results (g01ddfe.r)