###Diseño cuadrado latino Guia RBLOGGERS (https://www.r-bloggers.com/2010/01/latin-squares-design-in-r/)

###Factorial simple en Bloques al azar (FSBA) * Un solo factor * Dos razones de bloqueo Razon de bloqueo: Lote Proveedor de semilla: Prov Variable continua cuantitativa: biom

lote = c(
          rep("L1", 1),
          rep("L2", 1),
          rep("L3", 1),
          rep("L4", 1),
          rep("L5", 1))
  
genotipo = c(
           rep("gA",5), 
           rep("gB",5), 
           rep("gC",5), 
           rep("gD",5), 
           rep("gE",5))


prov = c(
  "A","E","C","B","D", "C","B","A","D",
  "E", "B","C","D","E","A", "D","A","E",
  "C","B", "E","D","B","A","C")
  

biom = c(42,45,41,56,47, 47,54,
         46,52,49, 55,52,57,49,
         45, 51,44,47,50,54, 44,
         50,48,43,46)
data<- data.frame(lote, genotipo, prov, biom)

head(data)
##   lote genotipo prov biom
## 1   L1       gA    A   42
## 2   L2       gA    E   45
## 3   L3       gA    C   41
## 4   L4       gA    B   56
## 5   L5       gA    D   47
## 6   L1       gB    C   47

Graficos descriptivos

library(lattice)
bwplot(biom ~ lote|prov + lote, data)

Modelo \[y = \mu+ tau_i + \beta_j + \delta_k + \epsilon_{ijk}\] \(i=1,dots, p\) \(j=1.dots, p\) \(k=1,dots, p\)

tbl = matrix(data$prov, 5)
colnames (tbl)= unique (data$genotipo)
rownames (tbl) = unique (data$lote)

Hipotesis \[H_0: \mu_{B_{g_1}}=\mu_{B{g_2}} = \mu{B_{g_3}} = \mu_{B_{g_4}} = \mu_{B_{g_5}}\] Se rechaza la H0 porque los genotipos no son iguales.

mod <- lm(biom~lote+genotipo+prov, data)
anova(mod)
## Analysis of Variance Table
## 
## Response: biom
##           Df Sum Sq Mean Sq F value   Pr(>F)    
## lote       4  17.76   4.440  0.7967 0.549839    
## genotipo   4 109.36  27.340  4.9055 0.014105 *  
## prov       4 286.16  71.540 12.8361 0.000271 ***
## Residuals 12  66.88   5.573                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
bwplot(biom ~ genotipo | prov, 
       data)

interaction.plot(genotipo, 
                 prov,
                 biom,
                 lwd = 2)

plot(factor (genotipo) , biom, col = factor(prov))

library(ggplot2)
ggplot (data)+
  aes (genotipo,
       biom,
       fill=prov)+
  geom_col (
    position = 'dodge')

En términos agronomicos se elige el genotipo D usando el fertilizante C debido a que tiene menjores Revisión de supuestos

res_mod=mod$residuals

#1.Normalidad 
shapiro.test(res_mod)
## 
##  Shapiro-Wilk normality test
## 
## data:  res_mod
## W = 0.97691, p-value = 0.8178
#2. Igualdad de varianzas
bartlett.test(res_mod, 
              genotipo)
## 
##  Bartlett test of homogeneity of variances
## 
## data:  res_mod and genotipo
## Bartlett's K-squared = 5.9223, df = 4, p-value = 0.205
#Se cumple el supuest de varianzas iguales
library(TukeyC)
tt= TukeyC(mod, 'genotipo')
plot(tt)

Estadisticamente, analizando el grafico de TukeyC los genotipos A y E tiene malos rendimientos, por otro lado, el genotipo C es el que tiene mejor redimiento.