# FRIEDMAN in R SCRIPT FILE. # www_statstutor_ac_uk Community Project. # Basile Marquier and Ellen Marshall, Sheffield University. # Reviewed by Basile Marquier, University of Sheffield. # Dataset: video csv. # Resource: FRIEDMAN in R. #Open the diet dataset which is saved as a csv file and call it dietR. #If your file is saved as a standard Excel file, save it as a csv file first. #You will need to change the command depending on where you have saved the file. # You will need to install the 'PMCMR' package # Click on "Packages"->"Install Package(s)" and choose 'PMCMR' #Download the data set in .csv format and put it in a directory on your computer #Open the file from the place it is saved on your computer #This example refers to the memory stick where the data is stored as stcp-Rdataset-video. videoR<-read.csv("E:\\stcp-Rdataset-video.csv",header=T,sep=",") #You should install the 'stats' package in order to have the function friedman. library('stats') #LOADING THE DATA #For me videoR<-read.csv("stcp-Rdataset-Video.csv",header=T,sep=",") #For MASH: #videoR<-read.csv("D:\\video.csv",header=T,sep=",") #Tell R we are using the diet dataset until further notice using attach. attach(videoR) median(videoR[,14]) median(TotalAGen) median(TotalBdoc) median(TotalCOld) median(TotalDDEMO) boxplot(TotalAGen,TotalBdoc,TotalCOld,TotalDDEMO,names=c("A","B","C","D")) ############################################################################################# ##################################################################### ##################################### ######################################################## ######################################## ASSUMPTIONS ################################################################################## ################################################################################### ############################################################################################# # Assumption 1: One group that is measured on three or more different occasions. # Assumption 2: Group is a random sample from the population. # Assumtion 3: Your dependent variable should be measured at the ordinal or continuous level. # Assumption 4: Samples DO not need to be normally distributed #If any of the columns is not normally distributed, then we should use Friedman. #If all columns are normally distributed then ANOVA is preferable. par(mfrow=c(2,2)) hist(Sample[,1], main="Histogram of TotalAGen",xlab="Value") hist(Sample[,2], main="Histogram of TotalBdoc",xlab="Value") hist(Sample[,3], main="Histogram of TotalCOld",xlab="Value") hist(Sample[,4], main="Histogram of TotalDDEMO",xlab="Value") ## => most of the graphs show skewed data, in particular for AGenUnderstanding, ## So we use a Friedman test rather than a Repeated Measures Anova ##################################################################### ######################################################## ######################################## ANALYSIS ################################################################################## ################################################################################### # The Friedman test is conducted from the table of data # with each column representing each sample: Sample<-matrix(c(TotalAGen,TotalBdoc,TotalCOld,TotalDDEMO),ncol=4) #To carry out a friedman test use friedman.test(table with samples presented as columns) provided by 'stats' package. friedman.test(Sample) ## => strong evidence against the null that the conditions are equivalent ####################### MULTIPLE COMPARISONS library(PMCMR) posthoc.friedman.nemenyi.test(Sample) ### => Apart from Sample 2 vs. Sample 4, there is a strong evidence against similarity in all pairs