2026-02-08

Slide 1 — Introduction

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.

Slide 2 — Model Definition (Math)

The simple linear regression model is:

\[ Y = \beta_0 + \beta_1 X + \varepsilon \]

Where:

  • \(\beta_0\) is the intercept
  • \(\beta_1\) is the slope
  • \(\varepsilon\) is the random error

Slide 3 — Estimation (Math)

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} \]

Slide 4 — Dataset and Setup

We use the built-in dataset mtcars.

  • Response variable: mpg (miles per gallon)
  • Predictor variable: wt (weight in 1000 lbs)
  • Extra variable for 3D plot: hp (horsepower)

Slide 5 — Scatterplot (ggplot #1)

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()

Slide 6 — Regression Line (ggplot #2)

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'

Slide 8 — Plotly 3D Interactive Plot

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))