Simple Linear Regression is a model that shows a relationship between two variables.
Examples:
- Predicting the house prices based on its area.
- Estimating salary based on the years of experience.
- Predicting the yield of crop based on the rainfall.
2025-10-18
Simple Linear Regression is a model that shows a relationship between two variables.
\[Y = \beta_0 + \beta_1 X + \epsilon\] Where:
The least Square Method is used to estimate the parameters \(\beta_0\) and \(\beta_1\) by minimizing the sum of the squares of the vertical deviation. Estimated Parameters:
\[\hat{\beta}_1 = \frac{\sum_{i=1}^{n}(X_i - \bar{X})(Y_i - \bar{Y})}{\sum_{i=1}^{n}(X_i - \bar{X})^2}\]
\[\hat{\beta}_0 = \bar{Y} - \hat{\beta}_1\bar{X}\]
We will be looking at the cars data for this. We will try to predict Distance using the Speed of car.
The following is the summary and first few rows of the data we are looking at:
speed dist Min. : 4.0 Min. : 2.00 1st Qu.:12.0 1st Qu.: 26.00 Median :15.0 Median : 36.00 Mean :15.4 Mean : 42.98 3rd Qu.:19.0 3rd Qu.: 56.00 Max. :25.0 Max. :120.00
speed dist 1 4 2 2 4 10 3 7 4 4 7 22 5 8 16
lm(dist ~ speed, data = cars)
Call:
lm(formula = dist ~ speed, data = cars)
Coefficients:
(Intercept) speed
-17.579 3.932
From this we can see that the equation we get is:
\[ dist = -17.579 + (3.932)*speed \]
This creates a scatterplot with a fitted linear regression line.
ggplot(cars,
aes(x=speed, y=dist)) +
geom_smooth(method = 'lm') +
geom_point() +
labs(title = "Simple Linear Regression of Dist & Speed",
x = "Speed", y = "Distance")