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.

  1. Uploading the data in R studio and viewing it
    > data_file <- "/My System/simpledata.csv"
    > sample_data <- read.csv(data_file)
    > View(sample_data)
  2. Summary of the dataset
    > summary(sample_data)
  3. Structure of the dataset
    > str(sample_data)
  4. Generating Scatterplot
    > plot(sample_data$X, sample_data$Y, main = "Scatterplot b/w X and Y", xlab = "X", ylab = "Y")
  5. Generating Simple Linear regression and it’s summary
    > simple_reg <- lm(sample_data$Y ~ sample_data$X, data = sample_data)
    > summary(simple_reg)
  6. Finding Intercept and Slope of the relationship
    > intercept = simple_reg$coefficients[1]
    slope <- simple_reg$coefficients[2]