Import Data and Packages

require(readxl)
require(ggplot2)
require(plotly)
require(emmeans)
require(multcomp)
require(tidyverse)
require(ggpubr)
require(rstatix)
require(lmerTest)
require(Rmisc)

data=read_excel("C:/Users/Claudia Gallo/Desktop/Bioestadistica/dat3way.xlsx")
data$CO2=as.factor(data$CO2)
data$id=as.factor(paste(data$Cab,"_",data$Obvs,sep=""))

names(data)[4]="Genotype"

Flushing

Exploratoring Data

g1=ggplot(data,aes(x=CO2,y=Flushing,fill=Temp))+geom_boxplot()+facet_grid(~Genotype)+theme_bw()
g1

En la gráfica se observan diferencias entre las temperaturas principalmente y genotipos. Sin embargo, entre los niveles de CO2 no se logran evidenciar fuertes diferencias.

3 way Anova

anova=aov(Flushing~Temp*CO2*Genotype+Error(id/Genotype),data=data)
summary(anova)
## 
## Error: id
##           Df Sum Sq Mean Sq F value   Pr(>F)    
## Temp       2  698.7   349.3  61.892 2.25e-11 ***
## CO2        1    0.5     0.5   0.089    0.768    
## Temp:CO2   2   16.6     8.3   1.469    0.246    
## Residuals 30  169.3     5.6                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Error: id:Genotype
##                   Df Sum Sq Mean Sq F value  Pr(>F)   
## Genotype           1  88.89   88.89  12.945 0.00114 **
## Temp:Genotype      2  30.53   15.26   2.223 0.12583   
## CO2:Genotype       1   0.50    0.50   0.073 0.78913   
## Temp:CO2:Genotype  2  36.08   18.04   2.627 0.08882 . 
## Residuals         30 206.00    6.87                   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

El anova confirma que efectivamente existen diferencias significativas entre los niveles de la temperatura y el genotipo anidado.

Posanova - Temp & CO2

bxp=ggboxplot(data,x="Temp",y="Flushing",title="Flushing",xlab="Temp",ylab="Flushing",color="Temp",palette="lancet",facet.by="CO2")

pwc=data%>%group_by(CO2)%>%pairwise_t_test(Flushing~Temp,paired=TRUE,p.adjust.method="bonferroni")

pwc=pwc%>%add_xy_position(x="Temp")
bxp+stat_pvalue_manual(pwc,tip.length=0,hide.ns=TRUE)+labs(subtitle=paste("Anova,","F(2)","=","61.892,","p","=","<0.00001"),caption=get_pwc_label(pwc))

Se observa en general que existen diferencias entre los niveles de temperatura indicando que a menos temperatura el Flushing disminuye. Sin embargo, es más marcada esta diferencia en el nivel 700 de CO2 a pesar de que la interacción no es significativa.

Posanova - Genotype

bxp=ggboxplot(data,x="Genotype",y="Flushing",title="Flushing",xlab="Genotype",ylab="Flushing",color="Genotype",palette="lancet")

pwc=data%>%group_by()%>%pairwise_t_test(Flushing~Genotype,paired=TRUE,p.adjust.method="bonferroni")

pwc=pwc%>%add_xy_position(x="Genotype")
bxp+stat_pvalue_manual(pwc,tip.length=0,hide.ns=TRUE)+labs(subtitle=paste("Anova,","F(2)","=","12.945,","p","=","0.00114"),caption=get_pwc_label(pwc))

Se observan diferencias significativas entre los genotipos indicando que el SCA06 presenta mayor nivel de Flushing.

Supuesto de normalidad

data%>%group_by(Temp,CO2)%>%shapiro_test(Flushing)
## # A tibble: 6 x 5
##   CO2   Temp      variable statistic       p
##   <fct> <chr>     <chr>        <dbl>   <dbl>
## 1 400   31_22     Flushing     0.903 0.175  
## 2 700   31_22     Flushing     0.966 0.860  
## 3 400   33.5_24.5 Flushing     0.973 0.936  
## 4 700   33.5_24.5 Flushing     0.797 0.00864
## 5 400   36_27     Flushing     0.916 0.255  
## 6 700   36_27     Flushing     0.903 0.171

NLFlush

Exploratoring Data

g1=ggplot(data,aes(x=CO2,y=NLFlush,fill=Temp))+geom_boxplot()+facet_grid(~Genotype)+theme_bw()
g1

En la gráfica se observan diferencias entre las temperaturas principalmente y genotipos. Sin embargo, entre los niveles del CO2 no se logran evidenciar fuertes diferencias.

3 way Anova

anova=aov(NLFlush~Temp*CO2*Genotype+Error(id/Genotype),data=data)
summary(anova)
## 
## Error: id
##           Df Sum Sq Mean Sq F value  Pr(>F)   
## Temp       2  179.9   89.93   6.212 0.00553 **
## CO2        1    9.4    9.39   0.649 0.42699   
## Temp:CO2   2   38.9   19.43   1.342 0.27654   
## Residuals 30  434.3   14.48                   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Error: id:Genotype
##                   Df Sum Sq Mean Sq F value   Pr(>F)    
## Genotype           1 117.56  117.56  13.529 0.000917 ***
## Temp:Genotype      2  46.86   23.43   2.697 0.083756 .  
## CO2:Genotype       1  34.72   34.72   3.996 0.054734 .  
## Temp:CO2:Genotype  2  20.19   10.10   1.162 0.326519    
## Residuals         30 260.67    8.69                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

El anova confirma que efectivamente existen diferencias significativas entre los niveles de la temperatura y el genotipo anidado.

