# Load the data
data(chapter_7_table_5)
# Or, alternatively load the data as
data(C7T5)
# View the structure
str(chapter_7_table_5)
# ---------------------------------------------------------------------
# Optional: a factor-coded copy for factorial ANOVA / model comparison.
# Feedback and Drug are stored as numeric codes so the book's contrast and
# model-comparison examples reproduce exactly. For a factorial ANOVA you
# want them as factors; otherwise a code enters the model as a single
# linear (1 df) term. The "Variables" section does not give level labels,
# so the numeric codes are kept as the factor levels. Build a *copy*
# (suffix "_factors") so the canonical data set is left unchanged.
C7T5_factors <- chapter_7_table_5
C7T5_factors$Feedback <- factor(C7T5_factors$Feedback)
C7T5_factors$Drug <- factor(C7T5_factors$Drug)
# This design is balanced, so the factorial ANOVA is order-invariant.
anova(lm(Score ~ Feedback * Drug, data = C7T5_factors))
Run the code above in your browser using DataLab