2026-02-07

Overview

Analysis of Simple Linear Regression

We’ll investigate the connection between vehicle weight and fuel economy.Making use of the traditional mtcars dataset
Questions we will respond to:
-What impact does weight have on miles per gallon?
-To what extent does our model match the data?
-What can we anticipate in terms of fuel effiency?

The Data

##                    mpg    wt  hp cyl
## Mazda RX4         21.0 2.620 110   6
## Mazda RX4 Wag     21.0 2.875 110   6
## Datsun 710        22.8 2.320  93   4
## Hornet 4 Drive    21.4 3.215 110   6
## Hornet Sportabout 18.7 3.440 175   8
## Valiant           18.1 3.460 105   6
## Duster 360        14.3 3.570 245   8
## Merc 240D         24.4 3.190  62   4

The mtcars dataset contains 32 observations with measurements on fuel efficiency (mpg), weight (wt), horsepower (hp), and cylinders (cyl).

Simple Linear Regression Model

The simple linear regression model is expressed as:

\[Y_i = \beta_0 + \beta_1 X_i + \epsilon_i\]

where:

  • \(Y_i\) is the response variable (mpg)
  • \(X_i\) is the predictor variable (weight)
  • \(\beta_0\) is the intercept
  • \(\beta_1\) is the slope
  • \(\epsilon_i \sim N(0, \sigma^2)\) are independent error terms

Scatter Plot with Regression Line

Model Coefficients

Our fitted regression equation is:

\[\hat{Y} = 37.29 - 5.34 \times \text{Weight}\]

## # A tibble: 2 × 5
##   term        estimate std.error statistic  p.value
##   <chr>          <dbl>     <dbl>     <dbl>    <dbl>
## 1 (Intercept)    37.3      1.88      19.9  8.24e-19
## 2 wt             -5.34     0.559     -9.56 1.29e-10

For every 1000 lb increase in weight, fuel efficiency decreases by approximately 5.34 mpg.

The model explains 75.3% of the variance in mpg (\(R^2\) = 0.753).

Residual Plot

Interactive Visualization

R Code Example

Here’s the code used to create the regression model:

data(mtcars)

# Fit simple linear regression
fit <- lm(mpg ~ wt, data = mtcars)

# Add fitted values and residuals
df <- mtcars %>%
  mutate(
    mpg_hat = fitted(fit),
    resid = resid(fit)
  )

summary(fit)

Wrap-up

Important Results:

Weight and fuel efficiency have a strong inverse relationship.The model is statistically significant (p < 0.001). Approximately 75% of the variation in mpg can be explained by weight alone. Expect to lose about 5 mpg for every 1000 lbs.

Uses: Automotive engineers can improve vehicle design for increased fuel efficiency with the aid of this kind of analysis.