# Load the data
data(chapter_4_table_1)
# Or, alternatively load the data as
data(C4T1)
# View the structure
str(chapter_4_table_1)
# ---------------------------------------------------------------------
# Optional: a factor-coded copy for ANOVA / model-comparison analyses.
# Group membership is stored as a numeric code so the book's contrast and
# model-comparison examples reproduce exactly. For a one-way ANOVA you
# generally want it as a factor; otherwise the code enters the model as a
# single linear (1 df) term. Build a *copy* (suffix "_factors") so the
# canonical data set is left unchanged. Labels are taken from the
# "Variables" section above.
C4T1_factors <- chapter_4_table_1
C4T1_factors$cond <- factor(C4T1_factors$cond, levels = 1:4,
labels = c("Drug Therapy", "Biofeedback", "Diet", "Combination"))
# The coding matters: numeric code (1 df) versus factor (3 df).
anova(lm(bloodpr ~ cond, data = chapter_4_table_1))
anova(lm(bloodpr ~ cond, data = C4T1_factors))
Run the code above in your browser using DataLab