1. The Problem

Understanding Car Fuel Efficiency

Fuel efficiency is an important factor when comparing vehicles.

  • Higher miles per gallon (MPG) generally means less fuel is required to travel the same distance.
  • Weight, horsepower, and engine cylinders can help explain differences in fuel efficiency.
  • Comparing these characteristics can help users understand how vehicle specifications relate to fuel consumption.

Our solution: An interactive application that estimates fuel efficiency from user-selected vehicle characteristics.


2. Data and Methodology

Dataset and Regression Model

The application uses R’s built-in mtcars dataset.

The model uses: - Weight (wt) - Horsepower (hp) - Number of cylinders (cyl)

data(mtcars)

model <- lm(
  mpg ~ wt + hp + factor(cyl),
  data = mtcars
)

round(coef(model), 2)
##  (Intercept)           wt           hp factor(cyl)6 factor(cyl)8 
##        35.85        -3.18        -0.02        -3.36        -3.19

The regression model estimates MPG using the relationship between these vehicle characteristics and observed fuel efficiency.


3. Demonstration and Results

Exploring Fuel Efficiency

This chart compares average observed MPG for cars with different numbers of cylinders.

avg_mpg <- tapply(
  mtcars$mpg,
  mtcars$cyl,
  mean
)

barplot(
  avg_mpg[c("4", "6", "8")],
  names.arg = c("4 cylinders", "6 cylinders", "8 cylinders"),
  col = "skyblue",
  main = "Average MPG by Number of Cylinders",
  ylab = "Miles Per Gallon (MPG)"
)

In the Shiny application, users adjust weight, horsepower, and cylinders to obtain a new estimated MPG.


4. Conclusion and Limitations

Key Takeaways

  • The app provides interactive fuel-efficiency estimates.
  • Linear regression connects vehicle characteristics with MPG.
  • The chart compares average fuel efficiency across cylinder groups.

Limitations: The mtcars dataset is small and historical. Predictions may not represent modern vehicles or real-world driving conditions.

Live application: https://vanditasingh.shinyapps.io/shiny-predictor/

GitHub source code: https://github.com/vandita-14-git/Shiny-Predictor/tree/main