2024-03-14

getwd() setwd(“/Users/ssayal08/RStudio”)

Simple Liner Regression

  • Simple linear regression (SLR) is a type of linear regression model used in statistics that has only one explanatory variable.
  • In other words, it deals with one independent variable along with a dependent variable (typically, the x and y coordinates within the Cartesian coordinate system) at two-dimensional sample points.
  • It also discovers a function that is linear (a non-vertical straight line) that as closely as possible forecasts the values of the dependent variable as a function of the variable that is independent.
  • The relationship between the outcome variable and a single predictor is indicated by the term simple.

Simple Liner Regression (continued)

  • The additional requirement that the technique of ordinary least squares (OLS) be applied is frequently made.
  • The objective of the OLS method is to minimize the sum of each of these squared deviations, which is determined by measuring the accuracy of every predicted value by its squared residual (the horizontal distance among the point of the data set as well as the fitted line).
  • In this instance, the relationship between y and x, adjusted for the ratio of these variables’ standard deviations, is what determines the slope that defines the fitted line.
  • The fitted line’s intercept is such that it goes through the data points’ center within the plane (x, y).

Plotly Plot

GGPLOT 1

GGPLOT 2

Math Equation 1

The equation of the least squares regression line is: \[y = \alpha + \beta x\] This is the model function for a line with y-intercept that is represented by α and slope that is represented by β.

Math Equation 2

The equation of the least squares regression line including an error term is: \[y = \alpha + \beta x + \varepsilon\] Generally speaking, this relationship might not hold true precisely for the population of values for both the dependent and independent variables that are primarily unknown; these unobserved variations from the above equation are referred to as errors. Using this error term ε, we can explain the underlying link between y and x.

R code

#library(ggplot2)

#ggplot(Housing_Price_Data, aes(x = area, y = price)) +
  #geom_point() +
  #geom_smooth(method = "lm", se = FALSE, color = "blue")

THANK YOU!