library(ggplot2)
library(Sleuth3)
qplot(Judge, Percent, data = case0502)
# === Extra Sum of Squares F-test === #
# the best guess for the means in the separate means model, the full model
case0502$group_average <- with(case0502, ave(Percent, Judge))
# the best guess for the means in the equal means model, the reduced model
case0502$overall_average <- with(case0502, mean(Percent))
head(case0502)
# the sum of squares for the equal means model
with(case0502, sum((Percent - overall_average)^2))
# the sum of squares for the separate means model
with(case0502, sum((Percent - group_average)^2))
# visualising the residuals
# within group residuals
qplot(Percent - group_average, data = case0502)+ xlim(-25, 25)
# equal means residuals
qplot(Percent - overall_average, data = case0502, fill = I("grey50")) + xlim(-25, 25)
# between group residuals
qplot(group_average - overall_average, data = case0502,
fill = I("red")) + xlim(-25, 25)