pacman::p_load(pacman,dplyr,GGally,ggplot2,ggthemes,ggvis,httr,lubridate,plotly,rio,rmarkdown,shiny,stringr,tidyr,tidyverse,lattice,caret,pls,MASS,yarrr,psych,ggcorrplot,GGally,CCA,CCP,rpart,rpart.plot,ggrepel)
library(tidyverse)
library(rpart)
library(rpart.plot)
library(caret)
library("rio")
df<-import("CafesFincasT.xlsx")

Pretratamiento de los datos

Cada uno de estos parámetros se convirtió al tipo factor

df <- df %>% filter(Dias>0)
df0<- df %>%  mutate(Temp=ifelse(T<24,"Finca_T",ifelse(T==24.0,"T24","T30")),Tiempo=ifelse(Dias<5,"Bajo","Alto"),Altura=ifelse(Altitud<1700,"H1","H2")) 

df0$Finca<-factor(df0$Finca)
df0$Tiempo<-factor(df0$Tiempo)
df0$Altura<-factor(df0$Altura)
df0$Temp<-factor(df0$Temp)
df3<-df0 %>% filter(Dias>=2)

boxplot(Puntaje~Finca,data=df0,col=c("blue","orange","red","green"))

ANOVA

model<-aov(Puntaje~Temp*Altura*Tiempo,data=df0)
summary(model)
##                    Df Sum Sq Mean Sq F value Pr(>F)    
## Temp                2   0.24    0.12   0.517 0.5994    
## Altura              1  63.84   63.84 274.008 <2e-16 ***
## Tiempo              1   0.54    0.54   2.339 0.1320    
## Temp:Altura         2   0.27    0.14   0.585 0.5604    
## Temp:Tiempo         2   0.48    0.24   1.020 0.3675    
## Altura:Tiempo       1   0.70    0.70   3.021 0.0879 .  
## Temp:Altura:Tiempo  2   1.75    0.87   3.750 0.0299 *  
## Residuals          54  12.58    0.23                   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
par(cex.axis=0.5)
boxplot(Puntaje~Temp+Altura+Tiempo,data=df0,col=c("green","orange","blue"))

PRUEBAS DE NORMALIDAD

qqnorm(model$residuals)
qqline(model$residuals,col="blue")

# Prueba de Normalidad Shapiro-Wilks

shapiro.test(model$residuals)
## 
##  Shapiro-Wilk normality test
## 
## data:  model$residuals
## W = 0.97353, p-value = 0.1698

El p-value>0.05 indica que podemos asumir que la distribución de los datos no es significativamente diferente a la distribución normal. En otras palabras los datos siguen una distribución normal

ggplot(df0, aes(x=Altura, y=Puntaje, fill=Temp)) + 
    geom_boxplot()+facet_wrap(~Tiempo)

Gráficos de Interacción

df0 %>% 
  group_by(Altura, Temp) %>% 
  summarise(P_groups = mean(Puntaje)) -> df2
## `summarise()` has grouped output by 'Altura'. You can override using the
## `.groups` argument.
df2
## # A tibble: 6 × 3
## # Groups:   Altura [2]
##   Altura Temp    P_groups
##   <fct>  <fct>      <dbl>
## 1 H1     Finca_T     86.8
## 2 H1     T24         86.4
## 3 H1     T30         86.5
## 4 H2     Finca_T     88.9
## 5 H2     T24         88.8
## 6 H2     T30         88.9
df2 %>% ggplot() +  aes(x = Altura, y = P_groups, color = Temp) +  geom_line(aes(group = Temp)) +  geom_point()

df0 %>% 
  group_by(Altura, Tiempo) %>% 
  summarise(P_groups = mean(Puntaje)) -> df2
## `summarise()` has grouped output by 'Altura'. You can override using the
## `.groups` argument.
df2
## # A tibble: 4 × 3
## # Groups:   Altura [2]
##   Altura Tiempo P_groups
##   <fct>  <fct>     <dbl>
## 1 H1     Alto       86.8
## 2 H1     Bajo       86.2
## 3 H2     Alto       88.9
## 4 H2     Bajo       88.8
df2 %>% ggplot() +  aes(x = Altura, y = P_groups, color = Tiempo) +  geom_line(aes(group = Tiempo)) +  geom_point()

df0 %>% 
  group_by(Temp, Tiempo) %>% 
  summarise(P_groups = mean(Puntaje)) -> df2
## `summarise()` has grouped output by 'Temp'. You can override using the
## `.groups` argument.
df2
## # A tibble: 6 × 3
## # Groups:   Temp [3]
##   Temp    Tiempo P_groups
##   <fct>   <fct>     <dbl>
## 1 Finca_T Alto       88.5
## 2 Finca_T Bajo       88.2
## 3 T24     Alto       88.3
## 4 T24     Bajo       88.2
## 5 T30     Alto       88.4
## 6 T30     Bajo       87.9
df2 %>% ggplot() +  aes(x = Temp, y = P_groups, color = Tiempo) +  geom_line(aes(group = Tiempo)) +  geom_point()

Efecto del Tiempo de Fermentación a diferentes temperaturas sobre el puntaje del café

library(ggrepel)
library(ggplot2)



df1<- df %>% group_by(Finca,Dias) %>% summarize(Puntaje=mean(Puntaje),Altitud=Altitud,Temp=T)
## `summarise()` has grouped output by 'Finca', 'Dias'. You can override using the
## `.groups` argument.
df1
## # A tibble: 66 × 5
## # Groups:   Finca, Dias [34]
##    Finca     Dias Puntaje Altitud  Temp
##    <chr>    <dbl>   <dbl>   <dbl> <dbl>
##  1 Corpachi   3      86.4    1375  20.6
##  2 Corpachi   3      86.4    1375  24  
##  3 Corpachi   3      86.4    1375  30  
##  4 Corpachi   4      86.0    1375  20.6
##  5 Corpachi   4      86.0    1375  24  
##  6 Corpachi   4      86.0    1375  30  
##  7 Corpachi   5      86.7    1375  20.6
##  8 Corpachi   5      86.7    1375  24  
##  9 Corpachi   5      86.7    1375  30  
## 10 Corpachi   5.5    88.5    1375  30  
## # ℹ 56 more rows
g = df1 %>% ggplot() +  aes(x = Dias, y = Puntaje, color = Finca) +  geom_line(aes(group = Finca)) +geom_point() 
g +labs(x="Tiempo de Fermentación",y="Puntaje")+facet_wrap(~Temp)