Você está na página 1de 3

Statistics and Computing (1992) 2, 1 1 7 - 1 1 9

Approximating the Shapiro-Wilk W-test


for non-normality
PATRICK ROYSTON
Department of Medical Physics, Royal Postgraduate Medical School, Ducane Road,
London W12 ONN

Received October 1991 and accepted October 1991

A new approximation for the coefficients required to calculate the Shapiro-Wilk W-test is
derived. It is easy to calculate and applies for any sample size greater than 3. A normalizing
transformation for the W statistic is given, enabling its P-value to be computed simply. The
distribution of the new approximation to W agrees well with published critical points which
use exact coefficients.
Keywords: Non-normality, Shapiro-Wilk W-test

1. Introduction deviation of the Yi, assuming normality. The exact value of


a is
Shapiro and Wilk's (1965) W-test is a well-established and a = (lnTv -1 V-Inl)-1niT V- 1
powerful test of departure from normality. Royston
(1982a) extended the test from the original sample size of where V is the covariance matrix of the order statistics of
n = 50 to n = 2000. The extension was based on Shapiro a sample of n standard normal random variables with
and Wilk's own suggested approximation to the co- expectation vector m. The vector a is antisymmetric, that
efficients used in the calculation of W, but no evaluation is, an = - al and, for odd n, a~,m + 1 = 0. Also aXa = 1, so
was made of its accuracy. Unfortunately, the use of exact for n = 3, an = --a~ = 2-89 The values of m and V may be
rather than approximate coefficients requires matrix ma- calculated using the algorithms of Royston (1982b) and
nipulations which are both computationally demanding Davies and Stephens (1978), respectively, supplemented by
and memory-hungry. In this paper, a new approximation that of Shea and Scallan (1988) for V~l, the variance of the
to the coefficients is produced which is simple, convenient largest order statistic. Since V is a symmetric n x n matrix,
and satisfactory for any sample size. A normalizing trans- storage of at least n + n(n + 1)/2 reals followed by n x n
formation of the W statistic is provided to enable simple matrix inversion is needed to compute a. For large samples
calculation of the P-value of the test for 4 < n -< 2000, (say, n > 250), tile task is beyond most statistical packages
though extrapolation beyond 2000 appears justified. and desktop machines, even with today's technology.
As noted indirectly by Verrill and Johnson (1988), the
W-test is asymptotically equivalent to the Shapiro and
2. New approximation Francia (1972) statistic

Suppose Yl < Y2 < 9 9 - < Y n i s a n ordered sample o f s i z e n


to be tested for non-normality. The W statistic is defined
T 1
by where bi = (m m) -Smi, and to the Welsberg and Bingham
(1975) staUstlc
" 9 (Z c~y~)2/Z ( Y i - Y-) 2 , where c~ = ( m~ T m)
~ 1 _2m;,
~

W = aiy i ( Y i - - f2) 2 rhi = ~ l { ( i _ 3)/(n + 41_)}and ~ is the normal cdf. Thus b


and e may be regarded as first approximations to a, e being
where a = (al . . . . . an) T is such that (n - 1) -89Z aiyi is the particularly simple to compute since it only requires the
best linear unbiased estimate (BLUE) of the standard inverse normal cdf.
0 9 6 0 - 3 1 7 4 / 9 2 $03.00 + .12 9 1992 C h a p m a n & H a l l
118 Royston

I n fact, up to a c o n s t a n t , b a n d e differ f r o m a m a i n l y in Table 1. E x a c t values o f an and some approximations


