Simple Linear regression in R
Problem Statement
This is an introductory project in R. As part of this project, we will take data for two variables, X and Y and
build a simple linear regression where X is the explanatory variable and Y is the response variable.
Link to Data
Detailed project with output screenshots in linked below. Click on "View Project" button.
-
Uploading the data in R studio and viewing it
> data_file <- "/My System/simpledata.csv"
> sample_data <- read.csv(data_file)
> View(sample_data)
-
Summary of the dataset
> summary(sample_data)
-
Structure of the dataset
> str(sample_data)
-
Generating Scatterplot
> plot(sample_data$X, sample_data$Y, main = "Scatterplot b/w X and Y", xlab = "X", ylab = "Y")
-
Generating Simple Linear regression and it’s summary
> simple_reg <- lm(sample_data$Y ~ sample_data$X, data = sample_data)
> summary(simple_reg)
-
Finding Intercept and Slope of the relationship
> intercept = simple_reg$coefficients[1]
slope <- simple_reg$coefficients[2]