Fuel efficiency is an important factor when comparing vehicles.
Our solution: An interactive application that estimates fuel efficiency from user-selected vehicle characteristics.
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.
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.
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