Diseño Factorial simple
area = área de daño foliar
set.seed(22)
area = c(rnorm(18, 3, 0.8),
rnorm(6, 0.2, 0.05))
inoculo = gl(4, 6, 24, paste0('D', 0:3))
dt = data.frame(area = round(sort(area), 3),
inoculo)
head(dt)
## area inoculo
## 1 0.119 D0
## 2 0.148 D0
## 3 0.166 D0
## 4 0.171 D0
## 5 0.200 D0
## 6 0.247 D0
Comparación de medias
boxplot(dt$area~dt$inoculo)
Hipótesis
\[H_0: \mu_{D0} = \mu_{D1}= \cdots = \mu_{D3}\]
mod_1 = aov(dt$area~dt$inoculo)
tb = summary(mod_1)
ifelse(unlist(tb)[9] < 0.05, 'Rechazo Ho',
'No rechazo Ho')
## Pr(>F)1
## "Rechazo Ho"
## Pr(>F)1
## "Rechazo Ho"
Prueba de comparaciones de Turkey
TukeyHSD(x = mod_1)
## Tukey multiple comparisons of means
## 95% family-wise confidence level
##
## Fit: aov(formula = dt$area ~ dt$inoculo)
##
## $`dt$inoculo`
## diff lwr upr p adj
## D1-D0 2.3715000 1.84876038 2.894240 0.0000000
## D2-D0 2.8731667 2.35042705 3.395906 0.0000000
## D3-D0 4.0190000 3.49626038 4.541740 0.0000000
## D2-D1 0.5016667 -0.02107295 1.024406 0.0628165
## D3-D1 1.6475000 1.12476038 2.170240 0.0000001
## D3-D2 1.1458333 0.62309372 1.668573 0.0000299
Modelo del diseño
\[y_{ij} = \mu + \tau_i + \epsilon_{ij} i=1,2,3,4~(inoculo) j=1,2,\cdots,6~(repeticiones)\]
Revisión de supuestos Normalidad \[[H_0:~los~residuales~del~modelo~tienen~distribución~normal\]
res = mod_1$residuals
n = shapiro.test(res)
n
##
## Shapiro-Wilk normality test
##
## data: res
## W = 0.97101, p-value = 0.692
#No rechazo Ho, los residuales se distribuyen normalmente pvalor>0.05
Homoceasticidad de varianza \[var~_{D_0} = var~_{D_1} = \cdots = var~_{D_4}\]
bartlett.test(dt$area~dt$inoculo)
##
## Bartlett test of homogeneity of variances
##
## data: dt$area by dt$inoculo
## Bartlett's K-squared = 22.055, df = 3, p-value = 6.355e-05
#Rechazo Ho: varianzas por grupo son distintas, No se cumple el supuesto de homocedasticidad. Pvalor < 0.05
ANALISIS DE VARIANZA CON VARIANZAS DESIGUALES (ANOVA DE WELCH)
mod_2 = oneway.test(dt$area~dt$inoculo)
mod_2
##
## One-way analysis of means (not assuming equal variances)
##
## data: dt$area and dt$inoculo
## F = 727.7, num df = 3.0000, denom df = 8.8951, p-value = 5.925e-11
ANALISIS DE VARIANZA NO PARAMETRICO (KRUSKAL WALLIS)
mod_3 = kruskal.test(dt$area~dt$inoculo)
mod_3
##
## Kruskal-Wallis rank sum test
##
## data: dt$area by dt$inoculo
## Kruskal-Wallis chi-squared = 21.6, df = 3, p-value = 7.9e-05
ANOVA PERMUTACIONAL
mod_4 = RVAideMemoire::perm.anova(dt$area~dt$inoculo, nperm = 5000)
##
|
| | 0%
|
|= | 1%
|
|= | 2%
|
|== | 3%
|
|=== | 4%
|
|==== | 5%
|
|==== | 6%
|
|===== | 7%
|
|====== | 8%
|
|====== | 9%
|
|======= | 10%
|
|======== | 11%
|
|======== | 12%
|
|========= | 13%
|
|========== | 14%
|
|========== | 15%
|
|=========== | 16%
|
|============ | 17%
|
|============= | 18%
|
|============= | 19%
|
|============== | 20%
|
|=============== | 21%
|
|=============== | 22%
|
|================ | 23%
|
|================= | 24%
|
|================== | 25%
|
|================== | 26%
|
|=================== | 27%
|
|==================== | 28%
|
|==================== | 29%
|
|===================== | 30%
|
|====================== | 31%
|
|====================== | 32%
|
|======================= | 33%
|
|======================== | 34%
|
|======================== | 35%
|
|========================= | 36%
|
|========================== | 37%
|
|=========================== | 38%
|
|=========================== | 39%
|
|============================ | 40%
|
|============================= | 41%
|
|============================= | 42%
|
|============================== | 43%
|
|=============================== | 44%
|
|================================ | 45%
|
|================================ | 46%
|
|================================= | 47%
|
|================================== | 48%
|
|================================== | 49%
|
|=================================== | 50%
|
|==================================== | 51%
|
|==================================== | 52%
|
|===================================== | 53%
|
|====================================== | 54%
|
|====================================== | 55%
|
|======================================= | 56%
|
|======================================== | 57%
|
|========================================= | 58%
|
|========================================= | 59%
|
|========================================== | 60%
|
|=========================================== | 61%
|
|=========================================== | 62%
|
|============================================ | 63%
|
|============================================= | 64%
|
|============================================== | 65%
|
|============================================== | 66%
|
|=============================================== | 67%
|
|================================================ | 68%
|
|================================================ | 69%
|
|================================================= | 70%
|
|================================================== | 71%
|
|================================================== | 72%
|
|=================================================== | 73%
|
|==================================================== | 74%
|
|==================================================== | 75%
|
|===================================================== | 76%
|
|====================================================== | 77%
|
|======================================================= | 78%
|
|======================================================= | 79%
|
|======================================================== | 80%
|
|========================================================= | 81%
|
|========================================================= | 82%
|
|========================================================== | 83%
|
|=========================================================== | 84%
|
|============================================================ | 85%
|
|============================================================ | 86%
|
|============================================================= | 87%
|
|============================================================== | 88%
|
|============================================================== | 89%
|
|=============================================================== | 90%
|
|================================================================ | 91%
|
|================================================================ | 92%
|
|================================================================= | 93%
|
|================================================================== | 94%
|
|================================================================== | 95%
|
|=================================================================== | 96%
|
|==================================================================== | 97%
|
|===================================================================== | 98%
|
|===================================================================== | 99%
|
|======================================================================| 100%
mod_4
## Permutation Analysis of Variance Table
##
## Response: dt$area
## 5000 permutations
## Sum Sq Df Mean Sq F value Pr(>F)
## dt$inoculo 51.465 3 17.1552 163.94 2e-04 ***
## Residuals 2.093 20 0.1046
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
ANOVA desbalanceado
dt_2 = dt
dt_2$area[15] = NA
library(car)
## Loading required package: carData
mod_5 = Anova(lm(dt_2$area~dt_2$inoculo),
type = 'II')
mod_5
## Anova Table (Type II tests)
##
## Response: dt_2$area
## Sum Sq Df F value Pr(>F)
## dt_2$inoculo 51.261 3 156.04 1.464e-13 ***
## Residuals 2.081 19
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1