2026-06-08

Introduction

Simple Linear Regression is a statistical method used to study the relationship between one independent and one dependent variable.

In this presentation, this method will be used to analyze the mtcars dataset to analyze the weight of a vehicle affects its fuel efficiency

The Dataset

For this presentation, we use the built-in R dataset mtcars.

This dataset has infromation about various car models and their corresponding characteristics.

The two variables we will focus on are:

  • wt = vehicle weight (in thousands of pounds)
  • mpg = miles per gallon (fuel efficiency)

These variables will help us investigate whether heavier cars tend to have lower fuel efficiency.

What is Linear Regression?

Linear regression is used to describe the relationship between an independent variable and a dependent variable.

In this case our variables would be the following:

  • Independent variable (X): vehicle weight (wt)
  • Dependent variable (Y): fuel efficiency (mpg)

In this case, the objective of using linear regression would allow us to find the relationship between the vehicle weight and the fuel efficiency allowing us to make accurate predictions.

Regression Equation

The simple linear regression model is:

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

Where:

  • \(Y\) = dependent variable (mpg)
  • \(X\) = independent variable (wt)
  • \(\beta_0\) = intercept
  • \(\beta_1\) = slope
  • \(\varepsilon\) = random error

Estimating the Slope

The slope can be calculated using the following formula:

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

This formula measures how much the dependent variable changes, on average, when the independent variable changes.

In our scenario, it shows how fuel efficiency changes as vehicle weight changes.

Weight vs Fuel Efficiency

The following scatter plot shows the relationship between vehicle weight and fuel efficiency.

Adding a Regression Line

The regression line helps summarize the overall relationship between vehicle weight and fuel efficiency.

## Interactive Plot

The following interactive plot allows us to explore the relationship between vehicle weight and fuel efficiency.

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

R Code Example

The following code creates a simple linear regression model using the mtcars dataset.

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

summary(model)

Conclusion

Based on the analysis of the mtcars dataset, we found a negative relationship between vehicle weight and fuel efficiency.

Findings:

  • Heavier vehicles tend to have lower MPG.
  • The scatter plots show a clear downward trend.
  • The regression line summarizes this relationship.
  • Linear regression is a useful tool for analyzing and predicting relationships between variables.