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.
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.
In this presentation, I used mtcars dataset which contains information about 32 automobiles.
The two variables:
We want to see whether heavier cars tend to have lower fuel efficiency.
Simple linear regression models the relationship between one explanatory variable \(x\) and one response variable \(y\).
In this example:
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.
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)"
)
## ## 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.
This presentation used simple linear regression to examine the relationship between car weight and fuel efficiency.
Two main points for today: