SPWLK
Performs a Shapiro‑Wilk W‑test for normality.
Required Arguments
X — Vector of length NOBS containing the observations. (Input)
W — Shapiro Wilk W statistic. (Output)
P — P -value for a test of normality. (Output)
Optional Arguments
NOBS — Number of observations. (Input)
NOBS must be in the range from 3 to 2000 inclusive.
Default: NOBS = size (X,1).
NMISS — Number of missing observations. (Output)
FORTRAN 90 Interface
Generic: CALL SPWLK (X, W, P [, …])
Specific: The specific interface names are S_SPWLK and D_SPWLK.
FORTRAN 77 Interface
Single: CALL SPWLK (NOBS, X, W, P, NMISS)
Double: The double precision name is DSPWLK.
Description
Routine SPWLK computes the Shapiro‑Wilk W‑statistic for testing for normality. This test is thought to be one of the best omnibus tests of normality (see D’Agostino and Stevens 1986, page 406). Routine SPWLK is based upon the approximations and code given by Royston (1982a, b, c). It may be used in samples as large as 2000, or as small as 3. In the Shapiro and Wilk test, W is given by.
where x(i) is the i‑th largest order statistic,
is the sample mean, and n is the number of observations. Royston (1982) gives approximations and tabled values which may be used to compute the coefficients ai, i = 1, K, n, and obtain the significance level of the W statistic.
Comments
1. Workspace may be explicitly provided, if desired, by use of S2WLK/DS2WLK. The reference is:
CALL S2WLK (NOBS, X, W, P, NMISS, WK)
The additional argument is:
WK — Work vector of length NOBS. If X is not needed, then WK and X can share the same storage locations. On output, WK will contain the sorted nonmissing elements of X. If X is sorted, WK is not used.
2. Informational errors
Type |
Code |
Description |
4 |
2 |
There are too many missing (NaN, “not a number”) values in X for the test to be performed. |
3 |
3 |
All observations in X are tied. |
Example
The following example is taken from Conover (1980, pages 364 and 195). The data consists of 50 two digit numbers taken from a telephone book. The W test fails to reject the null hypothesis of normality at the .05 level of significance.
USE SPWLK_INT
USE UMACH_INT
IMPLICIT NONE
INTEGER NMISS, NOBS, NOUT
PARAMETER (NOBS=50)
REAL P, W, X(NOBS)
!
DATA X/23, 36, 54, 61, 73, 23, 37, 54, 61, 73, 24, 40, 56, 62, &
74, 27, 42, 57, 63, 75, 29, 43, 57, 64, 77, 31, 43, 58, 65, &
81, 32, 44, 58, 66, 87, 33, 45, 58, 68, 89, 33, 48, 58, 68, &
93, 35, 48, 59, 70, 97/
!
CALL SPWLK (X, W, P, NMISS=NMISS)
! Write out results
CALL UMACH(2, NOUT)
WRITE(NOUT,5) W, P, NMISS
5 FORMAT(/ ' W = ', F6.4 / ' P = ', F6.4 / &
' NMISS = ',I3)
END
Output
W = 0.9642
P = 0.2309
NMISS = 0