library(readxl)
## Warning: package 'readxl' was built under R version 4.2.3
library(outliers)
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.2.3
library(collapsibleTree)
## Warning: package 'collapsibleTree' was built under R version 4.2.3
library(lattice)
library(TukeyC)
## Warning: package 'TukeyC' was built under R version 4.2.3
datos1 = read_xlsx("C://Users//Grald//OneDrive//Documentos//DISEÑO EXPERIMENTOS//TALLER PARCIAL.xlsx", sheet = 1)
View(datos1)
as.factor(datos1$presion)
## [1] p_0,05 p_0,05 p_0,05 p_0,1 p_0,1 p_0,1 p_0,2 p_0,2 p_0,2 p_0,25
## [11] p_0,25 p_0,25
## Levels: p_0,05 p_0,1 p_0,2 p_0,25
as.numeric(datos1$tf)
## [1] 0.88 0.89 0.87 0.92 0.94 0.93 0.95 0.95 0.94 0.98 0.98 0.99
ggplot(datos1)+
aes(presion, tf, fill=presion)+
geom_boxplot()
ggplot(data=datos1, aes(x=presion, y=tf, fill=presion))+
geom_col()
#ANOVA MODELO1
mod = aov(tf ~ presion, data = datos1)
summary(mod)
## Df Sum Sq Mean Sq F value Pr(>F)
## presion 3 0.016567 0.005522 82.83 2.3e-06 ***
## Residuals 8 0.000533 0.000067
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
*La presión si tiene efecto en el tiempo de fractura de la madera.
#Revisión de supuestos:
residuos = mod$residuals
TukeyHSD(mod, conf.level = 0.95)
## Tukey multiple comparisons of means
## 95% family-wise confidence level
##
## Fit: aov(formula = tf ~ presion, data = datos1)
##
## $presion
## diff lwr upr p adj
## p_0,1-p_0,05 0.05000000 0.028650987 0.07134901 0.0003178
## p_0,2-p_0,05 0.06666667 0.045317653 0.08801568 0.0000396
## p_0,25-p_0,05 0.10333333 0.081984320 0.12468235 0.0000014
## p_0,2-p_0,1 0.01666667 -0.004682347 0.03801568 0.1344163
## p_0,25-p_0,1 0.05333333 0.031984320 0.07468235 0.0002012
## p_0,25-p_0,2 0.03666667 0.015317653 0.05801568 0.0025538
#Normalidad
shapiro.test(residuos)
##
## Shapiro-Wilk normality test
##
## data: residuos
## W = 0.94102, p-value = 0.5114
#Homocedasticidad
bartlett.test(residuos, datos1$presion)
##
## Bartlett test of homogeneity of variances
##
## data: residuos and datos1$presion
## Bartlett's K-squared = 0.95233, df = 3, p-value = 0.8128
\[Y_{ij}: \mu + \tau_{i} + \epsilon_{ij}\]
#Prueba de datos atipicos:
grubbs.test(datos1$tf)
##
## Grubbs test for one outlier
##
## data: datos1$tf
## G = 1.64859, U = 0.73046, p-value = 0.5021
## alternative hypothesis: lowest value 0.87 is an outlier
datos2 = read_xlsx("C://Users//Grald//OneDrive//Documentos//DISEÑO EXPERIMENTOS//TALLER PARCIAL.xlsx", sheet = 2)
View(datos2)
as.factor(datos2$catalizador)
## [1] c_A c_A c_A c_A c_A c_A c_B c_B c_B c_B c_B c_B c_C c_C c_C c_C c_C c_C c_D
## [20] c_D c_D c_D c_D c_D
## Levels: c_A c_B c_C c_D
as.numeric(datos2$rend)
## [1] 60 63 62 61 63 62 65 67 70 68 66 65 69 66 73 68 66 67 58 63 61 63 62 65
#Analisis descriptivo
ggplot(datos2)+
aes(catalizador, rend, fill=catalizador)+
geom_boxplot()
ggplot(data=datos2, aes(x=catalizador, y=rend, fill=catalizador))+
geom_col()
* Los catalizadores B y C son los que tienen mayor impacto sobre el
rendimiento.
collapsibleTreeSummary(datos2,
c("catalizador", "rend"),
collapsed = FALSE)
#ANOVA Modelo2
mod2 = aov(rend ~ catalizador, data = datos2)
summary(mod2)
## Df Sum Sq Mean Sq F value Pr(>F)
## catalizador 3 192.5 64.15 14.5 3.01e-05 ***
## Residuals 20 88.5 4.43
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#Revisión de supuestos:
residuos = mod2$residuals
TukeyHSD(mod2, conf.level = 0.95)
## Tukey multiple comparisons of means
## 95% family-wise confidence level
##
## Fit: aov(formula = rend ~ catalizador, data = datos2)
##
## $catalizador
## diff lwr upr p adj
## c_B-c_A 5.0000000 1.600704 8.399296 0.0027711
## c_C-c_A 6.3333333 2.934037 9.732629 0.0002282
## c_D-c_A 0.1666667 -3.232629 3.565963 0.9990452
## c_C-c_B 1.3333333 -2.065963 4.732629 0.6948686
## c_D-c_B -4.8333333 -8.232629 -1.434037 0.0037860
## c_D-c_C -6.1666667 -9.565963 -2.767371 0.0003110
#Normalidad
shapiro.test(residuos)
##
## Shapiro-Wilk normality test
##
## data: residuos
## W = 0.96494, p-value = 0.5454
\[Y_{ij}: \mu + \tau_{i} + \epsilon_{ij}\] * i = factor, j = repeticiones. Media + factor + error
#Homocedasticidad
bartlett.test(residuos, datos2$catalizador)
##
## Bartlett test of homogeneity of variances
##
## data: residuos and datos2$catalizador
## Bartlett's K-squared = 2.9844, df = 3, p-value = 0.394
*Se cumple el supuesto de normalidad.
#Prueba de datos atipicos
grubbs.test(datos2$rend)
##
## Grubbs test for one outlier
##
## data: datos2$rend
## G = 2.37238, U = 0.74466, p-value = 0.1413
## alternative hypothesis: highest value 73 is an outlier
*No hay valores atipicos
plot(residuos, pch=16, cex=2)
grid()
datos3 = read_xlsx("C://Users//Grald//OneDrive//Documentos//DISEÑO EXPERIMENTOS//TALLER PARCIAL.xlsx", sheet = 3)
View(datos3)
as.factor(datos3$sitio)
## [1] norte norte norte centro centro centro sur sur sur
## Levels: centro norte sur
# Analisis descriptivo:
collapsibleTreeSummary(datos3,
c("sitio", "tiempo", "bloque"),
collapsed = FALSE)
ggplot(datos3)+
aes(sitio, tiempo, fill=sitio)+
geom_boxplot()
ggplot(datos3)+
aes(x=sitio, y=tiempo, fill=sitio)+
geom_col()
#ANOVA Modelo3
mod3 = aov(tiempo ~ bloque + sitio,
datos3)
summary(mod3)
## Df Sum Sq Mean Sq F value Pr(>F)
## bloque 1 42.67 42.67 4.848 0.0789 .
## sitio 2 229.56 114.78 13.043 0.0104 *
## Residuals 5 44.00 8.80
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
###MODELO DEL DISEÑO
\[Y_{ij}: \mu + \tau_{i} + \beta_j + \epsilon_{ij}\]
#Revisión de supuestos:
residuos = mod3$residuals
TukeyHSD(mod3, conf.level = 0.95)
## Warning in replications(paste("~", xx), data = mf): non-factors ignored: bloque
## Warning in TukeyHSD.aov(mod3, conf.level = 0.95): 'which' specified some
## non-factors which will be dropped
## Tukey multiple comparisons of means
## 95% family-wise confidence level
##
## Fit: aov(formula = tiempo ~ bloque + sitio, data = datos3)
##
## $sitio
## diff lwr upr p adj
## norte-centro 5.333333 -2.548031 13.2146978 0.1637485
## sur-centro -7.000000 -14.881364 0.8813645 0.0744269
## sur-norte -12.333333 -20.214698 -4.4519689 0.0087436
#Prueba de normalidad:
shapiro.test(residuos)
##
## Shapiro-Wilk normality test
##
## data: residuos
## W = 0.85397, p-value = 0.08239
#Prueba de homocedasticidad:
bartlett.test(residuos, datos3$sitio)
##
## Bartlett test of homogeneity of variances
##
## data: residuos and datos3$sitio
## Bartlett's K-squared = 0.060221, df = 2, p-value = 0.9703
#Prueba de datos atipicos:
grubbs.test(datos3$tiempo)
##
## Grubbs test for one outlier
##
## data: datos3$tiempo
## G = 1.83798, U = 0.52495, p-value = 0.18
## alternative hypothesis: highest value 96 is an outlier
plot(residuos, pch=16, cex=2)
grid()
datos4 = read_xlsx("C://Users//Grald//OneDrive//Documentos//DISEÑO EXPERIMENTOS//TALLER PARCIAL.xlsx", sheet = 4)
View(datos4)
as.factor(datos4$region)
## [1] R1 R1 R1 R2 R2 R2 R3 R3 R3
## Levels: R1 R2 R3
###MODELO DEL DISEÑO \[Y_{ijk}: \mu + \tau_{i} + \beta_j + \delta_k +\epsilon_{ijk}\] *
#Analisis descriptivo:
bwplot(ventas ~ producto | estacion + region, datos4)
ggplot(datos4)+
aes(producto, ventas, fill=producto)+
geom_boxplot()
collapsibleTreeSummary(datos4,
c("producto", "region", "estacion", "ventas"),
collapsed = FALSE)
#ANOVA Modelo4
mod4 = aov(ventas ~ region + estacion + producto,
datos4)
summary(mod4)
## Df Sum Sq Mean Sq F value Pr(>F)
## region 2 2163 1081 2.992 0.2505
## estacion 2 1506 753 2.083 0.3244
## producto 2 32380 16190 44.792 0.0218 *
## Residuals 2 723 361
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
*Al menos uno de los productos tiene efecto en las ventas.
#Revisión de supuestos
residuos = mod4$residuals
TukeyHSD(mod4, conf.level = 0.95)
## Tukey multiple comparisons of means
## 95% family-wise confidence level
##
## Fit: aov(formula = ventas ~ region + estacion + producto, data = datos4)
##
## $region
## diff lwr upr p adj
## R2-R1 23.00000 -68.44205 114.44205 0.4534211
## R3-R1 -14.66667 -106.10872 76.77538 0.6707084
## R3-R2 -37.66667 -129.10872 53.77538 0.2365160
##
## $estacion
## diff lwr upr p adj
## E2-E1 15.00000 -76.44205 106.44205 0.6607232
## E3-E1 -16.66667 -108.10872 74.77538 0.6121017
## E3-E2 -31.66667 -123.10872 59.77538 0.3046323
##
## $producto
## diff lwr upr p adj
## B-A 138.00000 46.55795 229.44205 0.0225911
## C-A 25.33333 -66.10872 116.77538 0.4061820
## C-B -112.66667 -204.10872 -21.22462 0.0335115
tt = TukeyC(mod4, "producto")
plot(tt)
* El mejor producto es el “C”
#Prueba de normalidad:
shapiro.test(residuos)
##
## Shapiro-Wilk normality test
##
## data: residuos
## W = 0.70608, p-value = 0.001671
#Prueba de homocedasticidad:
bartlett.test(residuos, datos4$producto)
##
## Bartlett test of homogeneity of variances
##
## data: residuos and datos4$producto
## Bartlett's K-squared = 2.9068e-15, df = 2, p-value = 1
#Prueba de datos atipicos:
grubbs.test(datos4$ventas)
##
## Grubbs test for one outlier
##
## data: datos4$ventas
## G = 1.60611, U = 0.63724, p-value = 0.3875
## alternative hypothesis: highest value 410 is an outlier
*No hay datos atipicos.
plot(residuos, pch=16, cex=2)
grid()
datos5 = read_xlsx("C://Users//Grald//OneDrive//Documentos//DISEÑO EXPERIMENTOS//TALLER PARCIAL.xlsx", sheet = 5)
View(datos5)
datos5$prof = as.factor(datos5$prof)
datos5$germinacion = as.numeric(datos5$germinacion)
###MODELO DEL DISEÑO: \[y_{ij} = \mu + \tau_{i} + \theta(x_{ij}-\bar{x}) + \epsilon_{ij}\] *Covarianza (teta)
###Hipotesis1:
\[H_0: \theta = 0 \] ###Hipotesis2: \[H_0: \mu_{s0} = \mu_{sf} = \mu_{si} = \mu_{sfi} \]
#ANCOVA modelo 5:
mod5 = aov(germinacion ~ CIC + CE + Ca_Mg + prof, datos5)
summary(mod5)
## Df Sum Sq Mean Sq F value Pr(>F)
## CIC 1 0.003 0.003 0.004 0.95332
## CE 1 14.137 14.137 19.789 0.00671 **
## Ca_Mg 1 2.924 2.924 4.093 0.09896 .
## prof 3 29.561 9.854 13.793 0.00747 **
## Residuals 5 3.572 0.714
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
CE y profundidad tienen impacto en en la germinación.
mod5b = aov(germinacion ~ CE + prof, datos5) summary(mod5b) mod5c = aov(germinacion ~ Ca_Mg + prof, datos) summary(mod5c)
#Analisis descriptivo:
ggplot(datos5)+
aes(prof, germinacion, fill=prof)+
geom_boxplot()
* A mayor profundidad de siembra mayor cantidad de días para la
germinación.
mod5= aov(germinacion ~ prof, data=datos5) summary(mod5) * Al menos uno de los tratamientos de profundidad de siembra tiene efecto sobre la germinación.
## Comparación de medias posterior al analisis de varianza
#Revision de supuestos.
residuos = mod5$residuals
TukeyHSD(mod5, conf.level = 0.95)
## Warning in replications(paste("~", xx), data = mf): non-factors ignored: CIC
## Warning in replications(paste("~", xx), data = mf): non-factors ignored: CE
## Warning in replications(paste("~", xx), data = mf): non-factors ignored: Ca_Mg
## Warning in TukeyHSD.aov(mod5, conf.level = 0.95): 'which' specified some
## non-factors which will be dropped
## Tukey multiple comparisons of means
## 95% family-wise confidence level
##
## Fit: aov(formula = germinacion ~ CIC + CE + Ca_Mg + prof, data = datos5)
##
## $prof
## diff lwr upr p adj
## f2-f1 0.70028257 -1.8461900 3.246755 0.7491551
## f3-f1 0.07084901 -2.4756236 2.617322 0.9995590
## f4-f1 3.58044806 1.0339755 6.126921 0.0130043
## f3-f2 -0.62943356 -3.1759062 1.917039 0.8003250
## f4-f2 2.88016549 0.3336929 5.426638 0.0314446
## f4-f3 3.50959905 0.9631265 6.056072 0.0141442
tt = TukeyC(mod5, "prof")
plot(tt)
##Normalidad:
shapiro.test(residuos)
##
## Shapiro-Wilk normality test
##
## data: residuos
## W = 0.99036, p-value = 0.9998
hist(mod5$residuals)
boxplot(mod5$residuals, pch=16)
# Revisando posible dato atipico
boxplot(germinacion ~ prof, datos5, pch=16)
#Homocedasticidad:
bartlett.test(residuos, datos5$prof)
##
## Bartlett test of homogeneity of variances
##
## data: residuos and datos5$prof
## Bartlett's K-squared = 2.4474, df = 3, p-value = 0.4849
#Revisión de datos atipicos:
grubbs.test(datos5$germinacion)
##
## Grubbs test for one outlier
##
## data: datos5$germinacion
## G = 1.53700, U = 0.76572, p-value = 0.665
## alternative hypothesis: lowest value 8.5 is an outlier
##INTERPRETACIÓN BIOLÓGICA La profundidad recomendada para la siembra es la f1 ya que es en donde las plantas germinan en una cantidad menor de dias