2.1 Main Regression
I’m estimating a model to predict fuel efficiency (mpg) using weight, horsepower, and displacement:
\[mpg_i = \beta_0 + \beta_1 \cdot wt_i + \beta_2 \cdot hp_i + \beta_3 \cdot disp_i + \epsilon_i\]
# Estimate the model
main_model <- lm(mpg ~ wt + hp + disp, data = mtcars)
summary(main_model)
##
## Call:
## lm(formula = mpg ~ wt + hp + disp, data = mtcars)
##
## Residuals:
## Min 1Q Median 3Q Max
## -3.891 -1.640 -0.172 1.061 5.861
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 37.105505 2.110815 17.579 < 2e-16 ***
## wt -3.800891 1.066191 -3.565 0.00133 **
## hp -0.031157 0.011436 -2.724 0.01097 *
## disp -0.000937 0.010350 -0.091 0.92851
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 2.639 on 28 degrees of freedom
## Multiple R-squared: 0.8268, Adjusted R-squared: 0.8083
## F-statistic: 44.57 on 3 and 28 DF, p-value: 8.65e-11
Weight has the biggest effect—each extra 1,000 lbs reduces mpg by about 3.8 miles per gallon. Horsepower is also significant (p = 0.011), but displacement isn’t (p = 0.929), probably because it’s highly correlated with the other variables. The adjusted R² is 0.82, so the model fits pretty well.