October 17, 2026

Introduction

Cars are common means of transportation in our daily life, and the fuel consumption varies among different car models. I suspect that the weight of the car might be an important factor affecting its fuel consumption.

Based on my speculation, I would like to explore the following:

Does the fuel consumption of a car increase as its weight increases?

I will analyze the relationship between car weight and fuel consumption using the linear regression method, and present the results through charts.

About the Dataset

The dataset I used for analysis was the built-in mtcars dataset in R. This dataset contains information about 32 cars, such as car weight, fuel consumption, and engine parameters, etc. This dataset is relatively simple and clear, making it suitable for analysis using linear regression.

I mainly used two variables:

  • mpg: The number of miles that can be traveled per gallon of gasoline. The higher the value, the more fuel-efficient it is.

  • wt: The weight of the car is measured in 1000 pounds.

By comparing these two variables, I will verify my speculation.

What Is Simple Linear Regression?

Linear regression is a common statistical method that can be used to study the relationship between two numerical variables. It represents the trend of one variable changing with respect to another through a straight line.

  • The independent variable is the weight of the car (wt).
  • The dependent variable is fuel efficiency (mpg).

If the regression line slopes downward, it indicates that mpg decreases as the weight of the car increases. However, this only shows that there is a negative correlation between the two variables, and it cannot directly prove that the weight of the car is an important factor affecting fuel consumption.

Mathematical Formula 1

The mathematical model of simple linear regression is:

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

  • \(Y_i\) represents the fuel efficiency of the car.
  • \(X_i\) represents the weight of the car.
  • \(\beta_0\) is the intercept.
  • \(\beta_1\) is the slope.
  • \(\varepsilon_i\) is the error term.

From this, we infer that the regression equation is:

\[ \hat{Y} = b_0 + b_1 X \]

This formula enables us to predict mpg based on the weight of the car. In this formula, the slope can indicate the change in mpg when the car’s weight increases by one unit.

Mathematical Formula 2

Linear regression usually uses the least squares method to find the appropriate straight line, so as to minimize the error between the actual values and the predicted values.

The formula is as follows:

\[ SSE = \sum_{i=1}^{n}(Y_i-\hat{Y}_i)^2 \]

Among them, \(Y_i\) represents the actual value, and \(\hat{Y}_i\) represents the predicted value.

Furthermore, we can also use \(R^2\) to evaluate the model.

\[ R^2 = 1 - \frac{\sum_{i=1}^{n}(Y_i-\hat{Y}_i)^2} {\sum_{i=1}^{n}(Y_i-\bar{Y})^2} \]

\(R^2\) can indicate how much of the data variation is explained by the model. The higher the \(R^2\) value, the greater the degree of explanation of the model for the data variation.

R Code

R Code enables us to quickly establish regression models.

The following code uses the lm() function to analyze the relationship between car weight and mpg.

data(mtcars)

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

summary(model)

coef(model)

Here, mpg ~ wt indicates that the weight of the car is used to predict fuel efficiency.

The summary() function can be used to view the statistical results of the model.

The coef() function can be employed to extract the intercept and slope in the regression equation.

Based on these results, we can further analyze the relationship between the two variables.

Regression Results

Measurement Value
(Intercept) Intercept 37.285
wt Slope -5.344
R-squared 0.753

Based on the calculation results, the obtained regression equation is:

\[ \widehat{mpg} = 37.285 - 5.344(wt) \]

We can observe that the slope in the formula is a negative value of 5.34. This indicates that mpg decreases as the weight of the car increases, and for every 1000 pounds increase in car weight, the average mpg decreases by approximately 5.34.

Additionally, \(R^2\) is approximately 0.753, suggesting that car weight can explain about 75.3% of the mpg variations in this dataset.

From this, it is clear that this result indeed demonstrates a direct relationship between the weight of a car and its fuel efficiency.

Visualization 1

From the scatter plot, it can be seen that as the weight of the car increases, mpg decreases. The yellow regression line slopes downward significantly, indicating that heavier cars generally consume more fuel than lighter cars. Although cars do not perfectly follow this pattern, the overall trend is in line with it.

Visualization 2

This graph compares the actual mpg of the cars with the predicted mpg by the model. If a point is closer to the yellow line, it indicates that the model’s prediction for this car is more accurate.

From the graph, it can be seen that the distance of the points from the line is unstable; some are close and some are far. This suggests that the weight of the car does indeed help us predict the amount of fuel consumption, but the model’s prediction is not completely accurate.

Therefore, I believe there are definitely many other factors affecting fuel efficiency. It may be related to the car’s engine, shape and structure, and various other factors.

Interactive Visualization

This graph is quite similar to the previous scatter plot. Its advantage is that it can be predicted more selectively through interaction. When the mouse hovers over a certain point, the weight and mpg of the corresponding car can be seen. This makes it easier to view the data of each car. Interactive charts are more convenient than ordinary charts. We can see more specific information through interaction.

Conclusion

Through this research, I discovered a relatively clear negative correlation between the weight of a car and its fuel efficiency. When the weight increases, the fuel consumption also increases. It can be basically confirmed that the weight of a car is an important factor affecting its fuel consumption.

From the regression model and the charts, the following conclusions can be drawn:

  • Generally, heavier cars have lower mpg.
  • The weight of a car can explain approximately 75% of the variation in mpg.
  • Linear regression can help us intuitively understand the relationship between the two variables.
  • The model still has errors and is not yet perfect, and cannot accurately predict each car.

Through this assignment, I learned to use R for regression analysis, as well as to use charts to present and interpret data. ## References

Data source:

  • R built-in dataset: mtcars
  • Motor Trend Car Road Tests The data includes information about 32 cars.

The tools used:

  • R: Statistical analysis
  • ggplot2: Data visualization
  • Plotly: Interactive charts
  • R Markdown: Creating ioslides presentations

Statistical methods:

  • Simple Linear Regression
  • Ordinary Least Squares

All the data used in this study were from the publicly available datasets provided by R, and no other external data were employed.