2026-03-05

Slide2: Intro - MPG Analysis

In this ppt, we will be calculating the relationship between a car’s weight and the fuel efficiency using the built-in mtcars dataset as we used in class .

  • Objective: To visualize how weight affects MPG.
  • Tool: We will use plotting libraries as asked in the requirements: ggplot2 and plotly.
  • Variables:
    • \(Y\): Miles per Gallon (mpg)
    • \(X\): Weight (1000 lbs)

Slide3: Simple Linear Regression Model

To calculate the relationship, we can use the following statistical model -

\[Y_i = \beta_0 + \beta_1 X_i + \epsilon_i\]

where: * \(Y_i\) is the response variable (MPG). * \(\beta_0\) is the y-intercept. * \(\beta_1\) is the slope coefficient for weight. * \(\epsilon_i\) is the random error, where \(\epsilon_i \sim N(0, \sigma^2)\).

Slide4: Analysis of model -

Slide 5 - R Code

model <- lm(mpg ~ wt, data = mtcars)
summary(model)
## 
## Call:
## lm(formula = mpg ~ wt, data = mtcars)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -4.5432 -2.3647 -0.1252  1.4096  6.8727 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  37.2851     1.8776  19.858  < 2e-16 ***
## wt           -5.3445     0.5591  -9.559 1.29e-10 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 3.046 on 30 degrees of freedom
## Multiple R-squared:  0.7528, Adjusted R-squared:  0.7446 
## F-statistic: 91.38 on 1 and 30 DF,  p-value: 1.294e-10

Slide 6

##We can calculate the estimated value \(\hat{Y}\) for specific weight:

\[\hat{Y} = \hat{\beta}_0 + \hat{\beta}_1 x^*\]

The \(95\%\) CI for mean is:

\[\hat{Y} \pm t_{\alpha/2, n-2} \cdot SE(\hat{Y})\]

Slide 7 Analysis

Slide 8 Plotting relationships

library(plotly)
plot_ly(mtcars, x = ~wt, y = ~hp, z = ~mpg, type = "scatter3d", mode = "markers",
        marker = list(color = ~mpg, colorscale = 'Viridis', showscale = TRUE)) %>%
  layout(title = "3D Analysis of Car Performance")