# R example of Friedman's Test on the soybean data # The response is yield # The treatments are the different varieties # The blocks are 3 different regions ########## ## # Reading the data into R: my.datafile <- tempfile() cat(file=my.datafile, " A 1 45 A 2 49 A 3 38 B 1 48 B 2 45 B 3 39 C 1 43 C 2 42 C 3 35 D 1 41 D 2 39 D 3 36 E 1 44 E 2 41 E 3 40 ", sep=" ") soy <- read.table(my.datafile, header=FALSE, col.names=c("variety", "region", "yield")) # Note we could also save the data columns into a file and use a command such as: # soy <- read.table(file = "z:/stat_705/filename.txt", header=FALSE, col.names = c("variety", "region", "yield")) attach(soy) ## ######### #################################################################### variety <- factor(variety) region <- factor(region) # In R, the Friedman test can be done with the friedman.test() function. friedman.test(yield, groups = variety, blocks = region) # Or, equivalently: friedman.test(yield ~ variety | region) ################################################################# # To calculate the ranks within blocks (regions): tapply(yield, region, rank)