ANOVA
Soumya Roy
Wed Jun 20 [Link] 2018
# Reading the data file
d<-[Link]("C:/Users/Soumya-
Roy/Desktop/DAR_18/Class_2/[Link]",header=T)
d
## Crust Coke Bread Delivery
## 1 0 1 1 14
## 2 1 1 0 21
## 3 0 0 0 18
## 4 0 0 1 17
## 5 1 0 0 19
## 6 1 0 1 17
## 7 0 1 0 19
## 8 0 0 0 20
## 9 0 1 0 16
## 10 1 1 1 19
## 11 0 0 1 18
## 12 1 1 0 22
## 13 1 0 1 19
## 14 0 1 1 16
## 15 1 0 0 20
## 16 1 1 1 18
# Naming the variables
crust<-[Link](d$Crust)
coke<-[Link](d$Coke)
bread<-[Link](d$Bread)
delivery<-d$Delivery
# Creating the treatments
treatment<-NULL
for(i in 1:16)
{
if(crust[i]=="0" & coke[i]=="0" & bread[i]=="0") treatment[i]<-"000"
if(crust[i]=="1" & coke[i]=="0" & bread[i]=="0") treatment[i]<-"100"
if(crust[i]=="0" & coke[i]=="1" & bread[i]=="0") treatment[i]<-"010"
if(crust[i]=="1" & coke[i]=="1" & bread[i]=="0") treatment[i]<-"110"
if(crust[i]=="0" & coke[i]=="0" & bread[i]=="1") treatment[i]<-"001"
if(crust[i]=="1" & coke[i]=="0" & bread[i]=="1") treatment[i]<-"101"
if(crust[i]=="0" & coke[i]=="1" & bread[i]=="1") treatment[i]<-"011"
if(crust[i]=="1" & coke[i]=="1" & bread[i]=="1") treatment[i]<-"111"
}
treatment<-[Link](treatment)
# Strip Chart
stripchart(delivery~treatment,xlab="Treatment",ylab="Delivery
Time",vertical=T,col="red",pch=24,lwd=2)
# Plot of Average Delivery Times
library(gplots)
##
## Attaching package: 'gplots'
## The following object is masked from 'package:stats':
##
## lowess
plotmeans(delivery~treatment,xlab="Treatment",ylab="Delivery
Time",col="red",bars=T,barwidth=2,lwd=2)
# One-way ANOVA to check whether the average delivery times are significantly
different
mod_1<-aov(delivery~treatment)
summary(mod_1)
## Df Sum Sq Mean Sq F value Pr(>F)
## treatment 7 48.94 6.991 4.474 0.0259 *
## Residuals 8 12.50 1.563
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# Multi-factor ANOVA
mod_2<-aov(delivery~crust*coke*bread)
summary(mod_2)
## Df Sum Sq Mean Sq F value Pr(>F)
## crust 1 18.062 18.062 11.56 0.00936 **
## coke 1 0.563 0.563 0.36 0.56511
## bread 1 18.062 18.062 11.56 0.00936 **
## crust:coke 1 10.562 10.562 6.76 0.03162 *
## crust:bread 1 0.062 0.062 0.04 0.84647
## coke:bread 1 1.563 1.563 1.00 0.34659
## crust:coke:bread 1 0.062 0.062 0.04 0.84647
## Residuals 8 12.500 1.563
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# Multi-factor ANOVA after dropping the insignificant terms
mod_3<-aov(delivery~crust+coke+bread+crust:coke)
summary(mod_3)
## Df Sum Sq Mean Sq F value Pr(>F)
## crust 1 18.062 18.062 14.004 0.00325 **
## coke 1 0.563 0.563 0.436 0.52259
## bread 1 18.062 18.062 14.004 0.00325 **
## crust:coke 1 10.562 10.562 8.189 0.01547 *
## Residuals 11 14.188 1.290
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# Plot of Residuals
plot(mod_3,which=c(1,2))
# Normality Check of Residuals
res<-mod_3$res
[Link](res)
##
## Shapiro-Wilk normality test
##
## data: res
## W = 0.94095, p-value = 0.3608
# Homoscedasticity Check for Residuals
[Link](res~crust)
##
## Bartlett test of homogeneity of variances
##
## data: res by crust
## Bartlett's K-squared = 0.82086, df = 1, p-value = 0.3649
[Link](res~coke)
##
## Bartlett test of homogeneity of variances
##
## data: res by coke
## Bartlett's K-squared = 0.22757, df = 1, p-value = 0.6333
[Link](res~bread)
##
## Bartlett test of homogeneity of variances
##
## data: res by bread
## Bartlett's K-squared = 0.20608, df = 1, p-value = 0.6499
# Plotting the Main Effects
library(gplots)
plotmeans(delivery~crust,xlab="Crust",ylab="Delivery
Time",col="red",bars=T,barwidth=2,lwd=2)
plotmeans(delivery~coke,xlab="Coke",ylab="Delivery
Time",col="red",bars=T,barwidth=2,lwd=2)
plotmeans(delivery~bread,xlab="Bread",ylab="Delivery
Time",col="red",bars=T,barwidth=2,lwd=2)
# Plotting the Interaction Effect
[Link](crust,coke,delivery,main="crust*coke")
# Pairwise Comparison
TukeyHSD(mod_3)$bread
## diff lwr upr p adj
## 1-0 -2.125 -3.374809 -0.8751908 0.003253457
TukeyHSD(mod_3)$'crust:coke'
## diff lwr upr p adj
## 1:0-0:0 0.50 -1.9168119 2.91681188 0.92267036
## 0:1-0:0 -2.00 -4.4168119 0.41681188 0.11663937
## 1:1-0:0 1.75 -0.6668119 4.16681188 0.18879599
## 0:1-1:0 -2.50 -4.9168119 -0.08318812 0.04207525
## 1:1-1:0 1.25 -1.1668119 3.66681188 0.43969227
## 1:1-0:1 3.75 1.3331881 6.16681188 0.00324530