3^2 factorial design

library(agricolae)
## Warning: package 'agricolae' was built under R version 4.4.3
library(readxl)
## Warning: package 'readxl' was built under R version 4.4.3
datos <- read_xlsx("resultados1.xlsx", sheet = "Hoja3")
datos$imb1 <- factor(datos$Imbibicion)
datos$gib1 <- factor(datos$GA3)
anova <- aov(Porcentaje ~ imb1*gib1,data=datos)
##             Df Sum Sq Mean Sq F value   Pr(>F)    
## imb1         2   9495    4747  73.949 2.08e-09 ***
## gib1         2    991     495   7.718  0.00380 ** 
## imb1:gib1    4   1379     345   5.372  0.00501 ** 
## Residuals   18   1156      64                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
boxplot(datos$Porcentaje ~ datos$Imbibicion, xlab = 'Imbibition time', ylab = '% Germination', col ="pink")

boxplot(datos$Porcentaje ~ datos$GA3, xlab = 'GA3 ppm Concentration', ylab = '% Germination', col = "pink")

interaction.plot(datos$Imbibicion, datos$GA3, datos$Porcentaje, xlab = 'Imbibition time',
                 ylab = '% Germination', trace.label = 'GA3 ppm Concentration', 
                 col = c("blue", "red", "green"), 
                 lty = 1, 
                 lwd = 2, 
                 main = "Interaction between Imbibition and GA3 in Percentage")

residuales<-anova$residuals
bartlett.test(anova$residuals, datos$Imbibicion)  
## 
##  Bartlett test of homogeneity of variances
## 
## data:  anova$residuals and datos$Imbibicion
## Bartlett's K-squared = 0.56193, df = 2, p-value = 0.7551
bartlett.test(anova$residuals, datos$GA3)
## 
##  Bartlett test of homogeneity of variances
## 
## data:  anova$residuals and datos$GA3
## Bartlett's K-squared = 3.2811, df = 2, p-value = 0.1939
shapiro.test(anova$residuals)  
## 
##  Shapiro-Wilk normality test
## 
## data:  anova$residuals
## W = 0.97077, p-value = 0.6223

Obtaining coefficients to characterize the type of curvature

TL <- rep(0,27)
TC <- rep(0,27)
for(i in 1:27)
{
  if(datos$Imbibicion[i] == 0) #nivel bajo
  {TL[i] <- -1 } 
  else {
    if(datos$Imbibicion[i] == 12) #nivel alto
    {TL[i] <- 1  }
  }
  if(datos$Imbibicion[i] == 0)
  {TC[i] <- 1 } 
  else {
    if(datos$Imbibicion[i] == 6) #nivel medio
    {TC[i] <- -2  }
    else {
      if(datos$Imbibicion[i] == 12)
      {TC[i] <- 1  }
    }
  }
}
SL <- rep(0,27)
SC <- rep(0,27)
for(i in 1:27)
{
  if(datos$GA3[i] == 0)
  {SL[i] <- -1 } 
  else {
    if(datos$GA3[i] == 6)
    {SL[i] <- 1  }
  }
  if(datos$GA3[i] == 0)
  {SC[i] <- 1 } 
  else {
    if(datos$GA3[i] == 6)
    {SC[i] <- 1  }
    else {
      if(datos$GA3[i] == 3)
      {SC[i] <- -2  }
    }}}
TLSL <- TL*SL
TLSC <- TL*SC
TCSL <- TC*SL
TCSC <- TC*SC

Regression analysis for the characterization of curvature

anova1 <- aov(datos$Porcentaje ~ TL+TC+SL+SC+TLSL+TLSC+TCSL+TCSC)
summary(anova1)
##             Df Sum Sq Mean Sq F value   Pr(>F)    
## TL           1   9491    9491 147.846 4.08e-10 ***
## TC           1      3       3   0.051 0.823399    
## SL           1    988     988  15.385 0.000998 ***
## SC           1      3       3   0.051 0.823399    
## TLSL         1    300     300   4.673 0.044356 *  
## TLSC         1     31      31   0.481 0.496925    
## TCSL         1    357     357   5.558 0.029921 *  
## TCSC         1    692     692  10.776 0.004137 ** 
## Residuals   18   1156      64                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
modelo.lm2 = lm (datos$Porcentaje ~ TL+TC+SL+SC+TLSL+TLSC+TCSL+TCSC)
summary(modelo.lm2)
## 
## Call:
## lm(formula = datos$Porcentaje ~ TL + TC + SL + SC + TLSL + TLSC + 
##     TCSL + TCSC)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -13.333  -4.444  -2.222   4.444  13.333 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  39.7531     1.5420  25.781 1.16e-15 ***
## TL           22.9630     1.8885  12.159 4.08e-10 ***
## TC            0.2469     1.0903   0.226 0.823399    
## SL            7.4074     1.8885   3.922 0.000998 ***
## SC            0.2469     1.0903   0.226 0.823399    
## TLSL          5.0000     2.3130   2.162 0.044356 *  
## TLSC          0.9259     1.3354   0.693 0.496925    
## TCSL          3.1481     1.3354   2.357 0.029921 *  
## TCSC          2.5309     0.7710   3.283 0.004137 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 8.012 on 18 degrees of freedom
## Multiple R-squared:  0.9113, Adjusted R-squared:  0.8718 
## F-statistic:  23.1 on 8 and 18 DF,  p-value: 5.855e-08
modelo.lm3 = lm (datos$Porcentaje ~ TL+TC+SL+SC+TLSL+TCSL+TCSC) 
summary(modelo.lm3)
## 
## Call:
## lm(formula = datos$Porcentaje ~ TL + TC + SL + SC + TLSL + TCSL + 
##     TCSC)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -13.333  -4.444  -1.296   4.444  13.333 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  39.7531     1.5208  26.140 2.34e-16 ***
## TL           22.9630     1.8625  12.329 1.64e-10 ***
## TC            0.2469     1.0753   0.230 0.820845    
## SL            7.4074     1.8625   3.977 0.000807 ***
## SC            0.2469     1.0753   0.230 0.820845    
## TLSL          5.0000     2.2811   2.192 0.041047 *  
## TCSL          3.1481     1.3170   2.390 0.027347 *  
## TCSC          2.5309     0.7604   3.328 0.003532 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 7.902 on 19 degrees of freedom
## Multiple R-squared:  0.9089, Adjusted R-squared:  0.8753 
## F-statistic: 27.07 on 7 and 19 DF,  p-value: 1.341e-08