posanova - Temp & CO2

bxp=ggboxplot(data,x="Temp",y="NLFlush",title="NLFlush",xlab="Temp",ylab="NLFlush",color="Temp",palette="lancet",facet.by="CO2")

pwc=data%>%group_by(CO2)%>%pairwise_t_test(NLFlush~Temp,paired=TRUE,p.adjust.method="bonferroni")

pwc=pwc%>%add_xy_position(x="Temp")
bxp+stat_pvalue_manual(pwc,tip.length=0,hide.ns=TRUE)+labs(subtitle=paste("Anova,","F(2)","=","6.212,","p","=","0.00553"),caption=get_pwc_label(pwc))

Se observa en general que existen diferencias entre los niveles de temperatura indicando que a mayor temperatura el NLFlush aumenta. Sin embargo, es más marcada esta diferencia en el nivel 700 de CO2, en el otro nivel, 400, no se presentan diferencias.

posanova - Genotype

bxp=ggboxplot(data,x="Genotype",y="NLFlush",title="NLFlush",xlab="Genotype",ylab="NLFlush",color="Genotype",palette="lancet")

pwc=data%>%group_by()%>%pairwise_t_test(NLFlush~Genotype,paired=TRUE,p.adjust.method="bonferroni")

pwc=pwc%>%add_xy_position(x="Genotype")
bxp+stat_pvalue_manual(pwc,tip.length=0,hide.ns=TRUE)+labs(subtitle=paste("Anova,","F(2)","=","13.529,","p","=","0.000917"),caption=get_pwc_label(pwc))

Se observan diferencias significativas entre los genotipos indicando que el SCA06 presenta mayor nivel de NLFlush.

Supuesto de normalidad

data%>%group_by(Temp,CO2)%>%shapiro_test(NLFlush)
## # A tibble: 6 x 5
##   CO2   Temp      variable statistic      p
##   <fct> <chr>     <chr>        <dbl>  <dbl>
## 1 400   31_22     NLFlush      0.957 0.736 
## 2 700   31_22     NLFlush      0.870 0.0650
## 3 400   33.5_24.5 NLFlush      0.943 0.542 
## 4 700   33.5_24.5 NLFlush      0.970 0.916 
## 5 400   36_27     NLFlush      0.940 0.492 
## 6 700   36_27     NLFlush      0.842 0.0290

SD

Exploratoring Data

g1=ggplot(data,aes(x=CO2,y=SD,fill=Temp))+geom_boxplot()+facet_grid(~Genotype)+theme_bw()
g1

En las gráficas se observan diferencias entre las temperaturas en los 3 factores: Temp, CO2 y Genotipo.

3 way Anova

anova=aov(SD~Temp*CO2*Genotype+Error(id/Genotype),data=data)
summary(anova)
## 
## Error: id
##           Df Sum Sq Mean Sq F value   Pr(>F)    
## Temp       2 527672  263836  44.296 1.11e-09 ***
## CO2        1 203456  203456  34.159 2.15e-06 ***
## Temp:CO2   2   8428    4214   0.707    0.501    
## Residuals 30 178687    5956                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Error: id:Genotype
##                   Df  Sum Sq Mean Sq F value   Pr(>F)    
## Genotype           1 1797092 1797092 184.539 2.37e-14 ***
## Temp:Genotype      2   51165   25583   2.627   0.0889 .  
## CO2:Genotype       1    2768    2768   0.284   0.5979    
## Temp:CO2:Genotype  2   21846   10923   1.122   0.3390    
## Residuals         30  292148    9738                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

El anova confirma que efectivamente existen diferencias significativas entre los niveles de los tres factores.

#Posanova - Temp, CO2 & Genotype

bxp=ggboxplot(data,x="CO2",y="SD",title="SD",xlab="CO2",ylab="SD",color="Temp",palette="lancet",facet.by="Genotype")

pwc=data%>%group_by(CO2,Genotype)%>%pairwise_t_test(SD~Temp,paired=TRUE,p.adjust.method="bonferroni")

pwc=pwc%>%add_xy_position(x="CO2")
bxp+stat_pvalue_manual(pwc,tip.length=0,hide.ns=TRUE)+labs(subtitle=paste("Anova,","F(2)","=","44.296,","p","=","<0.00001"),caption=get_pwc_label(pwc))

Se observa en general que existen diferencias entre los niveles de temperatura indicando que la temperatura promedio 33.5 presenta los mayores niveles de SD.

posanova - Genotype

bxp=ggboxplot(data,x="Genotype",y="SD",title="SD",xlab="Genotype",ylab="SD",color="Genotype",palette="lancet")

pwc=data%>%group_by()%>%pairwise_t_test(SD~Genotype,paired=TRUE,p.adjust.method="bonferroni")

pwc=pwc%>%add_xy_position(x="Genotype")
bxp+stat_pvalue_manual(pwc,tip.length=0,hide.ns=TRUE)+labs(subtitle=paste("Anova,","F(2)","=","184.539,","p","=","<0.00001"),caption=get_pwc_label(pwc))

Supuesto de normalidad

data%>%group_by(Temp,CO2)%>%shapiro_test(SD)
## # A tibble: 6 x 5
##   CO2   Temp      variable statistic      p
##   <fct> <chr>     <chr>        <dbl>  <dbl>
## 1 400   31_22     SD           0.873 0.0710
## 2 700   31_22     SD           0.908 0.199 
## 3 400   33.5_24.5 SD           0.942 0.529 
## 4 700   33.5_24.5 SD           0.854 0.0416
## 5 400   36_27     SD           0.893 0.130 
## 6 700   36_27     SD           0.946 0.582