2026-11-02

Simple Linear Regression

  • It shows the relationship between two continuous variables.
  • One variable, \(x\), is known as the predictor or independent variable.The other variable, \(y\), is known as the response, outcome, or dependent variable.
  • The equation is :\(y = \beta_0 + \beta_1 \cdot x + \varepsilon\)

Fitted Line

  • ‘lm()’ is used in R to find the best straight line through the data from ‘mtcars’

  • \(x\) is the weight of the car and \(\hat{y}\) is the predicted miles per gallon

  • The equation is : \[\hat{y} = 37.29 -5.34 x\]

Weight vs MPG

R code

ggplot(mtcars, aes(x = wt, y = mpg)) + 
  geom_point() + 
  geom_smooth(method = "lm") + 
  labs(x = "Weight", y = "MPG")

Horsepower vs MPG

Residual Plot

Plotly Plot

Conclusion

  • Cars that are heavier will use up more fuel and will get fewer miles per gallon.

  • Real world outcomes often depend on many other factors as well , so more variables can make predictions better.

  • A strong relationship between two variables does not always mean one causes the other.