2026-06-06

Data Preparation

## Rows: 32
## Columns: 13
## $ mpg   <dbl> 21.0, 21.0, 22.8, 21.4, 18.7, 18.1, 14.3, 24.4, 22.8, 19.2, 17.8…
## $ cyl   <dbl> 6, 6, 4, 6, 8, 6, 8, 4, 4, 6, 6, 8, 8, 8, 8, 8, 8, 4, 4, 4, 4, 8…
## $ disp  <dbl> 160.0, 160.0, 108.0, 258.0, 360.0, 225.0, 360.0, 146.7, 140.8, 1…
## $ hp    <dbl> 110, 110, 93, 110, 175, 105, 245, 62, 95, 123, 123, 180, 180, 18…
## $ drat  <dbl> 3.90, 3.90, 3.85, 3.08, 3.15, 2.76, 3.21, 3.69, 3.92, 3.92, 3.92…
## $ wt    <dbl> 2.620, 2.875, 2.320, 3.215, 3.440, 3.460, 3.570, 3.190, 3.150, 3…
## $ qsec  <dbl> 16.46, 17.02, 18.61, 19.44, 17.02, 20.22, 15.84, 20.00, 22.90, 1…
## $ vs    <dbl> 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0…
## $ am    <dbl> 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0…
## $ gear  <dbl> 4, 4, 4, 3, 3, 3, 3, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 4, 4, 4, 3, 3…
## $ carb  <dbl> 4, 4, 1, 1, 2, 1, 4, 2, 2, 4, 4, 3, 3, 3, 4, 4, 4, 1, 2, 1, 1, 2…
## $ car   <chr> "Mazda RX4", "Mazda RX4 Wag", "Datsun 710", "Hornet 4 Drive", "H…
## $ wt_kg <dbl> 1.1884110, 1.3040770, 1.0523334, 1.4582983, 1.5603565, 1.5694283…

MPG vs Engine Displacement

## `geom_smooth()` using formula = 'y ~ x'

MPG vs Weight + Residuals

## `geom_smooth()` using formula = 'y ~ x'

3D Plot: Weight, Horsepower, MPG

Image via R

Least Squares Estimation

\[ S(\beta_0, \beta_1) = \sum_{i=1}^n \left( mpg_i - \beta_0 - \beta_1 \cdot disp_i \right)^2 \]

\[ \hat{\beta}_1 = \frac{\sum_{i=1}^n (disp_i - \bar{disp})(mpg_i - \bar{mpg})} {\sum_{i=1}^n (disp_i - \bar{disp})^2} \]

Example R Output

The First plot shows us that Fuel efficiency is in a reciprocal correlation to the engine size of the car. This is probably beacause The amount of fuel used at a given speed is directly proportional to the engine displacement, and so is reciprocally proportional to fuel efficiency.

The Second plot shows that with respect to weight, the gravitational downforce on the vehicle is directly proportional to the weight of the car.

In the 3d plot we see that small engine cars eg 4cly mazda with less about 1000kg weight have the best fuel efficiency.

Slide with Bullets

  • Bullet 1
  • Bullet 2
  • Bullet 3

Slide with R Output

summary(cars)
##      speed           dist       
##  Min.   : 4.0   Min.   :  2.00  
##  1st Qu.:12.0   1st Qu.: 26.00  
##  Median :15.0   Median : 36.00  
##  Mean   :15.4   Mean   : 42.98  
##  3rd Qu.:19.0   3rd Qu.: 56.00  
##  Max.   :25.0   Max.   :120.00

Slide with Plot

Example Plot

R Markdown

This is an R Markdown presentation. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document.

Slide with Bullets

  • Bullet 1
  • Bullet 2
  • Bullet 3