hide long namesshow long names
hide short namesshow short names
Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

NAG Toolbox: nag_stat_test_shapiro_wilk (g01dd)

Purpose

nag_stat_test_shapiro_wilk (g01dd) calculates Shapiro and Wilk's WW statistic and its significance level for testing Normality.

Syntax

[w, pw, ifail, a] = g01dd(x, 'n', n, 'a', a)
[w, pw, ifail, a] = nag_stat_test_shapiro_wilk(x, 'n', n, 'a', a)
Note: the interface to this routine has changed since earlier releases of the toolbox:
Mark 23: a is now optional, calwts is no longer an input parameter, output parameters have been reordered
.

Description

nag_stat_test_shapiro_wilk (g01dd) calculates Shapiro and Wilk's WW statistic and its significance level for any sample size between 33 and 50005000. 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 x1,x2,,xnx1,x2,,xn sorted into either ascending or descending order (nag_sort_realvec_sort (m01ca) may be used to sort the data) this function calculates the value of Shapiro and Wilk's WW statistic defined as:
W = (
(n ) ∑ aixii = 1 2
)/( ∑ i = 1n (xi − x)2),
W= (i=1naixi) 2 i=1n (xi-x-) 2 ,
where x = 1/n 1n xi x- = 1n 1n xi  is the sample mean and ai ai , for i = 1,2,,n i=1,2,,n , are a set of ‘weights’ whose values depend only on the sample size nn.
On exit, the values of aiai, for i = 1,2,,ni=1,2,,n, are only of interest should you wish to call the function again to calculate ww and its significance level for a different sample of the same size.
It is recommended that the function is used in conjunction with a Normal (QQ)(Q-Q) plot of the data. Functions nag_stat_normal_scores_exact (g01da) and nag_stat_normal_scores_approx (g01db) can be used to obtain the required Normal scores.

References

Royston J P (1982) Algorithm AS 181: the WW test for normality Appl. Statist. 31 176–180
Royston J P (1986) A remark on AS 181: the WW test for normality Appl. Statist. 35 232–234
Royston J P (1992) Approximating the Shapiro–Wilk's WW 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 WW test for normality Appl. Statist. 44(4) 547–551

Parameters

Compulsory Input Parameters

1:     x(n) – double array
n, the dimension of the array, must satisfy the constraint 3n50003n5000.
The ordered sample values, xixi, for i = 1,2,,ni=1,2,,n.

Optional Input Parameters

1:     n – int64int32nag_int scalar
Default: The dimension of the arrays x, a. (An error is raised if these dimensions are not equal.)
nn, the sample size.
Constraint: 3n50003n5000.
2:     a(n) – double array
If supplied, a must contain the nn weights as calculated in a previous call to nag_stat_test_shapiro_wilk (g01dd), otherwise a need not be set.

Input Parameters Omitted from the MATLAB Interface

None.

Output Parameters

1:     w – double scalar
The value of the statistic, ww.
2:     pw – double scalar
The significance level of ww.
3:     ifail – int64int32nag_int scalar
ifail = 0ifail=0 unless the function detects an error (see [Error Indicators and Warnings]).
4:     a(n) – double array
The nn weights required to calculate ww.

Error Indicators and Warnings

Errors or warnings detected by the function:
  ifail = 1ifail=1
On entry,n < 3n<3.
  ifail = 2ifail=2
On entry,n > 5000n>5000.
  ifail = 3ifail=3
On entry,the elements in x are not in ascending or descending order or are all equal.

Accuracy

There may be a loss of significant figures for large nn.

Further Comments

The time taken by nag_stat_test_shapiro_wilk (g01dd) depends roughly linearly on the value of nn.
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 nag_stat_test_shapiro_wilk (g01dd) for a given sample size, unless calwts is reset to true before each call of nag_stat_test_shapiro_wilk (g01dd).
The Shapiro and Wilk's WW 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 ww,
WA = W ( ∑ x(i) − x 2 )/(
(n ) ∑ x(i) = x2 − (n − 1)/12ω2i = 1
) ,
WA=W x(i) - x- 2 { i=1n x(i)=x- 2 - n-1 12 ω2 } ,
where ωω is the rounding width. WAWA can be compared with a standard Normal distribution, but a further approximation is given by Royston (1986).
If n > 5000n>5000, a value for w and pw is returned, but its accuracy may not be acceptable. See Section [References] for more details.

Example

function nag_stat_test_shapiro_wilk_example
x = [0.11;
     0.21;
     0.42;
     0.46;
     0.47;
     0.71;
     0.93;
     1.52;
     3.14;
     3.24;
     4.43;
     4.55;
     4.61;
     4.75;
     4.97;
     6.66;
     7.87;
     7.95;
     9.53;
     10.14];
[w, pw, ifail, a] = nag_stat_test_shapiro_wilk(x)
 

w =

    0.9005


pw =

    0.0421


ifail =

                    0


a =

    0.4734
    0.3217
    0.2557
    0.2083
    0.1686
    0.1336
    0.1015
    0.0713
    0.0423
    0.0140
         0
         0
         0
         0
         0
         0
         0
         0
         0
         0


function g01dd_example
x = [0.11;
     0.21;
     0.42;
     0.46;
     0.47;
     0.71;
     0.93;
     1.52;
     3.14;
     3.24;
     4.43;
     4.55;
     4.61;
     4.75;
     4.97;
     6.66;
     7.87;
     7.95;
     9.53;
     10.14];
[w, pw, ifail, a] = g01dd(x)
 

w =

    0.9005


pw =

    0.0421


ifail =

                    0


a =

    0.4734
    0.3217
    0.2557
    0.2083
    0.1686
    0.1336
    0.1015
    0.0713
    0.0423
    0.0140
         0
         0
         0
         0
         0
         0
         0
         0
         0
         0



PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2013