The following version of the Shapiro-Wilk Test handles samples between 12 and 5,000 elements, although samples of at least 20 elements are recommended. We also show how to handle samples with more than 5,000 elements.

Assuming that the sample has *n* elements, perform the following steps:

1. Sort the data in ascending order *x*_{1} ≤ … ≤ *x _{n}*

2. Define the values *m*_{1}*, …, m _{n}* by

*m _{i}* = NORMSINV((

*i −*.375)/(

*n*+ .25))

3. Let *M* = [*m _{i}*] be the

*n*× 1 column vector whose elements are these

*m*and let

_{i}If *M* is represented by the *n* × 1 range R1 in Excel, then =SUMSQ(R1) calculates the value *m*.

4. Set *u* = 1/ and define the coefficients *a _{1}*

*, …, a*where

_{n}*a _{i}* =

*m*/ for 2 <

_{i}*i*<

*n*− 1

*a*_{2} = −*a _{n}*

_{-1}

*a*

_{1}= −

*a*

_{n}It turns out that *a _{i}* = −

*a*

_{n-i+}_{1}

*for all*

*i*and that

_{ }

where* A* = [*a _{i}*] is the

*n*× 1 column vector whose elements are the

*a*

_{i}.5. The *W* statistic is now defined by

Because of the above properties of the coefficients *a _{1}*

*, …, a*it turns out that

_{n}*W*= the square of the correlation coefficient between

*a*

_{1}*, …, a*and

_{n}*x*

_{1}*, …, x*. Thus the values of

_{n}*W*are always between 0 and 1.

It also turns out that for values of *n* between 12 and 5,000 the statistic ln (1−*W*) is approximately normally distributed with the following mean and standard deviation:

6. Thus we can test the statistic

using the standard normal distribution. If the p-value ≤ *α* then we reject the null hypothesis that the original data is normally distributed.

**Example 1**: Repeat Example 1 of Shapiro Wilk Original Test using the expanded test.

We carry out the calculations described above to get the results shown in Figure 1 (see Figure 2 for key formulas used). The *W* statistic is 0.971066. The p-value = .921649 > .05 = *α* shows that there are no grounds for rejecting the null hypothesis that the data is normally distributed.

**Figure 2 – Key formulas from Figure 1**

**Real Statistics Excel Functions**: The Real Statistics Resource Pack contains the following supplemental functions where R1 consists of only numerical data without headings.

**SHAPIRO**(R1) = the Shapiro-Wilk test statistic *W* for the data in the range R1 using the expanded method

**SWTEST**(R1) = p-value of the Shapiro-Wilk test on the data in R1 using the expanded method

**SWCoeff**(*n, j*) = the *j*th coefficient for samples of size *n*

**SWCoeff**(R1, C1) = the coefficient corresponding to cell C1 within sorted range R1.

Note that these functions can optionally take an additional argument *b, *i.e. SHAPIRO(R1, *b*), SWTEST(R1, *b*), SWCoeff(*n, j, b*) and SWCoeff(R1, C1, *b*). When omitted this argument defaults to True (i.e. the values for the expanded Shapiro-Wilk test as described above are used). If *b* is set to False then the values for the original Shapiro-Wilk test are used instead.

**Observation**: The functions SHAPIRO and SWTEST ignore all empty and non-numeric cells. The range R1 in SWCoeff(R1, C1) should not contain any empty or non-numeric cells.

**Example 2**: Determine whether the data in range A3:E14 of Figure 3 is normally distributed using the Shapiro-Wilk’s test.

This time we use the supplemental functions described above to obtain the results shown in Figure 3. The value of *W* and the p-value are as indicated using the formulas indicated. Since p-value = 0.019314 < .05 = *α*, we reject the hypothesis that the data is normally distributed. Note that we don’t need to sort the data and the data does not have to be arranged in a column to use the formulas.

