## Section 5.8 examples ## Grasses Example: # These are actually within-block ranks, but for # Friedman's test we can treat them as if they are raw data: grass.data <- matrix(c(4,3,2,1, 4,2,3,1, 3,1.5,1.5,4, 3,1,2,4, 4,2,1,3, 2,2,2,4, 1,3,2,4, 2,4,1,3, 3.5,1,2,3.5, 4,1,3,2, 4,2,3,1, 3.5,1,2,3.5), nrow=12, ncol=4, byrow=T) friedman.test(grass.data) # this assumes the columns represent the treatments and the rows represent the blocks # The data could be given in long vector form, with vectors # for the treatment-group labels and the block labels: grass.vec <- c(4,3,2,1,4,2,3,1,3,1.5,1.5,4,3,1,2,4,4,2,1,3,2,2,2,4,1,3,2,4,2,4,1,3,3.5,1,2,3.5,4,1,3,2,4,2,3,1,3.5,1,2,3.5) grasstype <- rep(1:4,times=12) homeowner <- rep(1:12, each=4) friedman.test(grass.vec, groups = grasstype, blocks = homeowner) ## Multiple Comparisons: alpha <- 0.05 b <- 12 k <- 4 Rj <- colSums(matrix(unlist(tapply(grass.vec,homeowner,rank)), nrow=b, ncol=k, byrow=T)) A1 <- sum(unlist(tapply(grass.vec,homeowner,rank))^2) abs(outer(Rj, Rj, '-')) > qt(1-alpha/2, df=((b-1)*(k-1)), lower=T)*sqrt((2*(b*A1-sum(Rj^2)))/((b-1)*(k-1))) ## Which pairs of grasses are significantly different?