Linear Regression- R

0
247

Let us continue with our topic of Linear Regression. In this section we would implement the linear regression using R. Please download the sample dataset to continue with the analysis. In this analysis we build a simple linear model predicting the salary of an employee based on number of years of experience. Let us start with implementation of linear regression in R.

Step 1: Set up a working directory. Setting up a working directory makes life very easy. We can refer to any file saved in working library without mentioning location again and again.

LRR_1

Step 2: Import the data set into R-Studio using following commands.

LRR_2

Step 3: Install the package required for Linear regression. We would install “caTools” for linear regression.

LRR_3

Step 4: build the linear regression model using the following command

LRR_4

Step 5: Summarize the output of regression model using the following command

LRR_5

Step 6: Predicting the regression output. In below command replace test_set with another sample data set. Basically we try test the regression results in the below command.

LRR_6

So, in the above mentioned 6 steps we could implement the very basic linear regression model using R.

 

LEAVE A REPLY

Please enter your comment!
Please enter your name here