#Asignatura: Dise昼㸱os Experimentales
#Facultad : Ingenier攼㹤a Estadistica e Informatica
#Universidad Nacional del Altiplano
library(knitr)
## Warning: package 'knitr' was built under R version 3.6.3
library(readxl)
## Warning: package 'readxl' was built under R version 3.6.3
DCAB <- read_excel("DCAB.xlsx")
DCAB
## # A tibble: 16 x 3
## ph FrutaA FrutaB
## <chr> <chr> <chr>
## 1 3.46 Melocoton Piña
## 2 3.48 Melocoton Piña
## 3 3.55 Melocoton Piña
## 4 3.54 Melocoton Piña
## 5 3.57 Melocoton Fresa
## 6 3.53 Melocoton Fresa
## 7 3.40 Melocoton Fresa
## 8 3.44 Melocoton Fresa
## 9 3.51 Papaya Piña
## 10 3.60 Papaya Piña
## 11 3.41 Papaya Piña
## 12 3.52 Papaya Piña
## 13 3.49 Papaya Fresa
## 14 3.41 Papaya Fresa
## 15 3.50 Papaya Fresa
## 16 3.58 Papaya Fresa
head(DCAB)
## # A tibble: 6 x 3
## ph FrutaA FrutaB
## <chr> <chr> <chr>
## 1 3.46 Melocoton Piña
## 2 3.48 Melocoton Piña
## 3 3.55 Melocoton Piña
## 4 3.54 Melocoton Piña
## 5 3.57 Melocoton Fresa
## 6 3.53 Melocoton Fresa
View(DCAB)
#Factores
DCAB$FrutaA <- factor(DCAB$FrutaA)
DCAB$FrutaB <- factor(DCAB$FrutaB)
DCAB$ph <- as.numeric(DCAB$ph)
str(DCAB)
## tibble [16 x 3] (S3: tbl_df/tbl/data.frame)
## $ ph : num [1:16] 3.46 3.48 3.55 3.54 3.57 3.53 3.4 3.44 3.51 3.6 ...
## $ FrutaA: Factor w/ 2 levels "Melocoton","Papaya": 1 1 1 1 1 1 1 1 2 2 ...
## $ FrutaB: Factor w/ 2 levels "Fresa","Piña": 2 2 2 2 1 1 1 1 2 2 ...
head(DCAB)
## # A tibble: 6 x 3
## ph FrutaA FrutaB
## <dbl> <fct> <fct>
## 1 3.46 Melocoton Piña
## 2 3.48 Melocoton Piña
## 3 3.55 Melocoton Piña
## 4 3.54 Melocoton Piña
## 5 3.57 Melocoton Fresa
## 6 3.53 Melocoton Fresa
#Analisis del ANOVA
mod1 <- aov(ph~ FrutaA + FrutaB, data = DCAB )
mod1
## Call:
## aov(formula = ph ~ FrutaA + FrutaB, data = DCAB)
##
## Terms:
## FrutaA FrutaB Residuals
## Sum of Squares 0.00015625 0.00140625 0.05713125
## Deg. of Freedom 1 1 13
##
## Residual standard error: 0.06629262
## Estimated effects may be unbalanced
summary(mod1)
## Df Sum Sq Mean Sq F value Pr(>F)
## FrutaA 1 0.00016 0.000156 0.036 0.853
## FrutaB 1 0.00141 0.001406 0.320 0.581
## Residuals 13 0.05713 0.004395
coef(mod1)
## (Intercept) FrutaAPapaya FrutaBPiña
## 3.486875 0.006250 0.018750
mod2 <- aov(ph~ FrutaB + FrutaA, data = DCAB )
mod2
## Call:
## aov(formula = ph ~ FrutaB + FrutaA, data = DCAB)
##
## Terms:
## FrutaB FrutaA Residuals
## Sum of Squares 0.00140625 0.00015625 0.05713125
## Deg. of Freedom 1 1 13
##
## Residual standard error: 0.06629262
## Estimated effects may be unbalanced
summary(mod2)
## Df Sum Sq Mean Sq F value Pr(>F)
## FrutaB 1 0.00141 0.001406 0.320 0.581
## FrutaA 1 0.00016 0.000156 0.036 0.853
## Residuals 13 0.05713 0.004395
coef(mod2)
## (Intercept) FrutaBPiña FrutaAPapaya
## 3.486875 0.018750 0.006250
#Graficas de Cajas
boxplot(ph~FrutaA, data=DCAB, col=c("blue","orange"), main="Diagrama de Cajas de los Jugos de Frutas")
mtext("By:Amarillas", side = 3, adj = 1, family = "mono")

boxplot(ph~FrutaB, data=DCAB, col=c("yellow","green"), main="Diagrama de Cajas de los Jugos de Frutas")
mtext("By:Amarillas", side = 3, adj = 1, family = "mono")

#Hipotesis de Normalidad
shapiro.test(mod1$residuals)
##
## Shapiro-Wilk normality test
##
## data: mod1$residuals
## W = 0.94645, p-value = 0.4357
#Grafico
qqnorm(mod1$residuals)
mtext("By:Amarillas", side = 3, adj = 1, family = "mono")

#Hipotesis de Homogeneidad
bartlett.test(DCAB$ph, DCAB$FrutaA)
##
## Bartlett test of homogeneity of variances
##
## data: DCAB$ph and DCAB$FrutaA
## Bartlett's K-squared = 0.11591, df = 1, p-value = 0.7335
bartlett.test(DCAB$ph, DCAB$FrutaB)
##
## Bartlett test of homogeneity of variances
##
## data: DCAB$ph and DCAB$FrutaB
## Bartlett's K-squared = 0.16743, df = 1, p-value = 0.6824
#Hipotesis de Independencia
layout(matrix(c(1,2,3,4),1,1))
plot(mod1)




plot(mod2)



library(agricolae)
## Warning: package 'agricolae' was built under R version 3.6.3

contraste <- SNK.test(mod1,"Fruta A", console=TRUE, main="Contraste de Newman-Keuls para el factor nivel de la Fruta A")
## Name: Fruta A
## FrutaA FrutaB