What is Simple Linear Regression?
Simple linear regression models the relationship between:
- Response variable \(Y\)
- Predictor variable \(X\)
It is widely used in engineering, data science, and applied statistics.
2026-02-08
Simple linear regression models the relationship between:
It is widely used in engineering, data science, and applied statistics.
The simple linear regression model is:
\[ Y = \beta_0 + \beta_1 X + \varepsilon \]
Where:
The estimated regression equation is:
\[ \hat{Y} = \hat{\beta}_0 + \hat{\beta}_1 X \]
The slope estimator is:
\[ \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} \]
We use the built-in dataset mtcars.
mpg (miles per gallon)wt (weight in 1000 lbs)hp (horsepower)library(ggplot2)
ggplot(mtcars, aes(x = wt, y = mpg)) +
geom_point(size = 3) +
labs(
title = "MPG vs Weight",
x = "Weight (1000 lbs)",
y = "Miles per Gallon (MPG)"
) +
theme_minimal()
library(ggplot2)
ggplot(mtcars, aes(x = wt, y = mpg)) +
geom_point(size = 3) +
geom_smooth(method = "lm", se = TRUE) +
labs(
title = "Regression Fit: mpg ~ wt",
x = "Weight (1000 lbs)",
y = "Miles per Gallon (MPG)"
) +
theme_minimal()
## `geom_smooth()` using formula = 'y ~ x'
library(plotly)
## ## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2': ## ## last_plot
## The following object is masked from 'package:stats': ## ## filter
## The following object is masked from 'package:graphics': ## ## layout
plot_ly( data = mtcars, x = ~wt, y = ~hp, z = ~mpg, type = "scatter3d", mode = "markers", marker = list(size = 4))