Introduction

In this presentation, we’ll explore the relationship between weight and fuel efficiency. The goal is to see how fuel efficiency changes depending on weight.

Dataset & variables

In this presentation, I used mtcars dataset which contains information about 32 automobiles.

The two variables:

  • wt: weight of the car (in 1000 pounds)
  • mpg: fuel efficiency (miles per gallon)

We want to see whether heavier cars tend to have lower fuel efficiency.

What is Simple Linear Regression?

Simple linear regression models the relationship between one explanatory variable \(x\) and one response variable \(y\).

In this example:

  • \(x = wt\)
  • \(y = mpg\)

Regression Equation

The general form of a simple linear regression model is

\[ y = \beta_0 + \beta_1 x + \epsilon \]

For our example, the estimated regression line can be written as

\[ \hat{y} = \beta_0 + \beta_1 x \]

For this presentation,

\[ \widehat{mpg} = \beta_0 + \beta_1(wt) \]

The slope tells us how much fuel efficiency changes when car weight increases by 1 unit.

Scatter Plot (ggplot)

Regression Line (ggplot)

Interactive Plot (plotly)

R Code Example

Below is an example of R code used to create the regression plot.

ggplot(mtcars, aes(x = wt, y = mpg)) +
  geom_point(size = 3) +
  geom_smooth(method = "lm", se = TRUE) +
  labs(
    title = "Regression Line for Weight and Fuel Efficiency",
    x = "Weight (wt)",
    y = "Miles per Gallon (mpg)"
  )

Fitted Model in R

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

The regression output shows the estimated slope and intercept. A negative slope suggests that heavier cars tend to have lower fuel efficiency.

Conclusion

This presentation used simple linear regression to examine the relationship between car weight and fuel efficiency.

Two main points for today:

  • Car weight and fuel efficiency have a negative relationship.
  • As wt increases, mpg tends to decrease.