Introduction

In Lab 9, we predicted fuel economy using one variable at a time. Here, we will use more than one predictor and investigate what changes when we account for additional information.

Our goals are to:

  • Fit multiple regression models and interpret their coefficients.
  • Explain why estimates and evidence can change when we add a predictor.
  • Distinguish the overall F-test from a test comparing two nested models.

Use \(\alpha=.05\) throughout. Save each model and dataset with the name specified so you can return to it later. Give brief answers in context; you do not need to transcribe every number in the output.

The data

We will continue with the 32 vehicles in mtcars. This lab starts with a fresh working copy, so you do not need to load your Lab 9 work.

Variable Description
mpg Fuel economy, in miles per gallon
wt Vehicle weight, in thousands of pounds
transmission Automatic or manual, created from am
library(dplyr)
library(ggplot2)
theme_set(theme_bw())

cars <- mtcars
cars$transmission <- factor(cars$am, levels = c(0, 1),
                             labels = c("automatic", "manual"))

The reference category is automatic. A coefficient named transmissionmanual compares manual cars with automatic cars.

Question 1: Comparing transmissions

  • Part A: Use group_by() and summarize() to find the number of cars, mean fuel economy, and mean weight for each transmission group. Save and display the result as transmission_summary.
  • Part B: Fit a model predicting fuel economy using transmission alone. Save it as transmission_fit and display its summary. Interpret the manual coefficient, state its null hypothesis, and draw a conclusion using its p-value.
  • Part C: Create a scatter plot of weight on the x-axis and fuel economy on the y-axis, coloring points by transmission. Label the axes with units. Using the plot and your summary, describe how the transmission groups differ in weight. Does the transmission-only model account for that difference?

Adding a second predictor

To include two predictors, separate them with +:

## Do not run this, this is just an example
lm(outcome ~ predictor1 + predictor2, data = dataset)

For weight and transmission, our fitted equation has the form

\[ \hat y = \hat\beta_0 + \hat\beta_{\mathrm{wt}}\,\mathrm{wt} + \hat\beta_{\mathrm{manual}}\,\mathbf{1}_{\mathrm{manual}}. \]

The indicator is 1 for manual and 0 for automatic cars. This model gives both transmission groups the same weight slope, but allows their intercepts to differ. We are not including an interaction.

Each coefficient now describes a comparison holding the other predictor fixed. For example, the transmission coefficient compares the predicted means of manual and automatic cars at the same weight.

Question 2: Accounting for weight

  • Part A: Fit the model with fuel economy as the outcome and weight and transmission as predictors. Save it as weight_transmission_fit and display its summary. Write the fitted equation and interpret both the weight and manual coefficients. Be explicit about what is held fixed.
  • Part B: Predict mean fuel economy for an automatic car and a manual car, both weighing 3,000 pounds. You may use your equation or the code below. How does the difference between the predictions relate to the manual coefficient? Should individual cars necessarily have these exact fuel economies?
same_weight_cars <- data.frame(
  wt = c(3, 3),
  transmission = factor(c("automatic", "manual"),
                         levels = levels(cars$transmission))
)

same_weight_cars$predicted_mpg <- predict(
  weight_transmission_fit, newdata = same_weight_cars
)
same_weight_cars
  • Part C: Compare the manual coefficient and its p-value with the transmission-only model. How has the conclusion at \(\alpha=.05\) changed? A classmate says, “One model says transmission matters and the other says it doesn’t, so one must be wrong.” Explain how the two coefficients answer different questions. Use your plot and summary from Question 1 to support your explanation.
  • Part D: Run the code below to plot the predictions from your combined model. Compare the two lines where the groups’ weight ranges overlap. How does this picture help explain the manual coefficient? Does a nonsignificant coefficient prove that the population difference is zero?
# Save the fitted predictions alongside the original observations.
car_predictions <- cars %>%
  mutate(predicted_mpg = fitted(weight_transmission_fit))

ggplot(car_predictions, aes(wt, mpg, color = transmission)) +
  geom_point() +
  geom_line(aes(y = predicted_mpg, group = transmission)) +
  labs(x = "Weight (1,000 pounds)", y = "Fuel economy (mpg)",
       color = "Transmission")

The lines come from the saved model. Adding geom_smooth(method = lm) separately for each transmission group would estimate two slopes rather than the common slope in our additive model.

Comparing models

We now have two questions we could ask about the combined model:

  • Overall F-test: Do weight and transmission, taken together, help describe mean fuel economy? This tests whether both non-intercept coefficients are zero, comparing with an intercept-only model.
  • Nested F-test: Does transmission add information after weight is already included? This compares a weight-only model with the weight-plus-transmission model.

Use summary() for the overall test. To compare nested models, use anova(reduced_model, full_model), putting the smaller model first. Both models must use the same outcome and observations.

Question 3: Does the addition help?

  • Part A: Fit a weight-only model, save it as weight_fit, and display its summary. Compare its \(R^2\) and residual standard error with those of weight_transmission_fit. Does adding transmission noticeably improve the fit? Is an increase in ordinary \(R^2\) alone enough to justify keeping an additional predictor?
  • Part B: Find the overall F-test in summary(weight_transmission_fit). State its null hypothesis and give a conclusion. Does rejecting this null establish that both predictors contribute after accounting for the other?
  • Part C: Run the comparison below. State the null hypothesis and use the p-value in the second row to draw a conclusion. Explain why this result can differ from the overall F-test in Part B. What does this nested test have in common with the manual coefficient’s t-test?
anova(weight_fit, weight_transmission_fit)