Predict a car’s fuel consumption (mpg) based on: - Weight (wt) - in 1000 lbs - Cylinders (cyl) - 4, 6 or 8 - Horsepower (hp) Dataset used: mtcars (R base, 32 car models)
data(mtcars) dim(mtcars)
## [1] 32 11
July 20 2026
1 - USE THE (→) ON YOUR KEYBOARD TO ADVANCE OR CLICK (👆) TO THE RIGHT OUTSIDE THE SLIDE TO ADVANCE
2 - USE THE (←) ON YOUR KEYBOARD TO GO BACK OR CLICK (👆) TO THE LEFT OUTSIDE THE SLIDE TO GO BACK
Predict a car’s fuel consumption (mpg) based on: - Weight (wt) - in 1000 lbs - Cylinders (cyl) - 4, 6 or 8 - Horsepower (hp) Dataset used: mtcars (R base, 32 car models)
data(mtcars) dim(mtcars)
## [1] 32 11
Multiple linear regression model:
model <- lm(mpg ~ wt + cyl + hp, data = mtcars) summary(model)$r.squared
## [1] 0.84315
The model explains ~84% of the variability in fuel consumption.
Example prediction for a 3000 lbs, 6-cyl, 150 hp
predict(model, data.frame(wt = 3.0, cyl = 6, hp = 150))
## 1 ## 20.89545
Live App: CLICK (👇)
https://019f807a-a619-871f-6617-5aed6af9e909.share.connect.posit.cloud/
Code: CLICK (👇)
https://github.com/fabilenenogueiraprado/Fuel-Consumption-Predictor-Shiny
Built with: R, Shiny, mtcars dataset
Slides created with: Quarto Presentation
Note: “R Presentations” (in old versions of RStudio) have been replaced by the more modern R Markdown and Quarto presentation tools.