# R example: Repeated Measures Analysis # The data set is the wine judging data from chapter 27 options(scipen=999) # suppressing scientific notation # Each of 6 subjects (judges) rates 4 wines in a random sequence. # The rating is the response. # The wine types are the treatments. # Main question: Is there a significant difference # in the mean ratings for the 4 wines? ##################################################### # Save the data file into a directory and # use the full path name: wine.data <- read.table(file = "z:/My Documents/teaching/stat_705/winedata.txt", header=FALSE, col.names = c('rating', 'judge', 'wine')) # attaching the data frame: attach(wine.data) # Making "judge" and "wine" factors: judge <- factor(judge) wine <- factor(wine) # Informally checking the "compound symmetry" assumption: # Getting the within-subjects variance-covariance matrix: wine1.ratings <- rating[wine==1] wine2.ratings <- rating[wine==2] wine3.ratings <- rating[wine==3] wine4.ratings <- rating[wine==4] cov(cbind(wine1.ratings, wine2.ratings, wine3.ratings, wine4.ratings)) # The covariance matrix is printed. # We check whether the variances (the diagonal elements) # are roughly of similar magnitude. # We also check whether all the covariances (the off-diagonal elements) # are roughly of similar magnitude. # If so, the compound symmetry assumption is reasonable. # ######################################################### # The analysis is identical to that of the RCBD: # Fitting the no-interaction ANOVA model and producing the ANOVA table: wine.fit <- lm(rating ~ judge + wine); anova(wine.fit) # There is no equivalent of the RANDOM statement in the lm() function, # but keep in mind that "judge" has random levels. # Tukey procedure: TukeyHSD(aov(wine.fit),conf.level=0.95)$wine # All the same assumption checks that were used in the RCBD can be used here.