# R example of Friedman's test: # Wind example from Nigeria # The response (WSR) is average wind speed reduction # The treatments are the different distances for the shelterbelt # The blocks are 9 different months # Entering the data: ########## ## # Reading the data into R: ff <- tempfile() cat(file=ff, " Jan 20 22.1 Jan 40 20.7 Jan 100 15.4 Jan 150 12.3 Jan 200 6.9 Feb 20 19.2 Feb 40 18.7 Feb 100 14.9 Feb 150 9.3 Feb 200 6.5 Mar 20 21.5 Mar 40 21.9 Mar 100 14.3 Mar 150 9.9 Mar 200 7.1 Apr 20 21.5 Apr 40 21.2 Apr 100 11.1 Apr 150 9.4 Apr 200 6.2 May 20 21.3 May 40 20.9 May 100 11.2 May 150 9.4 May 200 7.7 Jun 20 20.9 Jun 40 19.6 Jun 100 16.9 Jun 150 11.6 Jun 200 7.0 Aug 20 19.3 Aug 40 18.7 Aug 100 14.4 Aug 150 12.5 Aug 200 7.0 Sep 20 20.1 Sep 40 19.6 Sep 100 15.6 Sep 150 12.6 Sep 200 7.5 Oct 20 23.7 Oct 40 20.4 Oct 100 14.6 Oct 150 12.4 Oct 200 8.5 ", sep=" ") windspeed <- read.table(ff, header=FALSE, col.names=c("month", "distance", "wsr")) # Note we could also save the data columns into a file and use a command such as: # windspeed <- read.table(file = "z:/stat_705/filename.txt", header=FALSE, col.names = c("month", "distance", "wsr")) attach(windspeed) # The data frame called windspeed is now created, # with three variables, "month", "distance", "wsr". ## ######### #################################################################### month <- factor(month) distance <- factor(distance) # In R, the Friedman test can be done with the friedman.test() function. friedman.test(wsr, groups = distance, blocks = month) # Or, equivalently: friedman.test(wsr ~ distance | month) ################################################################# # To calculate the ranks within blocks (months): tapply(wsr, month, rank)