2026-09-15

What Is Simple Linear Regression?

Simple linear regression examines the relationship between one predictor variable and one response variable.

For this example, we will study how vehicle weight affects fuel economy.

The Regression Model

A simple linear regression model is:

\[ Y_i = \beta_0 + \beta_1X_i + \epsilon_i \]

Where:

  • \(\beta_0\) = intercept
  • \(\beta_1\) = slope
  • \(\epsilon_i\) = random error

The Data

We will use the built-in R dataset mtcars.

Important variables:

  • mpg = miles per gallon
  • wt = vehicle weight in thousands of pounds
  • hp = horsepower
##                    mpg    wt  hp
## Mazda RX4         21.0 2.620 110
## Mazda RX4 Wag     21.0 2.875 110
## Datsun 710        22.8 2.320  93
## Hornet 4 Drive    21.4 3.215 110
## Hornet Sportabout 18.7 3.440 175
## Valiant           18.1 3.460 105

Weight vs. Fuel Economy

## `geom_smooth()` using formula = 'y ~ x'

Heavier vehicles generally have lower fuel economy.

Regression Equation

The estimated regression equation is:

\[ \hat{Y} = b_0 + b_1X \]

## (Intercept)          wt 
##   37.285126   -5.344472

The slope shows how MPG changes as vehicle weight increases.

Model Fit

The coefficient of determination is:

\[ R^2 = 1 - \frac{SS_{res}}{SS_{tot}} \]

## [1] 0.7528328

A higher \(R^2\) means the model explains more of the variation in MPG.

Residual Plot

Residuals help determine whether the linear model is reasonable.

Interactive 3D Plot

This interactive graph compares weight, horsepower, and fuel economy.

R Code Example

library(ggplot2)

model <- lm(mpg ~ wt, data = mtcars)

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

Example Prediction

Suppose a vehicle weighs 3,000 pounds.

Since wt is measured in thousands:

\[ X = 3 \]

##        1 
## 21.25171

The model predicts the expected MPG for a vehicle weighing 3,000 pounds.

Key Takeaways

  • Linear regression studies relationships between quantitative variables.
  • The slope measures how the response changes.
  • \(R^2\) measures how well the model explains the data.
  • Residuals help evaluate the model.
  • Vehicle weight is strongly related to fuel economy.