Rishabh Sharda
October 27, 2026
Estimate vehicle MPG, fuel consumption, and annual fuel cost — interactively.
Built using R Shiny, a regression model, and the built-in mtcars dataset.
Five inputs → an instant, interpretable fuel-cost estimate.
The prediction uses weight, horsepower, and transmission.
cars <- mtcars
cars$transmission <- factor(cars$am, levels=c(0,1),
labels=c("Automatic", "Manual"))
fit <- lm(mpg ~ wt + hp + transmission, data=cars)
example_car <- data.frame(wt=3, hp=120,
transmission=factor("Automatic", levels=levels(cars$transmission)))
example_mpg <- as.numeric(predict(fit, newdata=example_car))
round(c(MPG=example_mpg, Annual_cost_USD=12000/example_mpg*3.50), 2)
MPG Annual_cost_USD
20.87 2012.49
The code above executes when the presentation renders.
The model uses all 32 historical cars in R's built-in mtcars dataset.
Try the Shiny application using the submitted Shiny URL.
Note: Based on a small historical dataset; for learning, not buying decisions.