library(reshape2) library(gplots) library(multcomp) DF = read.csv('../../Data/ASCII_Comma/Chapter_12/dogs.txt', header=FALSE) colnames(DF) = sprintf('Dog%d', seq(10)) DF$Anesthesia = c('Isofluorane', 'Halothane', 'Cyclopropane') DF_melt = melt(DF, id.vars=c('Anesthesia'), variable.name='Dog', value.name='Concentration') DF_melt$Anesthesia = as.factor(DF_melt$Anesthesia) fit = aov(Concentration ~ Anesthesia + Dog, data=DF_melt) # 2-way ANOVA print(summary(fit)) fit = aov(Concentration ~ Anesthesia, data=DF_melt) # 1-way ANOVA print(summary(fit)) #postscript("../../WriteUp/Graphics/Chapter12/prob_26_plotmeans.eps", onefile=FALSE, horizontal=FALSE) plotmeans(Concentration ~ Anesthesia, data=DF_melt) #dev.off() # A Tukey comparison of means test: # TukeyHSD(fit) par(las=2) par(mar=c(5, 8, 4, 2)) plot(TukeyHSD(fit)) # Use the multcomp package: # par(las=2) par(mar=c(5, 4, 6, 2)) tuk = glht(fit, linfct=mcp(Anesthesia='Tukey')) plot(cld(tuk, level=0.05), col='lightgrey') # A nonparametric test for one-way ANOVA: # print(kruskal.test(Concentration ~ Anesthesia, data=DF_melt))