the first two c o m p o n e n t s (also in the last two, b u t
ai -- - a~ _ i + 1). Because o f its convenience, e was chosen n E x a c t an Shapiro-Wilk an cn
as the basis for a p p r o x i m a t i n g a. P o l y n o m i a l (quintic 1
regression analysis o f an - c, a n d a , 1 - - Cn-- 1 o n x = n - g 4 0.6873 0.6869 0.6873 0.6800
5 0.6645 0.6647 0.6646 0.6516
for 4 _ n -< 1000 gave the following equations:
6 0.6430 0.6431 0.6430 0.6258
fin = c~ + 0.221157x - 0.147981x z - 2.071190x 3 7 0.6232 0.6258 0.6231 0.6029
8 0.6051 0.6039 0.6051 0.5826
+ 4.434685x 4 - 2.706056x 5 9 0.5887 0.5854 0.5887 0.5645
~ln 1 = Cn - 1 -al- 0.042981x - 0.293762x 2 -- 1.752461x 3 10 0.5737 0.5694 0.5737 0.5483
12 0.5474 0.5429 0.5474 0.5204
+ 5.682633x 4 - 3.582663x 5 15 0.5149 0.5124 0.5150 0.4868
20 0.4733 0.4758 0.4734 0.4449
T h e n n o r m a l i z i n g the r e m a i n i n g rhi b y writing 25 0.4417 0.4450 0,4418 0.4138
4 = ( ~Tfil - 2rh2)/( 1 - 2 a-2. ) if n -< 5 30 0.4166 0.4255 0.4167 0.3895
40 0.3786 0.3964 0.3786 0.3530
= (~'rfil -- 2rh~ -- 2mn_
~ 2 1)/(1 --2~72 -- 2~2_ ~) ifn >5 50 0.3506 0.3751 0.3506 0.3265
75 0.3034 0.3392 0.3034 0.2823
we have
100 0.2729 0.3158 0.2728 0.2539
{li = ~p - ~rn i 125 0.2510 0.2988 0.2509 0.2335
150 0.2341 0.2855 0.2340 0.2179
for i - - 2 , . . . , n - 1 (n-<5) or i=3 .... ,n-2(n>5). 200 0.2094 0.2657 0.2093 0.1951
250 0.1918 0.2514 0.1918 0.1788
350 0.1677 0.2311 0.1677 0.1566
3. S o m e c o m p a r i s o n s 500 0.1451 0.2114 0.1452 0.1357
750 0.1228 0.1910 0.1229 0.1151
A c o m p a r i s o n between various a p p r o x i m a t i o n s to a, is 1000 0.1089 0.1778 0.1091 0.1023
given in T a b l e 1. S h a p i r o a n d W i l k ' s (1965) a p p r o x i m a -
tion for n > 20 ( R o y s t o n , 1982a, for n > 50) is inadequate;
even their 'exact' values for n <- 20 are incorrect. T h e new
a p p r o x i m a t i o n , 8~, is a c c u r a t e to +_ 1 in the f o u r t h decimal
4. N o r m a l i z a t i o n o f W s t a t i s t i c
place. The a s y m p t o t i c a p p r o x i m a t i o n c~----(ff~Xlia)-Srn,
converges slowly to an b u t is still a b o u t 6 % t o o low at
F o r n = 3, the c d f o f W is (6/~) { s i n - ' ( W ~ ) - sin-l(0.75 89
n - - 1 0 0 0 . T h e m a x i m u m a b s o l u t e errors over all i
( S h a p i r o a n d Wilk, 1965), small values i n d i c a t i n g n o n -
(1 -< i <- n) a n d selected n (4 -< n < 1000, as in T a b l e 1) are
n o r m a l i t y . F o r 4 < n < 11, a t h r e e - p a r a m e t e r l o g n o r m a l
0.0689 for S h a p i r o a n d W i l k , 0.0010 for g a n d 0.0335 for
d i s t r i b u t i o n was f o u n d to fit the e m p i r i c a l ( s i m u l a t i o n )
c~. T h e e r r o r in fi is greatest in the f o u r t h c o m p o n e n t
d i s t r i b u t i o n o f l n ( 1 - W) adequately. A t w o - p a r a m e t e r
(i = 4).
l o g n o r m a l fitted the u p p e r h a l f o f the d i s t r i b u t i o n o f
Critical percentage p o i n t s o f the W statistic using differ-
1 - W for n > 11. T h e mean, #, a n d s t a n d a r d deviation, a,
ent a p p r o x i m a t i o n s to a are s h o w n in Table 2. The p o i n t s
o f w ( t r a n s f o r m e d W) were e s t i m a t e d as the m e d i a n a n d
were o b t a i n e d by s i m u l a t i o n o f p s e u d o r a n d o m n o r m a l l y
(95th centile - m e d i a n ) / 1.6449 o f w, respectively, a n d were
d i s t r i b u t e d samples with 10 000 repetitions per s a m p l e size.
s m o o t h e d as follows. F o r 4 < n -< 11:
The values for exact a are t a k e n f r o m T a b l e 1 o f Verrill
a n d J o h n s o n (1988) a n d were b a s e d on 5000 repetitions. w = - ln[7 - ln(1 - W)]
The p o i n t s using the fi a p p r o x i m a t i o n agree closely with
y = - 2 . 2 7 3 + 0.459n
those o f Verrill a n d J o h n s o n (the v a r i a t i o n is greater at
the 0.01 critical point, as w o u l d be expected). R o y s t o n # = 0.5440 - 0.39978n + 0.025054n z - 0.0006714n 3
(1982a) gives m u c h lower critical values for n > 80, be-
a = exp( 1.3822 - 0.77857n + 0.062767n 2 - 0.0020322n 3)
cause the i m p o r t a n t a ~ / a n _ ~ coefficient ratio is far t o o
large, which places i n a p p r o p r i a t e weight on the extreme F o r 12 < n -< 2000:
s a m p l e values relative to the next m o s t extreme. T h e 0.05
x=lnn
critical p o i n t s for the ~ a p p r o x i m a t i o n with n > 2000 were
o b t a i n e d b y e x t r a p o l a t i o n using the n o r m a l i z a t i o n o f W w = in( 1 - W )
described in the next section. N o t e h o w closely they agree
# = - 1.5861 - 0.31082x - 0.083751x 2 + 0.0038915x 3
with Verrill a n d J o h n s o n ' s exact 0.05 p o i n t s c a l c u l a t e d
f r o m a s y m p t o t i c theory. a = exp( --0.4803 - 0.082676x + 0.0030302x 2)
A p p r o x i m a t i n g the Shapiro - W i l k W - t e s t f o r non-normality 119

Table 2. Some critical points for W

n Royston (1982a) Based on ~ Verrill and Johnson (1988)


0.05 0.01 0.05 0.01 0.05 0.01

20 0.904 0.868 0.904 0.866 0.905 0.855


30 0.928 0.902 0.930 0.903 0.929 0.893
40 0.941 0.922 0.945 0.924 0.945 0.917
60 0.9538 0.9411 0.9605 0.9459 0.9606 0.9442
80 0.9602 0.9505 0.9691 0.9579 0.9694 0.9565
100 0.9642 0.9561 0.9746 0.9654 0.9747 0.9652
150 0.9698 0.9640 0.9822 0.9760 0.9821 0.9750
250 0.9748 0.9710 0.9888 0.9850 0.9890 0.9853
500 0.97945 0.97707 0.99411 0.99218 0.99419 0.99200
1000 0.98305 0.98159 0.99692 0.99594 0.99683* -
2000 0.98602 0.98514 0.99839 0.99790 0.99837* -
4000 - - 0.99915 0.99890 0.99916* -
5000 - 0.99931 0.99910 0.99932* -

*Asymptotic points

To find the P-value for W, z = (w - #)/a is referred to the accompany the W-test to provide qualitative information
upper tail of N(0, 1). about the shape of the sample distribution.

Worked example. The following is a r a n d o m sample of size References


10 from a lognormal distribution: 48.4, 49.0, 59.5, 59.6, 60.7,
88.8, 98.2, 109.4, 169.1, 227.1. The first five approximate Davies, C. S. and Stephens, M. A. (1978) Algorithm AS128.
expected order statistics (rh) for n = 10 are -1.5466, Approximating the covariance matrix of normal order statis-
- 1.0005, - 0.6554, - 0.3755, - 0.1226 and the correspond- tics. Applied Statistics, 27, 206 212.
ing approximate coefficients (~) are -0.5737, -0.3290, Royston, J. P. (1982a) An extension of Shapiro and Wilk's W test
for normality to large samples. Applied Statistics, 31, 115 - 124.
-0.2143, -0.1228, -0.0401. Thus W = 158.5942/
Royston, J. P. (1982b) Algorithm AS177. Expected normal order
31136=0.8078. For n = 1 0 , we have 7 = 2 . 3 1 7 , # = statistics (exact and approximate). Applied Statistics, 31,
- 1.6198, a = 0.I 1544, giving w = - 1.3779, z = ( w - #)/o- 161-165.
=2.095 and P = 0.018. The data depart significantly from Royston, J. P. (1983) Some techniques for assessing multivariate
normality at the 0.02 significance level. The value of Wusing normality based on the Shapiro-Wilk W. Applied Statistics,
exact coefficients (a) is also 0.8078 to four decimal places, 32, 121-133.
so the approximation here introduces negligible error. Royston, P. ( 1991a) Estimation, reference ranges and goodness-of-
fit for the three-parameter lognormal distribution. Statistics
in Medicine, in press.
Royston, P. ( 1991b) Aspects of goodness-of-fit tests for normality.
5. Comments
I. Use of the tests when the data contain ties. Technometrics,
submitted.
The W-test may be modified for use in different situations, Shapiro, S. S. and Francia, R. S. (1972) An approximate analysis
including testing normality in censored samples (Verrill and of variance test for normality. Journal of the American
Johnson, 1988), multivariate normality (Royston, 1983) Statistical Association, 67, 215-216.
and goodness-of-fit of the three-parameter lognormal dis- Shapiro, S. S. and Wilk, M. B. (1965) An analysis of variance test
tribution (Royston, 1991a). Its power characteristics are for normality (complete samples). Biometrika, 52, 591-611.
well known and m a y be summarized by saying that it is Shea, B. L. and Scallan, A. J. (1988) AS R72. A remark on
strongest against short-tailed (platykurtic) and skew distri- Algorithm AS128: approximating the covariance matrix of
butions and weakest against symmetric moderately long- normal order statistics. Applied Statistics, 37, 151-155.
Verrill, S. and Johnson, A. (1988) Tables and large-sample
tailed (leptokurtic) distributions. A negative feature is its
distribution theory for censored-data correlation statistics for
sensitivity to the presence of ties in the data, caused by
testing normality. Journal of the American Statistical Associ-
rounding or imprecise measurement. It then rejects the null ation, 83, 1192 1197.
hypothesis too often, but Royston (1991b) shows how to Weisberg, S. and Bingham, C. (1975) An approximate analysis of
obtain conservative P-values under such circumstances. In variance test for non-normality suitable for machine calcula-
practical terms, a normal probability plot should always tion. Technometries, 17, 133-134.

Você também pode gostar