You are on page 1of 2

Testing for Assumptions of OLS

Compiled by Vishesh Garg and Pallavi Mehrotra

Test for Normality


Jarque Bera Test
1. Install.packages(“normtest”)
2. Library(normtest)
3. myData<-read.csv(file.choose(), header=TRUE) #Select nks.csv file
4. attach(myData)
5. x1 <- cbind(Sales)
6. x2 <- cbind(Price)
7. x1NormTest <- jb.norm.test(x1)
8. x2NormTest <- jb.norm.test(x2)
9. print(x1NormTest)
10. print(X2NormTest)

H0 = Data follows normal distribution


H1 = Data does not follow normal distribution

If the p-value is less than 0.05, the data does not follow normal distribution.

Shapiro Wilk Test


1. myData<-read.csv(file.choose(), header=TRUE) #Select nks.csv file
2. attach(myData)
3. x1 <- cbind(Sales)
4. x2 <- cbind(Price)
5. Shapiro.test(x1)

H0 = Data follows normal distribution


H1 = Data does not follow normal distribution

If p-value is less than 0.05, the data does not follow normal distribution

Test for Multicollinearity


Obtain Correlation Matrix

1. Import data to “mydata” variable


2. Cor(mydata)
3. See the correlation between independent variables
4. If greater than 0.75, there can be multicollinearity

Obtain VIF

1. Install.packages(“faraway”)
2. Library(farway)
3. Import nks.csv as mydata
4. Model1<- lm(Profits ~ Sales + Price, data=mydata)
5. Summary(Model1) #This gives us a simple linear regression model statistics
6. Vif(model1)
7. We see the VIF for all the variables.

If the VIF of any independent variable is more than 10, there is severe multi-collinearity problem

Test for Heteroskedasticity


Breusch Pagan Test (bptest)
H0 = Homoskedasticity, that is variance of residuals is equal
H1 = Heteroskedasticity

1. Install.packages(“lmtest”) #you may not need to install, default packages, go to next step
2. Library(lmtest)
3. Import nks.csv as mydata
4. Attach(mydata)
5. Model1 <- lm(Profits~Sales+Price, data=mydata)
6. bptest(Model1)

if the p-value is less than 0.05, we conclude that the data has heteroskedasticity

Can also be concluded by looking at graph of residuals.

Test for Autocorrelation


Durbin Watson test
1. library(lmtest)
2. import data as mydata (panel data)
3. attach(mydata)
4. y <- cbind (Sales)
5. x <- cbind(Price,Repairs)
6. model1 = lm(y~x, data=mydata)
7. dwtest(model1)

If the p-value is less than 0.05, there is autocorrelation.

You might also like