Una compañía distribuidora ubicada en los suburbios está interesada en estudiar la diferencia en costos (tiempo y gasolina) entre las cuatro rutas (A, B, C, D) que llevan a la zona comercial, más importante para ellos, en el otro extremo de la ciudad. Deciden correr un experimento en cuadro grecolatino controlando los factores de bloque chofer, marca de vehículo (a, b, c, d) y día de la semana. El experimento se repite en dos semanas diferentes, en las cuales no hay días festivos ni quincenas. Los costos observados en pesos se muestran en la siguiente tabla:
library(agricolae)
df<-read.csv("https://docs.google.com/spreadsheets/d/1kCOHoc9qLi6rrBGEyhVQoMCa-j1IfTuJLvpbVQq4wQ8/export?format=csv")
df$Chofer=factor(df$Chofer)
df$Dia=factor(df$Dia)
df$Trat1=factor(df$Trat1)
df$Trat2=factor(df$Trat2)
df$Y=as.numeric(df$Y)
df
## Chofer Dia Trat1 Trat2 Y
## 1 1 1 D a 825
## 2 1 1 D a 750
## 3 1 2 C c 585
## 4 1 2 C c 610
## 5 1 3 B b 550
## 6 1 3 B b 580
## 7 1 4 A d 580
## 8 1 4 A d 650
## 9 2 1 A c 650
## 10 2 1 A c 725
## 11 2 2 B a 540
## 12 2 2 B a 560
## 13 2 3 C d 580
## 14 2 3 C d 635
## 15 2 4 D b 850
## 16 2 4 D b 770
## 17 3 1 C b 700
## 18 3 1 C b 675
## 19 3 2 D d 650
## 20 3 2 D d 740
## 21 3 3 A a 635
## 22 3 3 A a 540
## 23 3 4 B c 450
## 24 3 4 B c 550
## 25 4 1 B d 475
## 26 4 1 B d 480
## 27 4 2 A b 560
## 28 4 2 A b 615
## 29 4 3 D c 650
## 30 4 3 D c 725
## 31 4 4 C a 670
## 32 4 4 C a 730
modelo<-lm(Y~Chofer+Dia+Trat1+Trat2,data=df)
anova<-aov(modelo)
summary(anova)
## Df Sum Sq Mean Sq F value Pr(>F)
## Chofer 3 13165 4388 1.920 0.1607
## Dia 3 18902 6301 2.756 0.0708 .
## Trat1 3 200221 66740 29.196 2.54e-07 ***
## Trat2 3 22415 7472 3.268 0.0439 *
## Residuals 19 43434 2286
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
qqnorm(modelo$residuals)
qqline(modelo$residuals)
boxplot(Y~Trat1,data = df)
boxplot(Y~Trat2,data = df)
library(agricolae)
LSD<-LSD.test(y=anova,trt="Trat2",group=T,console=T)
##
## Study: anova ~ "Trat2"
##
## LSD t Test for Y
##
## Mean Square Error: 2285.979
##
## Trat2, means and individual ( 95 %) CI
##
## Y std r LCL UCL Min Max
## a 656.250 106.66202 8 620.8694 691.6306 540 825
## b 662.500 107.23805 8 627.1194 697.8806 550 850
## c 618.125 91.76591 8 582.7444 653.5056 450 725
## d 598.750 89.95038 8 563.3694 634.1306 475 740
##
## Alpha: 0.05 ; DF Error: 19
## Critical Value of t: 2.093024
##
## least Significant Difference: 50.03574
##
## Treatments with the same letter are not significantly different.
##
## Y groups
## b 662.500 a
## a 656.250 a
## c 618.125 ab
## d 598.750 b
bar.group(x=LSD$groups,horiz=T,col="skyblue",xlim=c(0,750),xlab="Costos", ylab="Marca", main="Costos vs Marca")
LSD<-LSD.test(y=anova,trt="Trat1",group=T,console=T)
##
## Study: anova ~ "Trat1"
##
## LSD t Test for Y
##
## Mean Square Error: 2285.979
##
## Trat1, means and individual ( 95 %) CI
##
## Y std r LCL UCL Min Max
## A 619.375 59.36795 8 583.9944 654.7556 540 725
## B 523.125 47.57982 8 487.7444 558.5056 450 580
## C 648.125 54.57220 8 612.7444 683.5056 580 730
## D 745.000 72.25945 8 709.6194 780.3806 650 850
##
## Alpha: 0.05 ; DF Error: 19
## Critical Value of t: 2.093024
##
## least Significant Difference: 50.03574
##
## Treatments with the same letter are not significantly different.
##
## Y groups
## D 745.000 a
## C 648.125 b
## A 619.375 b
## B 523.125 c
bar.group(x=LSD$groups,horiz=T,col="blue",xlim=c(0,850), xlab="Costos", ylab="Ruta", main="Costos vs Ruta")
Duncan<-duncan.test(anova,"Trat2", group=T, console=T)
##
## Study: anova ~ "Trat2"
##
## Duncan's new multiple range test
## for Y
##
## Mean Square Error: 2285.979
##
## Trat2, means
##
## Y std r Min Max
## a 656.250 106.66202 8 540 825
## b 662.500 107.23805 8 550 850
## c 618.125 91.76591 8 450 725
## d 598.750 89.95038 8 475 740
##
## Alpha: 0.05 ; DF Error: 19
##
## Critical Range
## 2 3 4
## 50.03574 52.51024 54.07757
##
## Means with the same letter are not significantly different.
##
## Y groups
## b 662.500 a
## a 656.250 a
## c 618.125 ab
## d 598.750 b
bar.group(x=Duncan$groups,horiz=T,col="pink",xlim=c(0,750), xlab="Costos", ylab="Marca", main="Costos vs Marca")
Duncan<-duncan.test(anova,"Trat1", group=T, console=T)
##
## Study: anova ~ "Trat1"
##
## Duncan's new multiple range test
## for Y
##
## Mean Square Error: 2285.979
##
## Trat1, means
##
## Y std r Min Max
## A 619.375 59.36795 8 540 725
## B 523.125 47.57982 8 450 580
## C 648.125 54.57220 8 580 730
## D 745.000 72.25945 8 650 850
##
## Alpha: 0.05 ; DF Error: 19
##
## Critical Range
## 2 3 4
## 50.03574 52.51024 54.07757
##
## Means with the same letter are not significantly different.
##
## Y groups
## D 745.000 a
## C 648.125 b
## A 619.375 b
## B 523.125 c
bar.group(x=Duncan$groups,horiz=T,col="red",xlim=c(0,850), xlab="Costos", ylab="Ruta", main="Costos vs Ruta")
library(car)
## Loading required package: carData
##
## Attaching package: 'carData'
## The following object is masked _by_ '.GlobalEnv':
##
## Duncan
leveneTest(df$Y~df$Trat2)
## Levene's Test for Homogeneity of Variance (center = median)
## Df F value Pr(>F)
## group 3 0.2713 0.8455
## 28
leveneTest(df$Y~df$Trat1)
## Levene's Test for Homogeneity of Variance (center = median)
## Df F value Pr(>F)
## group 3 0.3052 0.8214
## 28
plot(anova$residuals)
abline(h=0)