If for some reason we want to obtain the coefficients, we need to sort the data. This is done by highlighting the range G3:K14 and entering =QSORT(A3:E14) and simultaneously pressing **Ctrl-Shft-Enter**. The first coefficient is obtained by entering the formula =SWCoeff($G$3:$K$14,G3) in cell M3. If you highlight the range M3:Q14 and press **Ctrl-R** and **Ctrl-D**, all the coefficients will be displayed as shown in Figure 3.

**Observation**: If a sample larger than 5,000, you can randomly divide the larger sample into a number of approximately equal-sized smaller samples and then run the SW algorithm as described above on each sample to obtain the z score for each smaller sample. Suppose that there are *k* such samples with z scores of* z*_{1}*, …, z _{k}.* Recall that if range R1 contains sample

*i*then

*z*= NORMSINV(SWTEST(R1)).

_{i}The average of the z-scores will be an approximation of the z value for the whole sample. The expected mean of *z* is the average of the means of the *z _{i},* namely 0 and the standard deviation of

*z*should be the standard deviation of the

*z*divided by √

_{i}*k*, namely 1/. Thus you should test

*z*using the standard normal distribution.

**Real Analysis Data Analysis Tool**: The **Descriptive Statistics and Normality** supplemental data analysis tool in the Real Statistics Resource pack has a Shapiro-Wilk option. You can use this option to perform the Royston version of the SW Test, as described in Example 3.

**Example 3**: Determine which of the three samples displayed on the left side (range A3:C16) of Figure 4 is normally distributed.

Enter **Ctrl-m** and select the **Descriptive Statistics and Normality** tool from the dialog box that appears. The dialog box shown in Figure 5 now appears. Choose the **Descriptive Statistics**, **Box Plot** and **Shapiro-Wilk** options as shown.

**Figure 5 – Dialog box for Descriptive Statistics and Normality**

The resulting output is shown on the right side of Figure 4. As we can see, based on the Shapiro-Wilk test only Sample 2 shows a significant departure from normality (p-value = 0.044 < .05 = *α*).

This conclusion is supported by the fact that the kurtosis for Sample 2 is high (3.326) and the fact that the Box Plot for Sample 2 is not very symmetric.

Note that at present, the SW Test only produces the correct answer if there are no blank or non-numeric cells in the data.

Hi,

I’m updating my statistical textbook (a Finnish one) and found your site when seeking a simple calculation of Royston’s procedure. Here I found it – if it can be simple…. Thanks for it. I’ll make a link from the book to your page for thise who are interested in working in the Excel environment.I myself have demonstrated practically all the methods first by using Excel and then by SPSS.

In this page, there seems to be a tiny mistake which may be good to update. Namely in the formula of W, there seems to miss the second power of SUM(aixi). In your Excel figure the value is calculated by using the second power but the formula misses it. Am I correct?

JMe

Hello Jari,

I am very pleased that my website has been helpful. I also appreciate your adding a link from your textbook to my site.

Thanks also for catching the typo on the web page. I have now corrected the error.

Charles

Dear Charles,

I’m trying to apply the Shapiro-Wilk expanded Test to my dataset but I don’t understand how to calculate the parameters used to estimate the coefficients a(n), a(n-1),…

Could you help me?

Thank you.

Carole

Hi Carole,

The website offers three choices. If your sample has at most 50 elements you can use the a(n), … coefficients in the original paper of Shapiro and Wilk. A table of these coefficients can be found on the webpage http://www.real-statistics.com/statistics-tables/shapiro-wilk-table/. Note that a(n) = a(1), a(n-1) = a(2), etc. A description of how you use these coefficients can be found on the webpage http://www.real-statistics.com/tests-normality-and-symmetry/statistical-tests-normality-symmetry/shapiro-wilk-test/

Alternatively you can calculate the coefficients as described on the webpage http://www.real-statistics.com/tests-normality-and-symmetry/statistical-tests-normality-symmetry/shapiro-wilk-expanded-test

The Real Statistics Resource Pack also provides an Excel function called SWCoeff(n, j). This returns the coefficient a(j) for a sample of size n. You can download the Real Statistics Resource Pack for free as described on the webpage http://www.real-statistics.com/free-download/real-statistics-resource-pack/

