Checking if linear regression assumptions ( Linearity, Normality, Independence and Constant variance) are violated with R - Not for beginners One should have the basic concept in statistics to understand this and the different terms associated with this work sheet. #Regression diagnostics #R #Data & Analytics
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Regression diagnostics - Checking if linear regression assumptions are violated with R
1. ## Checking the validity of the assumption made in Linear Model for bivariate ##
#One should have the basic concept in statistics and R to understand this and the different terms associated with
this work sheet.
#Please read my Simple Linear Regression With R (http://www.slideshare.net/jeromerick/simple-linear-regression-with-
r-52336944) to get a better understanding of this lesson.
# We will use R's inbuilt data - trees
data("trees") # loading the data into R
?trees # see what the data is all about
# We will examine the assumptions for a model of the relationship between height and girth
# Where height is the y variable and girth X
plot(trees$Girth, trees$Height) # plotting the variables Girth and Height
reg1<- lm(trees$Height ~ trees$Girth) # regression model for predicting the height of the tress using the variable
girth.
reg1 # to see the model reg1
summary(reg1)
abline(reg1, col=3, lwd = 3) # plot the regression line
# Before validating the assumption of linear regression model one should know what the assumptions are for this
please refer to Gauss-Markov Theorem.
# We will be checkin the assumptions for Linearity, Normality, Independence and Constant variance.
# Concept of Autocorrelation, Simultaneity, Heteroskedasticity and Multicollinearity must be clear.
# R has inbuilt regression diagnostic plots to test assumptions of a linear regression model:
plot(reg1) # to produce the 4 diagnostic plots to test assumptions of a linear regression model
par(mfrow=c(2,2)) # change the plotting screen into two rows and two columns
plot(reg1)
par(mfrow=c(1,1)) # change the plotting screen into one rows and one columns
# R has a set of (four) build in regression diagnostic plots, they are:
# 1. Residual v/s fitted - check linearity and constant variance assumption, there should be no pattern.
# 2. Normal Q-Q - Quantile Quantile plot - check Normality assumption, the points should fall roughly on the diagonal
line if y values or errors are normally distributed.
# 3. Scale Location - It plots the root of standardized residuals and fitted values.
# 4. Residual v/s Leverage - It plots Residual v/s Leverage.
# We have Durbin-Watson test to check Autocorrelation, it wrks under the following packages
install.packages("lmtest")
install.packages("car")
require(car)
require(lmtest)
dwtest(trees$Girth ~ trees$Height)
#Regression Diagnostics - Checking if Linear regression assumptions are made
?influence
?influence.measures
lm.influence(reg1)
influence.measures(reg1)
rm(list = ls()) # To clear the data and work done
## By Jerome Gomes ##
## For queries and more information feel free to contact me @ jeromegomes89@gmail.com ##
## If you want this R-Script then mail me at the above mail id ##