2026-02-09

Simple Linear Regression

The study of linear regressions between the values of X and Y variables is called Simple Linear Regression. The variable, out of the two, which is known is called the independent variable and the variable that is to be predicated is called dependent variable.

What the regression line looks like

Regression of Y on X:

Ŷ=a+bX

  • a is the intercept
  • b is the slope

Connecting slope with correlation

bᵧₓ = r (sᵧ⁄ sₓ)

  • r is the correlation between X and Y
  • sₓ is the standard deviation of X
  • sᵧ is the standard deviation of Y

Weight vs Miles per gallon

We’ll use the mtcars dataset. This scatter plot shows how miles per gallon changes with car weight.

## (Intercept)          wt 
##   37.285126   -5.344472

Actual vs predicted miles per gallon

This plot compares the mpg values predicted by the regression line to the actual mpg values. Points closer to the line indicate better predictions.

Code

The code used for the previous graph

cars$pred <- predict(fit)

ggplot(cars, aes(x = pred, y = mpg)) +
  geom_point() +
  
  geom_smooth(method = "lm", se = FALSE) +
  labs(title = "Actual mpg vs Predicted mpg", x = "Predicted mpg",
       y = "Actual mpg")

Interactive