2026-11-01

What is Simple Linear Regression?

Simple linear regression is a statistical measure used to examine the relationship between two numerical values.

  • Independent variable (X): : Vehicle weight
  • Dependent variable (Y): Fuel efficiency (MPG)
  • Goal: Determine whether vehicle weight can predict fuel efficiency.

For this analysis, we will use built-in mtcars dataset, which contains information about 32 vehicles.

The Linear Regression Equation

Simple linear regression uses the following equation to predict an outcome:

\[ \hat{Y} = \beta_0 + \beta_1 X \]

Where:

  • Y-hat: Predicted value of the dependent variable
  • Beta 0: Intercept, or predicted Y when X = 0
  • Beta 1: Slope, or change in predicted Y for each one-unit increase in X
  • X: Independent variable

In our analysis, we will use vehicle weight

Exploring the mtcars Dataset

The mtcars dataset contains information about 32 vehicles.

We will focus on two variables:

  • wt: Vehicle weight (in thousands of pounds)
  • mpg: Fuel efficiency (miles per gallon)

Our goal is to determine whether heavier vehicles tend to have lower fuel efficiency.

##                      wt  mpg
## Mazda RX4         2.620 21.0
## Mazda RX4 Wag     2.875 21.0
## Datsun 710        2.320 22.8
## Hornet 4 Drive    3.215 21.4
## Hornet Sportabout 3.440 18.7
## Valiant           3.460 18.1

Vehicle Weight vs. Fuel Efficiency

This scatterplot illustrates the relationship between vehicle weight and fuel efficiency.

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

Simple Linear Regression Results

The fitted regression equation is: \[\widehat{MPG} = 37.2851 - 5.3445(wt)\] Where \(wt\) represents vehicle weight in thousands of pounds.

## 
## Call:
## lm(formula = mpg ~ wt, data = mtcars)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -4.5432 -2.3647 -0.1252  1.4096  6.8727 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  37.2851     1.8776  19.858  < 2e-16 ***
## wt           -5.3445     0.5591  -9.559 1.29e-10 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 3.046 on 30 degrees of freedom
## Multiple R-squared:  0.7528, Adjusted R-squared:  0.7446 
## F-statistic: 91.38 on 1 and 30 DF,  p-value: 1.294e-10

Distribution of Veihcle Weights

This histogram illustrates the distribution of vehicle weights among the 32 vehicles in the mtcars dataset. Vehicle weight is measured in thousands of pounds.

Interpreting the Regression Results

The regression analysis identified a strong negative relationship between vehicle weight and fuel efficiency.

  • Regression equation: MPG = 37.2851 - 5.3445(WT)

  • Slope: Every additional 1,000 pounds of vehicle weight is associated with an estimated 5.34 MPG decrese.

  • R-squared: Vehicle weight explains approximately 75.28% of the variation in MPG.

  • P-value: 1.29 x 10^(-10), indicating a statistically significant relationship.

Conclusion: Heavier vehicles gnerally have lower fuel efficiency. Vehicle weight is a strong predictor of MPG in the mtcars dataset.

Interactive Regression Plot

This interactive scatterplot shows the relationship between vehicle weight and fuel efficiency.

Conclusion

Our simple linear regression analysis found a strong negative relationship between vehicle weight and fuel efficiency.

  • Regression equation: MPG = 37.285 -5.344(wt)
  • Slope: For every additional 1,000 pounds of vehicle weight, predicted fuel efficiency decreases by approximately 5.34 MPG.
  • R-squared: 0.7528, meaning vehicle weight explains approximately 75.3% of the variation in fuel efficiency.
  • P-value: 1.29e-10, indicating a statistically significant relationship.

Overall, heavier vehicles tend to have lower fuel efficiency. Vehicle weight is a strong predictor of the MPG in the mtcars dataset.

R Code: Simple Linear Regression

The following R code creates our regression model:

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