Diseño 2 incumplimiento de supuestos

# Factor
genotipo = gl(n = 6, k = 6, length = 36,
              labels = paste0('gen', 1:6))

              
# Variable respuesta 
set.seed(123)
PS = c(
  rnorm(12, 1200, 120),
  rnorm(12, 1500, 100),
  rnorm(12, 1420, 250)
)

aleat = sample(36)
datos = data.frame(genotipo, PS)
head(datos)
##   genotipo       PS
## 1     gen1 1132.743
## 2     gen1 1172.379
## 3     gen1 1387.045
## 4     gen1 1208.461
## 5     gen1 1215.515
## 6     gen1 1405.808
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.2.3
ggplot(datos)+
  aes(genotipo, PS)+
  geom_boxplot()

mod1b = aov(PS ~ genotipo, datos)
smod1b = summary(mod1b)

shapiro.test(mod1b$residuals)
## 
##  Shapiro-Wilk normality test
## 
## data:  mod1b$residuals
## W = 0.98349, p-value = 0.8558
bartlett.test(mod1b$residuals, datos$genotipo)
## 
##  Bartlett test of homogeneity of variances
## 
## data:  mod1b$residuals and datos$genotipo
## Bartlett's K-squared = 12.401, df = 5, p-value = 0.02969

*Como se rechaza la hipotesis nula de igualdad de variazan se incumple el supuesto lo cual complica la interpretación.

Analisis de varianza para un diseño factorial simple en arreglo completamente al azar en presencia de heterocedasticidad (en presencia de varianzas desiguales):

mod1c =oneway.test(PS ~ genotipo, datos)
mod1c
## 
##  One-way analysis of means (not assuming equal variances)
## 
## data:  PS and genotipo
## F = 8.6764, num df = 5.000, denom df = 13.702, p-value = 0.0006918

Cuando se incumple normalidade igualdad de varianzas (Prueba de Kruskal para cuando no se cumplen los dos supuestos): permite comparar los tratamientos

*Analisis de varianza no parametrico para un diseño en arreglo factorial simple en arreglo completamente al azar

\[H_0: R1=R2=R3=R4=R5=R6=\]

mod1d = kruskal.test(PS, genotipo)
mod1d
## 
##  Kruskal-Wallis rank sum test
## 
## data:  PS and genotipo
## Kruskal-Wallis chi-squared = 17.204, df = 5, p-value = 0.004128
# library(PMCMR)
# posthoc.kruskal.nemenyi.test(PS, genotipo)
library(PMCMRplus)
## Warning: package 'PMCMRplus' was built under R version 4.2.3
kwAllPairsNemenyiTest(PS, genotipo)
## 
##  Pairwise comparisons using Tukey-Kramer-Nemenyi all-pairs test with Tukey-Dist approximation
## data: PS and genotipo
##      gen1  gen2  gen3  gen4  gen5 
## gen2 0.998 -     -     -     -    
## gen3 0.172 0.058 -     -     -    
## gen4 0.443 0.205 0.995 -     -    
## gen5 0.807 0.533 0.883 0.993 -    
## gen6 0.046 0.012 0.995 0.904 0.587
## 
## P value adjustment method: single-step
## alternative hypothesis: two.sided
library(FSA)
## Warning: package 'FSA' was built under R version 4.2.3
## ## FSA v0.9.4. See citation('FSA') if used in publication.
## ## Run fishR() for related website and fishR('IFAR') for related book.
dunnTest(PS, genotipo)
## Dunn (1964) Kruskal-Wallis multiple comparison
##   p-values adjusted with the Holm method.
##     Comparison          Z      P.unadj      P.adj
## 1  gen1 - gen2  0.4383973 0.6610983037 0.66109830
## 2  gen1 - gen3 -2.3563855 0.0184537565 0.22144508
## 3  gen2 - gen3 -2.7947828 0.0051934597 0.06751498
## 4  gen1 - gen4 -1.8357887 0.0663889146 0.66388915
## 5  gen2 - gen4 -2.2741860 0.0229548062 0.25250287
## 6  gen3 - gen4  0.5205968 0.6026476838 1.00000000
## 7  gen1 - gen5 -1.2603922 0.2075279011 1.00000000
## 8  gen2 - gen5 -1.6987895 0.0893588460 0.80422961
## 9  gen3 - gen5  1.0959932 0.2730817290 1.00000000
## 10 gen4 - gen5  0.5753965 0.5650232007 1.00000000
## 11 gen1 - gen6 -2.8769823 0.0040149814 0.05620974
## 12 gen2 - gen6 -3.3153796 0.0009151876 0.01372781
## 13 gen3 - gen6 -0.5205968 0.6026476838 1.00000000
## 14 gen4 - gen6 -1.0411936 0.2977857118 1.00000000
## 15 gen5 - gen6 -1.6165900 0.1059668029 0.84773442
rangos = rank(PS, ties.method = 'average')
rangos
##  [1]  4  7 16  8  9 19 11  2  3  6 15 10 27 25 21 35 28 13 29 22 17 24 18 20 12
## [26]  1 32 23  5 36 26 14 34 33 31 30
boxplot(rangos ~ genotipo)

Analisis de varianza permutacional

Se corre el analisis de varianza haciendo simulación,

library(RVAideMemoire)
## Warning: package 'RVAideMemoire' was built under R version 4.2.3
## *** Package RVAideMemoire v 0.9-81-2 ***
## 
## Attaching package: 'RVAideMemoire'
## The following object is masked from 'package:FSA':
## 
##     se
perm.anova(PS ~ genotipo, data = datos, nperm = 999)
## 
  |                                                                            
  |                                                                      |   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%
## Permutation Analysis of Variance Table
## 
## Response: PS
## 999 permutations
##           Sum Sq Df Mean Sq F value Pr(>F)    
## genotipo  627712  5  125542  5.3717  0.001 ***
## Residuals 701126 30   23371                   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Rechaza la hipotesis nula, los genotipos son diferentes.