Shapiro-Wilks test of Normality

Enter the name for this tabbed section: Description
This test evaluates whether a sample was taken from a Normal distribution. The statistics W summarises the discrepancies with similar number taken from a normal distribution and uses principles of symmetry around the median of the Normal distribution. When the distribution is normal, W takes values very close to 1 and W decreases as the distribution is less and less normal.
Enter the name for this tabbed section: R Syntax
In R, the test can be performed using the function:

shapiro.test{stats}

shapiro.test(var1)
  • var1 is a vector with the values observed in the sample.

The Shapiro-Wilks test has been shown to have power equal or superior to other normality test (Kolmogorov Smirnov, Lillifors, Anderson-Dealing, etc.
Enter the name for this tabbed section: Example

Let’sfirst create two samples: the first one ns is normally distributed (mean = 34, standard deviation = 4.3). The second samples is extracted from a chi-square distribution with 4 degrees of freedom. This second sample represents a typical “non-normal” distribution. Both have 24 observations.

# put a samples from a normal distribution into ns
# and from a chi-square distribution into nchi
ns <- rnorm(24, mean = 34, sd = 4.3)
nchi <- rchisq(24, df = 4)

# we can now carry out the test on the first sample
shapiro.test(ns)
## 
##  Shapiro-Wilk normality test
## 
## data:  ns
## W = 0.93659, p-value = 0.1369

Then on the second sample

# we can now carry out the test on the second sample
shapiro.test(nchi)
## 
##  Shapiro-Wilk normality test
## 
## data:  nchi
## W = 0.90614, p-value = 0.0291

Shapiro-Wilks test had no problem identifying that the second sample did not come from a normal distribution (p = 0.004), and that the first sample was likely sampled from a Normal distribution (p = 0.51)