You can also use the function SWTEST which carries out the Shapiro-Wilk test without having to worry about the actual values of the a(j) coefficients. This function can also be found in the Real Statistics Resource Pack.

Charles

Carole,

I forgot to mention one other important thing. You can look at the actual Excel worksheet that carries out the calculation found in Figure 1 of the webpage http://www.real-statistics.com/tests-normality-and-symmetry/statistical-tests-normality-symmetry/shapiro-wilk-expanded-test/. This will tell you exactly how I was able to calculate the values for a(n), … This and all the other examples in the website are contained in the Real Statistics Examples Workbook.

You can download Real Statistics Examples Workbook for free from the webpage http://www.real-statistics.com/free-download/real-statistics-examples-workbook/.

Charles

Hello Mr. Zaionts,

thank you very much for all that great work you did here. I could follow you explanations to the expanded Shapiro Wilk test and I could calculate the values for the first example (the ages statistics). The only thing I couldn’t find is how to actually calculate the p-value for samples with n>50. In the example the p-value is calculated with 0,921649 with W=0,971066. How is the p-value calculated? and what is the z-value for.

Thank you very much!

Joerg

Hello Joerg,

As described in step 5 on the webpage http://www.real-statistics.com/tests-normality-and-symmetry/statistical-tests-normality-symmetry/shapiro-wilk-expanded-test/, it turns out that ln(1-W) has a normal distribution with the mean and standard deviation as given in step 5. z is simply the z-score for ln(1-W); i.e. z = STANDARDIZE(ln(1-W),mean,stdev). Thus we can test z using NORMSDIST or NORM.S.DIST, as described in step 6; i.e. p-value = 1-NORMSDIST(z).

For Example 1, z is calculated by the formula =STANDARDIZE(LN(1-Y9),Y10,Y11) and p-value is calculated by the formula =1-NORMSDIST(Y12).

Charles

Hi Charles,

Thanks for the article. To tell you the truth though, I am really struggling to figure out how you are calculating the a coefficients.

Is the value of mn in the coefficient function: an = …, equal to the last item in the M vector (e.g., in this example, is mn equal to 1.63504)?

Also, is mn-1 in the second function, a(n-1) equal to the second to last item in the M vector?

I think it would really help me, and many others who view this already great article, if you would show the exact values that are being plugged into the a(n), a(n-1), e = …, functions. And if you could just please show a complete ai() example, that would make this article even better.

Thank you so much,

Hi MWS,

I will update the webpage to provide a complete example as you suggest. I will do this after I finish Release 2.8 of the Real Statistics Resource Pack which I hope to release in the next few days.

Charles

Sorry to keep bugging you Charles, but could you please show me us a complete example for calculating the first two values and the last two values of the A vector? Anyways, thanks again for the helpful article. Now if only I could get these a values calculated

No problem. Now that I have finished the latest releases, I plan to update the referenced webpage to provide a more complete explanation. Charles

I have updated the referenced webpage. See Figure 2 for a description of most of the formulas shown in Figure 1, including the formulas for the A vector. Charles

Charles,

Great tools – thanks very much. I have a query on the use of the NORMSDIST function to generate a p-value.

The NORMSDIST function returns a cumulative probability. One minus the NORMSDIST output returns the right sided probability (p for the tail). This is a one-sided test result as I understand it. If you want to obtain a two-sided p-value then we ask for 2*(1-NORMSDIST()).

Is this not more appropriate. Is there some reason why the Shapiro-Wilks test should be based on a on-sided z-test?

Thanks

Nigel

Nigel, sorry, but I don’t know why Shapiro and Wilk designed the test in this way. Charles

Sir

In the last Observation (sample size > 5000), you wrote: zi = NORMSINV(SWTEST(R1)). Why not zi = NORMSINV(1-SWTEST(R1)).

And you said “Thus you should test z/sqrt(k) using the standard normal distribution”, is that a typo? Do you mean z*sqrt(k)

Colin