Confidence interval for the regression betas

confint(modelo.lm2,level = 0.95)
##                  2.5 %    97.5 %
## (Intercept) 36.5135175 42.992655
## TL          18.9953176 26.930608
## TC          -2.0438075  2.537635
## SL           3.4397620 11.375053
## SC          -2.0438075  2.537635
## TLSL         0.1406467  9.859353
## TLSC        -1.8796230  3.731475
## TCSL         0.3425992  5.953697
## TCSC         0.9110798  4.150649

CONTOUR AND RESPONSE SURFACE GRAPH

imbp=seq(0,12,length.out=50)
giba=seq(0,6,length.out=50)

We generate two equally spaced numeric sequences (imbp and giba) with 50 values each. These sequences define the resolution of the axes for the contour and response surface plots.

f1=function(imbp,giba){
    modelo.lm3$coe[1]+
    modelo.lm3$coe[2]*I((imbp-6)/6)+
    modelo.lm3$coe[3]*I(-2+3*((imbp-6)/6)^2)+
    modelo.lm3$coe[4]*I((giba-3)/3)+
    modelo.lm3$coe[5]*I(-2+3*((giba-3)/3)^2)+
    modelo.lm3$coe[6]*I((imbp-6)/6)*I((giba-3)/3)+
    modelo.lm3$coe[7]*I(-2+3*((imbp-6)/6)^2)*I((giba-3)/3)+
    modelo.lm3$coe[8]*I(-2+3*((imbp-6)/6)^2)*I(-2+3*((giba-3)/3)^2)
  }
z1= outer(imbp,giba,f1)
par(mfrow = c(1,2))
persp(imbp,giba,z1,col=rainbow(50),theta=30,phi=10,ticktype='detailed',zlab='Germination %', xlab = 'Imbibition h',ylab='GA ppm')
image(imbp,giba,z1,xlab='Imbibition h',ylab='GA ppm')
contour(imbp,giba,z1,xlab='Imbibition h',ylab='GA ppm',add=TRUE)

## Post-hoc analysis

tukey_result <- HSD.test(anova2, trt = "interaction", group = TRUE, console = TRUE)
## 
## Study: anova2 ~ "interaction"
## 
## HSD Test for Porcentaje 
## 
## Mean Square Error:  64.19753 
## 
## interaction,  means
## 
##      Porcentaje       std r       se       Min      Max      Q25      Q50
## 0.0    13.33333  6.666667 3 4.625924  6.666667 20.00000 10.00000 13.33333
## 0.3    13.33333  6.666667 3 4.625924  6.666667 20.00000 10.00000 13.33333
## 0.6    24.44444  7.698004 3 4.625924 20.000000 33.33333 20.00000 20.00000
## 12.0   51.11111  7.698004 3 4.625924 46.666667 60.00000 46.66667 46.66667
## 12.3   55.55556  3.849002 3 4.625924 53.333333 60.00000 53.33333 53.33333
## 12.6   82.22222 10.183502 3 4.625924 73.333333 93.33333 76.66667 80.00000
## 6.0    33.33333 13.333333 3 4.625924 20.000000 46.66667 26.66667 33.33333
## 6.3    48.88889  3.849002 3 4.625924 46.666667 53.33333 46.66667 46.66667
## 6.6    35.55556  7.698004 3 4.625924 26.666667 40.00000 33.33333 40.00000
##           Q75
## 0.0  16.66667
## 0.3  16.66667
## 0.6  26.66667
## 12.0 53.33333
## 12.3 56.66667
## 12.6 86.66667
## 6.0  40.00000
## 6.3  50.00000
## 6.6  40.00000
## 
## Alpha: 0.05 ; DF Error: 18 
## Critical Value of Studentized Range: 4.955209 
## 
## Minimun Significant Difference: 22.92242 
## 
## Treatments with the same letter are not significantly different.
## 
##      Porcentaje groups
## 12.6   82.22222      a
## 12.3   55.55556      b
## 12.0   51.11111      b
## 6.3    48.88889      b
## 6.6    35.55556     bc
## 6.0    33.33333     bc
## 0.6    24.44444      c
## 0.0    13.33333      c
## 0.3    13.33333      c

We perform multiple comparisons Tukey to evaluate differences between treatment levels.