2026-04-13

What is Simple Linear Regression?

Simple linear regression studies the relationship between:

  • one predictor variable \(x\)
  • one response variable \(y\)

\[ y = \beta_0 + \beta_1 x + \varepsilon \]

Why is it Useful?

  • Helps understand the relationship between two variables
  • Allows prediction of one variable using another
  • Gives a simple mathematical model for data
  • Example: predicting miles per gallon using car weight

Regression Formula

\[ \hat{y} = b_0 + b_1 x \]

\[ b_1 = \frac{\sum (x_i - \bar{x})(y_i - \bar{y})}{\sum (x_i - \bar{x})^2} \]

\[ b_0 = \bar{y} - b_1 \bar{x} \]

Assumptions

  • Linear relationship
  • Independent observations
  • Constant variance of errors
  • Errors are approximately normal

Example Dataset

We use the built-in mtcars dataset.

  • wt = car weight
  • mpg = miles per gallon
mpg wt
Mazda RX4 21.0 2.62
Mazda RX4 Wag 21.0 2.88
Datsun 710 22.8 2.32
Hornet 4 Drive 21.4 3.21
Hornet Sportabout 18.7 3.44
Valiant 18.1 3.46

Scatter Plot

Regression Line

Interactive Plot

Model Results

From the fitted model:

  • Intercept \(b_0 \approx 37.29\)
  • Slope \(b_1 \approx -5.34\)
  • \(R^2 \approx 0.753\)

Weight explains about 75.3% of the variation in MPG, and the relationship is negative.

Interpreting the Slope

\[ \widehat{mpg} = 37.29 - 5.34(wt) \]

Interpretation:

  • For every 1-unit increase in car weight, predicted MPG decreases by about 5.34 on average

R Code Used

We fit a linear model and visualize the relationship.

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

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

Conclusion

  • Simple linear regression models the relationship between two quantitative variables
  • In this example, weight and MPG have a negative relationship
  • Regression is useful for both prediction and interpretation