How to implement Multiple Linear regression using R?

Description

To implement the multiple linear regression in R programming.

1) Range or variation :

  • Step 1 : Import the data
  • Step 2 : Check Correlation between the variables
  • Step 3 : Create a relationship model using lm() function in R
  • Step 4 : Summary of the linear model using summary() function
  • Step 5: Check normality o the residuals.
  • Step 6 : Visualizing the regression graphically.
  • Step 7 : Predicting the dependent variable for two or more independent variable using predict() function.

#Hypothsesis Testing

#Get and Set Working Directory
print(getwd())
setwd(“/home/soft13″)
getwd()

#Read file from Excel
#install.packages(“xlsx”)
library(“xlsx”)
data<-read.xlsx(“mtcars.xlsx”,sheetIndex=1)
View(data)
x1<-data$mpg
x2<-data$disp

#Check Normality

#Anderson – Darling Test
library(“nortest”)
ad.test(x1)

#One Sample t test
t.test(x1)

#Two Sample t test
t.test(x1,x2)

#One sample Z test
#install.packages(“TeachingDemos”)
library(“TeachingDemos”)
z.test(x1,sd=sd(x1))

#Chi- Squared Test
chisq.test(data$mpg,data$cyl)

#F- test
var.test(x1,x2)
fisher.test(x1,x2)

Leave Comment

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

clear formSubmit