A note on AI tools: You may use AI assistants (ChatGPT, Claude, etc.) to help debug your R code — that’s a realistic professional skill. You may not use AI to generate your interpretations. Every write-up sentence must reflect your own reading of the output. If you use AI for any part of this assignment, note where at the end.
This assignment uses two datasets that ship with base R — no downloading required.
mtcarsmtcars$am codes transmission type (0 = automatic, 1 =
manual) as a number. First, turn it into a proper factor with meaningful
labels:
data(mtcars)
mtcars$am_f <- factor(mtcars$am, labels = c("automatic", "manual"))
table(mtcars$am_f)Predict first. Which transmission type do you expect
to get better gas mileage (mpg) — automatic or manual? By
roughly how much?
model1 <- lm(mpg ~ am_f, data = mtcars)
summary(model1)am_fmanual coefficient.
Which one is the mean mpg for automatic cars, and which is the
difference between manual and automatic?Now verify the equivalence directly:
t.test(mpg ~ am_f, data = mtcars, var.equal = TRUE)am_fmanual coefficient
from Question 2. Are they the same test? What’s different between the
two outputs (besides which number is reported as the “reference”)?irisiris$Species has three levels (setosa, versicolor,
virginica) — a direct test of the one-way-ANOVA equivalence.
data(iris)
levels(iris$Species)
table(iris$Species)model2 <- lm(Sepal.Length ~ Species, data = iris)
summary(model2)Sepal.Length for each of the three species? (You’ll need to
add each coefficient to the intercept for the non-reference
species.)Now verify against a proper ANOVA:
model2_aov <- aov(Sepal.Length ~ Species, data = iris)
summary(model2_aov)
anova(model2)aov() to the F-statistic and p-value from
anova(model2) (the regression version). Are they
identical?summary() output only directly compares
versicolor and virginica each to setosa. What comparison is
missing, and what R function (from Ch 17/18) would you use to get
it?iris$Species2 <- relevel(iris$Species, ref = "virginica")
model3 <- lm(Sepal.Length ~ Species2, data = iris)
summary(model3)model2, and
which stayed the same? Specifically: did the overall
F-statistic change? Why or why not?am_fmanual was significant,
that proves switching a car from automatic to manual transmission would
improve its mpg.” What’s wrong with this claim, using the language from
the chapter’s own causation caveat?