#Example - 2-Factor Factorial Design # Testing hypothesis in two-way ANOVA library(car) library(ggplot2) #Set working directory setwd("~/Dropbox/ISI SCB/Data sets") # read in csv file life <-read.csv("lifetime.csv", TRUE) Lifetime <- life$Lifetime Material <- life$Material Temperature <-life$Temperature #boxplots ggplot(life, aes(x=Temperature, y=Lifetime, fill=Material), fixed=TRUE) + geom_boxplot() interaction.plot(Temperature,Material,Lifetime, type ="b", pch=c(19, 17, 15), col=c("blue","red","green"),fixed=TRUE) #Two-way ANOVA life.aov<- aov(Lifetime~Material+Temperature+Material:Temperature) summary(life.aov) #Two-way ANOVA life.aov<- aov(Lifetime~Material*Temperature) summary(life.aov) #Multiple Comparisons life.tukey <- TukeyHSD(life.aov) life.tukey plot(life.tukey) #residuals and fitted values of the model res <- life.aov$residuals fit <- life.aov$fitted.values #residual plot to assess constant variance assumption plot(fit,res, main="Residual Plot",xlab= "Fitted Values", ylab="Residuals") #Test constant variance assumption leveneTest(Lifetime~Material*Temperature) #assess normality assumption qqnorm(res, ylab = "Residuals Sample Quantiles") shapiro.test(res) hist(res)