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

The Problem

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

The Model

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.

How the App Works

  1. Adjust weight (slider), cylinders (dropdown),horsepower (numeric input)
  2. Click “Calculate Prediction”
  3. App displays predicted mpg + 95% confidence interval
  4. Regression plots update automatically

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 & Code