• 2nd Floor, #7a, High School Road, Secretariat Colony Ambattur, Chennai-600053 (Landmark: SRM School) Tamil Nadu, India
• pro@slogix.in
• +91- 81240 01111

### How to test normality using R?

###### Description

To test the normality of the given data in R programming.

#### Visual methods:

Histogram (R Function : hist())

Q-Q plot (R Function : plot(qqnorm()))

Density plot : (R Function : plot(density()))

#### Normality test:

R Package : nortest

Anderson- Darling test (R Function : test() )

Shapiro- Wilk test

###### Sapmle Code

#Normality Test in R
#install caret package
#install.packages(“caret”)
library(“caret”)
#Get and Set Working Directory
print(getwd())
setwd(“/home/soft13”)
getwd()

#install.packages(“xlsx”)
library(“xlsx”)
print(data)
View(data)

#Check Normality
#Histogram Test for Normality
x1<-data\$speed
x2<-data\$dist
hist(x1,col=”yellow”)
hist(x2,col=”violet”)

#Q-Q plot
plot(qqnorm(x1))
#Generating a line for Q-Q plot
qqline (x1, col=2)
title(main=”Normal Q-Q Plot”)

#Density plot
plot(density(x1))
polygon(density(x1),col=”blue”)

#Anderson – Darling test for Normality
#install.packages(“nortest”)
library(“nortest”)