2026-10-18

What is Simple Linear Regression?

Simple linear regression is a statistical method used to study the relationship between two quantitative variables.

  • Independent variable (x): the variable used to make a prediction
  • Dependent variable (y): the variable we want to predict
  • The goal is to find a straight line that best describes the relationship between x and y

For example, we can study whether a car’s weight can be used to predict its fuel efficiency (MPG).

The Regression Equation

The equation for simple linear regression is:

\[y = \beta_0 + \beta_1x + \epsilon\]

Where:

  • \(y\) = dependent variable
  • \(x\) = independent variable
  • \(\beta_0\) = intercept
  • \(\beta_1\) = slope
  • \(\epsilon\) = random error

The slope tells us how much we expect y to change when x increases by one unit.

Example: The mtcars Dataset

For my example, I’ll will use the built-in mtcars dataset in R.

Now let’s examine the relationship between:

  • wt: car weight (in 1,000 lbs)
  • mpg: fuel efficiency in miles per gallon

Our question is:

Can a car’s weight be used to predict its fuel efficiency?

We expect heavier cars to generally have lower MPG.

Weight vs. Fuel Efficiency

The scatter plot below shows the relationship between car weight and fuel efficiency.

Linear Regression Line

A regression line helps us visualize the relationship between weight and fuel efficiency.

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

Interactive Regression Plot

This interactive plot allows us to explore the relationship between weight and MPG.

Interpreting the Regression

For our example, the estimated regression equation has the form:

\[\widehat{MPG} = \beta_0 + \beta_1(Weight)\]

The slope \(\beta_1\) describes how MPG changes as car weight increases.

  • If \(\beta_1 > 0\), MPG increases as weight increases.
  • If \(\beta_1 < 0\), MPG decreases as weight increases.

=Based on our plots, we expect \(\beta_1\) to be negative because heavier cars tend to have lower MPG.

Creating the Regression Model in R

We can create a simple linear regression model using the lm() function in R.

model <- lm(mpg ~ wt, data = mtcars)
model
## 
## Call:
## lm(formula = mpg ~ wt, data = mtcars)
## 
## Coefficients:
## (Intercept)           wt  
##      37.285       -5.344

Results and Conclusion

Our fitted regression equation is:

\[\widehat{MPG} = 37.285 - 5.344(Weight)\]

The slope is negative, which supports what we observed in our graphs.

  • For every additional 1,000 lbs of weight, predicted MPG decreases by about 5.344 MPG.
  • Heavier cars generally have lower fuel efficiency.
  • Simple linear regression allows us to describe and predict the relationship between two quantitative variables.