## Testing Normality

In this post, I’ll demonstrate one sample test for checking if the given sample are from normal distribution with mean=0, stddev=1.

```> x = rnorm(30, 0, 1)
```

Most representative test is Shapiro Wilk.

```> shapiro.test(x)

Shapiro-Wilk normality test

data:  x
W = 0.9605, p-value = 0.3187
```

As p > 0.05, we can not reject H0 (normal distribution).

Another test is Kolmogorov-Smirnov test which is popular non-parametric test (this implies that K-S test works for small samples for which, in general, we can not assume a certain distribution) that checks if the given one-sample is from a certain distribution or two samples are from the same distribution. One limitation of Kolmogorov-Smirnov is that we can not estimate parameters of a distribution (mean and stddev, in this example) from the sample for testing purpose. Instead, we need to specify model fully.

Let’s see how K-S test works.

```> ks.test(x, "pnorm", mean=0, sd=1)

One-sample Kolmogorov-Smirnov test

data:  x
D = 0.2201, p-value = 0.09332
alternative hypothesis: two-sided
```

As explained, we need to specify model parameters. Anderson-Darling Test is one that overcomes this limitation.

```> library(nortest)

Anderson-Darling normality test

data:  x
A = 0.6474, p-value = 0.08246
```