2026-09-11

What is Simple Linear Regression ?

Simple linear regression is a statistical method used to model the linear relationship between two continuous variables.

  • Predictor variable: The variable used to help predict another variable.
  • Response variable: The variable we are trying to predict.

It estimates this relationship by fitting a straight line to observed data points, allowing for the prediction of the dependent variable’s value based on the independent variable.

The Regression Equation

Simple linear regression represents the relationship between two variables using the equation:

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

\[ \hat{y} = b_0 + b_1x \]

where:

  • \(y\) = Observed value of the response variable
  • \(x\) = Value of the predictor variable
  • \(\beta_0\) = Intercept, the expected value of \(y\) when \(x = 0\)
  • \(\beta_1\) = Slope, the expected change in \(y\) for a one-unit increase in \(x\)
  • \(\varepsilon\) = Random error, representing variation in \(y\) not explained by \(x\)

The goal is to find the line that best represents the relationship between \(x\) and \(y\).

Slope, Intercept, and Residuals

These three important parts help us understand a simple linear regression model:

  • Slope (\(\beta_1\)): Describes how much the expected value of \(y\) changes when \(x\) increases by one unit.
  • Intercept (\(\beta_0\)): Represents the expected value of \(y\) when \(x = 0\).
  • Residual: The difference between an observed value and the value predicted by the fitted regression line.

\[ e_i = y_i - \hat{y}_i \]

A small residual means the predicted value is close to the observed value.

Example: Cars and Fuel Economy

In order to demonstrate linear regression, we’ll use the built-in ‘mtcars’ dataset.

The question we’ll be asking: Can a car’s weight help predict its fuel economy ?

  • Predictor (\(x\)): ‘wt’ - Car weight in thousands of pounds
  • Response (\(y\)): ‘mpg’ - Fuel economy measured in miles per gallon
  • Each observation represents a different car.

We’ll use simple linear regression to examine how changes in car weight are related to changes in fuel economy.

Exploring the Relationship

Before we build the regression model, let’s visualize the relationship between car weight and fuel economy.

Building the Regression Model in R

We’ll fit a simple linear regression model using R’s ‘lm()’ function.

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

coef(model)
## (Intercept)          wt 
##   37.285126   -5.344472

The model uses: - ‘mpg’ as the response variable - ‘wt’ as the predictor variable - ‘lm()’ to estimate the intercept and slope

Visualizing the Regression Line

The fitted regression line shows the predicted relationship between car weight and fuel economy.

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

The downward slope tells us that heavier cars tend to have lower predicted fuel economy.

Interactive Regression Plot

Plotly allows us to explore the relationship between car weight and fuel economy interactively.

The interactive plot allows us to examine individual cars and their weight and MPG values.

Key Takeaways

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

  • The slope shows how the predicted response changes as the predictor increases.

  • Residuals measure the difference between observed and predicted values.

  • In our ‘mtcars’ example, heavier cars generally have lower fuel economy.

  • Regression can be used to describe relationships and make predictions, but a relationship doesn’t necessarily imply causation.