R Code for Checking Normality Assumptions

As requested, here's some R code for checking the normality of a set of data. In the code below, I've assigned to the variable x a set of 12 random numbers generated from a normal distribution. For your projects, you'll already have a set of data to check.

> x <- rnorm(12,0,1)
> x
 [1]  1.45969937  1.06523019 -0.55190387  0.50203983 -0.18073330
 [6]  0.03498171  0.74422040 -0.26451116 -0.99968966 -1.65212671
[11]  1.16201012  0.29497770
> qqnorm(x)
> qqline(x)
> hist(x)
> counts <- vector(mode="numeric",3)
> for (i in 1:3) counts[i] <- length(subset(x,abs(x-mean(x)) < i*sd(x)))/length(x)
> counts
[1] 0.5833333 1.0000000 1.0000000

The above code generated these two plots:

Leave a Reply

Your email address will not be published. Required fields are marked *