Skip to content

Instantly share code, notes, and snippets.

@ramhiser
Created July 4, 2015 03:45
Show Gist options
  • Save ramhiser/f36a907e376461593763 to your computer and use it in GitHub Desktop.
Save ramhiser/f36a907e376461593763 to your computer and use it in GitHub Desktop.
Exercise 4.7 (p.160) from Box, Hunter and Hunter (2005) "Statistics for Experimenters"
library(dplyr)
library(BHH2)
df <- expand.grid(drivers=c('I', 'II', 'III', 'IV'),
cars=1:4)
df <- rbind(df, df) %>% arrange(drivers, cars)
df$treatment <- c(
rep(c('A', 'B', 'D', 'C'), each=2),
rep(c('D', 'C', 'A', 'B'), each=2),
rep(c('B', 'D', 'C', 'A'), each=2),
rep(c('C', 'A', 'B', 'D'), each=2)
)
df <- tbl_df(df) %>%
mutate(drivers=factor(drivers), cars=factor(cars))
df$measurements <- c(
20.6, 21.4, 25, 27, 18.8, 19.2, 26.3, 25.7,
20.6, 21.4, 25.5, 26.5, 22.9, 23.1, 25.8, 26.2,
17.6, 16.4, 14.3, 13.7, 14.8, 15.2, 13.5, 14.5,
17.3, 16.7, 13.8, 14.2, 18.2, 19.8, 22.3, 21.7
)
lm_out <- lm(measurements ~ drivers*cars + treatment, data=df)
anova(lm_out)
aov_out <- aov(measurements ~ ., data=df)
anovaPlot(aov_out, main = "Anova plot: Exercise 4.7", labels = TRUE, cex.lab = 0.6)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment