2026-04-10

What is Simple Linear Regression?

Simple Linear Regression models the relationship between one independent variable (\(x\)) and one dependent variable (\(y\)) using a straight line.

Ask a question? Is it possible to predict a car’s fuel efficiency (miles per gallon) from its weight?

I will use R’s mtcars dataset for this assignment.

The Model

The equation for simple linear regression is:

\[Y = \beta_0 + \beta_1 X\]

  • \(Y\) = response variable (mpg)
  • \(X\) = predictor variable (weight)
  • \(\beta_0\) = intercept
  • \(\beta_1\) = slope

Fitting the Model in R

model = lm(mpg ~ wt, data = mtcars)
summary(model)$coefficients
##              Estimate Std. Error   t value     Pr(>|t|)
## (Intercept) 37.285126   1.877627 19.857575 8.241799e-19
## wt          -5.344472   0.559101 -9.559044 1.293959e-10
  • mtcars stores wt in thousands of pounds, e.g. 3,400 lbs has wt = 3.4.

Interpreting the Output

From the model output:

\[\hat{Y} = 37.29 - 5.34 \cdot X\]

  • The intercept is \(\hat{\beta}_0 = 37.29\)
  • The slope is \(\hat{\beta}_1 = -5.34\)

This means for every 1000 lb increase in weight, mpg decreases by 5.3444.

Scatter Plot with Regression Line

Residual Plot

The residual plot looks mostly random indicating a straight line is a good modeling method.

Interactive 3D Plot

Conclusion

  • Weight is a strong predictor of fuel efficiency.
summary(model)$r.squared
## [1] 0.7528328
  • \(R^2 = 0.7528\), meaning 75% of the variation in mpg is explained by weight.
  • The relationship is negative which indicates heavier cars get worse gas mileage than lighter ones.