install.packages("readxl")
## Installing package into '/cloud/lib/x86_64-pc-linux-gnu-library/4.6'
## (as 'lib' is unspecified)
install.packages("tidyverse")
## Installing package into '/cloud/lib/x86_64-pc-linux-gnu-library/4.6'
## (as 'lib' is unspecified)
install.packages("skimr")
## Installing package into '/cloud/lib/x86_64-pc-linux-gnu-library/4.6'
## (as 'lib' is unspecified)
install.packages("summarytools")
## Installing package into '/cloud/lib/x86_64-pc-linux-gnu-library/4.6'
## (as 'lib' is unspecified)
install.packages("car")
## Installing package into '/cloud/lib/x86_64-pc-linux-gnu-library/4.6'
## (as 'lib' is unspecified)
install.packages("agricolae")
## Installing package into '/cloud/lib/x86_64-pc-linux-gnu-library/4.6'
## (as 'lib' is unspecified)
install.packages("emmeans")
## Installing package into '/cloud/lib/x86_64-pc-linux-gnu-library/4.6'
## (as 'lib' is unspecified)
install.packages("ggplot2")
## Installing package into '/cloud/lib/x86_64-pc-linux-gnu-library/4.6'
## (as 'lib' is unspecified)
install.packages("paletteer")
## Installing package into '/cloud/lib/x86_64-pc-linux-gnu-library/4.6'
## (as 'lib' is unspecified)
library(readxl)
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.2.1     ✔ readr     2.2.0
## ✔ forcats   1.0.1     ✔ stringr   1.6.0
## ✔ ggplot2   4.0.4     ✔ tibble    3.3.1
## ✔ lubridate 1.9.5     ✔ tidyr     1.3.2
## ✔ purrr     1.2.2     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(skimr)
library(summarytools)
## Warning in fun(libname, pkgname): couldn't connect to display ":0"
## system might not have X11 capabilities; in case of errors when using dfSummary(), set st_options(use.x11 = FALSE)
## 
## Attaching package: 'summarytools'
## 
## The following object is masked from 'package:tibble':
## 
##     view
library(car)
## Loading required package: carData
## 
## Attaching package: 'car'
## 
## The following object is masked from 'package:dplyr':
## 
##     recode
## 
## The following object is masked from 'package:purrr':
## 
##     some
library(agricolae)
library(emmeans)
## Welcome to emmeans.
## Caution: You lose important information if you filter this package's results.
## See '? untidy'
library(ggplot2)
library(paletteer)
DATOS_SUELO <- read_excel("datos_suelo1.xlsx")
# EXPLORACION BASE DE DATOS
str(DATOS_SUELO)
## tibble [19 × 8] (S3: tbl_df/tbl/data.frame)
##  $ MUESTRAS           : chr [1:19] "T1-R0" "T1-R1" "T1-R2-R3" "T2-R0-R1" ...
##  $ BIOESTIMULANTE     : num [1:19] 0 0 0 1 1 1 2 2 2 0 ...
##  $ SALINIDAD_AGUA     : num [1:19] 0 0 0 0 0 0 0 0 0 3.6 ...
##  $ TRATAMIENTOS_TOMATE: chr [1:19] "B0_S0" "B0_S0" "B0_S0" "B1_S0" ...
##  $ PROFUNDIDAD        : chr [1:19] "Superficie" "Medio" "Base" "Superficie" ...
##  $ MUESTRA_SUP        : chr [1:19] "T1M1" "T1M2" "T1M3" "T2M1" ...
##  $ PH                 : num [1:19] 6.2 6.2 6.7 6.2 6.5 7 6.3 6.5 6.7 6.2 ...
##  $ CE                 : num [1:19] 0.3 0.3 0.2 0.3 0.2 0.1 0.3 0.2 0.1 0.7 ...
# CAMBIAMOS LOS chr POR factor
SUELO <- DATOS_SUELO %>% 
  mutate(
    MUESTRAS = factor(MUESTRAS),
    BIOESTIMULANTE = factor(BIOESTIMULANTE),
    SALINIDAD_AGUA = factor(SALINIDAD_AGUA),
    TRATAMIENTOS_TOMATE = factor(TRATAMIENTOS_TOMATE),
    PROFUNDIDAD = factor(PROFUNDIDAD),
    MUESTRA_SUP = factor(MUESTRA_SUP))
str(SUELO)
## tibble [19 × 8] (S3: tbl_df/tbl/data.frame)
##  $ MUESTRAS           : Factor w/ 18 levels "T1-R0","T1-R1",..: 1 2 3 4 5 6 7 8 9 11 ...
##  $ BIOESTIMULANTE     : Factor w/ 3 levels "0","1","2": 1 1 1 2 2 2 3 3 3 1 ...
##  $ SALINIDAD_AGUA     : Factor w/ 2 levels "0","3.6": 1 1 1 1 1 1 1 1 1 2 ...
##  $ TRATAMIENTOS_TOMATE: Factor w/ 6 levels "B0_S0","B0_S3",..: 1 1 1 3 3 3 5 5 5 2 ...
##  $ PROFUNDIDAD        : Factor w/ 3 levels "Base","Medio",..: 3 2 1 3 2 1 3 2 1 3 ...
##  $ MUESTRA_SUP        : Factor w/ 19 levels "T1M1","T1M2",..: 1 2 3 4 5 6 7 8 9 10 ...
##  $ PH                 : num [1:19] 6.2 6.2 6.7 6.2 6.5 7 6.3 6.5 6.7 6.2 ...
##  $ CE                 : num [1:19] 0.3 0.3 0.2 0.3 0.2 0.1 0.3 0.2 0.1 0.7 ...

DCA: INTERACCION BIOESTIMULANTE x SALINIDAD EN AGUA

Modelo Matemático

yijk=μ+α+βj+αβij+εijk

Donde:

μ: media general del experimento,

αi: efecto debido al i -ésimo nivel del factor A,

βj: efecto del j -ésimo nivel del factor B,

αβij: representa el efecto de interacción de la combinación ij ,

εijk: el error aleatorio

HIPOTESIS DE TRABAJO

Interacción entre los factores:

\[ H_0:(\alpha\beta)_{ij}=0 \]

\[ H_1:(\alpha\beta)_{ij}\neq 0 \]

DATOS pH

st_options(lang = "es")
SUELO %>% 
  group_by(TRATAMIENTOS_TOMATE) %>% 
  descr(PH)
## Estadísticas descriptivas  
## PH por TRATAMIENTOS_TOMATE  
## Data frame: SUELO  
## N: 19  
## 
##                       B0_S0    B0_S3    B1_S0    B1_S3    B2_S0    B2_S3       NA
## ------------------ -------- -------- -------- -------- -------- -------- --------
##              Media     6.37     6.13     6.57     6.17     6.50     6.20     6.80
##           Dev.std.     0.29     0.06     0.40     0.06     0.20     0.10       NA
##                Min     6.20     6.10     6.20     6.10     6.30     6.10     6.80
##                 Q1     6.20     6.10     6.20     6.10     6.30     6.10     6.80
##            Mediana     6.20     6.10     6.50     6.20     6.50     6.20     6.80
##                 Q3     6.70     6.20     7.00     6.20     6.70     6.30     6.80
##                Max     6.70     6.20     7.00     6.20     6.70     6.30     6.80
##                DAP     0.00     0.00     0.44     0.00     0.30     0.15     0.00
##                 RI     0.25     0.05     0.40     0.05     0.20     0.10     0.00
##                 CV     0.05     0.01     0.06     0.01     0.03     0.02       NA
##          Asimetría     0.38     0.38     0.16    -0.38     0.00     0.00       NA
##       ES-Asimetría     1.22     1.22     1.22     1.22     1.22     1.22     0.00
##           Curtosis    -2.33    -2.33    -2.33    -2.33    -2.33    -2.33       NA
##         Num.Válido     3.00     3.00     3.00     3.00     3.00     3.00     1.00
##                  N     3.00     3.00     3.00     3.00     3.00     3.00     1.00
##         Pct.Válido   100.00   100.00   100.00   100.00   100.00   100.00   100.00

GRAFICO DATOS pH

ggplot(
  subset(SUELO, !is.na(PH) & !is.na(TRATAMIENTOS_TOMATE) & TRATAMIENTOS_TOMATE != "NA"),
  aes(TRATAMIENTOS_TOMATE, PH, fill = TRATAMIENTOS_TOMATE)
) +
  geom_boxplot() +
  scale_fill_paletteer_d("RColorBrewer::RdYlBu") +
  scale_y_continuous(
    limits = c(5.5, 7.5),
    breaks = seq(5, 7.5, 0.5)
  ) +
  labs(
    x = "Tratamientos",
    y = "pH"
  ) +
  theme_minimal() +
  theme(legend.position = "none")

ANOVA DATOS pH

factorial_PH <- aov( PH ~ BIOESTIMULANTE + SALINIDAD_AGUA + BIOESTIMULANTE:SALINIDAD_AGUA, data = SUELO)
summary(factorial_PH)
##                               Df Sum Sq Mean Sq F value Pr(>F)  
## BIOESTIMULANTE                 2 0.0478  0.0239   0.473 0.6345  
## SALINIDAD_AGUA                 1 0.4356  0.4356   8.615 0.0125 *
## BIOESTIMULANTE:SALINIDAD_AGUA  2 0.0211  0.0106   0.209 0.8145  
## Residuals                     12 0.6067  0.0506                 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 1 observation deleted due to missingness

GRAFICOS SUPUESTOS pH

#NORMALIDAD: QQplot
#HOMOCEDASTICIDAD: Scale Location
plot(factorial_PH)

PRUEBA NORMALIDAD (shapiro) factorial_PH

shapiro.test(factorial_PH$residuals)
## 
##  Shapiro-Wilk normality test
## 
## data:  factorial_PH$residuals
## W = 0.95456, p-value = 0.5009

#PRUEBA HOMOCEDASTICIDAD (levene) factorial_PH

leveneTest(PH ~ BIOESTIMULANTE * SALINIDAD_AGUA, data = SUELO)
## Levene's Test for Homogeneity of Variance (center = median)
##       Df F value Pr(>F)
## group  5  0.8824 0.5218
##       12

GRAFICO INTERACCION factorial_PH

emmip(factorial_PH, SALINIDAD_AGUA ~ BIOESTIMULANTE)

PRUEBAS POSTERIORI (tukey) factorial_PH

#EFECTO SALINIDAD EN AGUA
Tukey_PH_SAL <- HSD.test(factorial_PH, "SALINIDAD_AGUA") 
Tukey_PH_SAL
## $statistics
##      MSerror Df     Mean       CV       MSD
##   0.05055556 12 6.322222 3.556433 0.2309394
## 
## $parameters
##    test         name.t ntr StudentizedRange alpha
##   Tukey SALINIDAD_AGUA   2         3.081307  0.05
## 
## $means
##           PH        std r         se Min Max Q25 Q50 Q75
## 0   6.477778 0.28185891 9 0.07494854 6.2 7.0 6.2 6.5 6.7
## 3.6 6.166667 0.07071068 9 0.07494854 6.1 6.3 6.1 6.2 6.2
## 
## $comparison
## NULL
## 
## $groups
##           PH groups
## 0   6.477778      a
## 3.6 6.166667      b
## 
## attr(,"class")
## [1] "group"

PRUEBAS POSTERIORI (fisher) factorial_PH (SALINIDAD EN AGUA)

#VARIABLE SALINIDAD EN AGUA 

#Test de Fisher (LSD) y Gráfico 

 Fisher_PH_SAL <- LSD.test(factorial_PH, "SALINIDAD_AGUA", p.adj = "none") 

 print(Fisher_PH_SAL) 
## $statistics
##      MSerror Df     Mean       CV  t.value       LSD
##   0.05055556 12 6.322222 3.556433 2.178813 0.2309394
## 
## $parameters
##         test p.ajusted         name.t ntr alpha
##   Fisher-LSD      none SALINIDAD_AGUA   2  0.05
## 
## $means
##           PH        std r         se      LCL      UCL Min Max Q25 Q50 Q75
## 0   6.477778 0.28185891 9 0.07494854 6.314479 6.641077 6.2 7.0 6.2 6.5 6.7
## 3.6 6.166667 0.07071068 9 0.07494854 6.003368 6.329966 6.1 6.3 6.1 6.2 6.2
## 
## $comparison
## NULL
## 
## $groups
##           PH groups
## 0   6.477778      a
## 3.6 6.166667      b
## 
## attr(,"class")
## [1] "group"
plot(Fisher_PH_SAL, main = "Test de Fisher",   

xlab= "Salinidad en agua",  

ylab= "pH",  

ylim= c(5.5, 8)) 

DATOS CE

st_options(lang = "es")
SUELO %>% 
  group_by(TRATAMIENTOS_TOMATE) %>% 
  descr(CE)
## Estadísticas descriptivas  
## CE por TRATAMIENTOS_TOMATE  
## Data frame: SUELO  
## N: 19  
## 
##                       B0_S0    B0_S3    B1_S0    B1_S3    B2_S0    B2_S3       NA
## ------------------ -------- -------- -------- -------- -------- -------- --------
##              Media     0.27     0.77     0.20     0.73     0.20     0.80     0.30
##           Dev.std.     0.06     0.06     0.10     0.21     0.10     0.10       NA
##                Min     0.20     0.70     0.10     0.50     0.10     0.70     0.30
##                 Q1     0.20     0.70     0.10     0.50     0.10     0.70     0.30
##            Mediana     0.30     0.80     0.20     0.80     0.20     0.80     0.30
##                 Q3     0.30     0.80     0.30     0.90     0.30     0.90     0.30
##                Max     0.30     0.80     0.30     0.90     0.30     0.90     0.30
##                DAP     0.00     0.00     0.15     0.15     0.15     0.15     0.00
##                 RI     0.05     0.05     0.10     0.20     0.10     0.10     0.00
##                 CV     0.22     0.08     0.50     0.28     0.50     0.13       NA
##          Asimetría    -0.38    -0.38     0.00    -0.29     0.00     0.00       NA
##       ES-Asimetría     1.22     1.22     1.22     1.22     1.22     1.22     0.00
##           Curtosis    -2.33    -2.33    -2.33    -2.33    -2.33    -2.33       NA
##         Num.Válido     3.00     3.00     3.00     3.00     3.00     3.00     1.00
##                  N     3.00     3.00     3.00     3.00     3.00     3.00     1.00
##         Pct.Válido   100.00   100.00   100.00   100.00   100.00   100.00   100.00

GRAFICO DATOS CE

ggplot(
  subset(SUELO, !is.na(CE) & !is.na(TRATAMIENTOS_TOMATE) & TRATAMIENTOS_TOMATE != "NA"),
  aes(TRATAMIENTOS_TOMATE, CE, fill = TRATAMIENTOS_TOMATE)
) +
  geom_boxplot() +
  scale_fill_paletteer_d("RColorBrewer::RdBu") +
  scale_y_continuous(
    limits = c(0, 1),
    breaks = seq(0, 1, 0.1)
  ) +
  labs(
    x = "Tratamientos",
    y = "CE (dS/m)"
  ) +
  theme_minimal() +
  theme(legend.position = "none")

ANOVA DATOS CE

factorial_CE <- aov( CE ~ BIOESTIMULANTE + SALINIDAD_AGUA + BIOESTIMULANTE:SALINIDAD_AGUA, data = SUELO)
summary(factorial_CE)
##                               Df Sum Sq Mean Sq F value   Pr(>F)    
## BIOESTIMULANTE                 2 0.0078  0.0039   0.292    0.752    
## SALINIDAD_AGUA                 1 1.3339  1.3339 100.042 3.57e-07 ***
## BIOESTIMULANTE:SALINIDAD_AGUA  2 0.0078  0.0039   0.292    0.752    
## Residuals                     12 0.1600  0.0133                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 1 observation deleted due to missingness

GRAFICOS SUPUESTOS CE

#NORMALIDAD: QQplot
#HOMOCEDASTICIDAD: Scale Location
plot(factorial_CE)

PRUEBA NORMALIDAD (shapiro) factorial_CE

shapiro.test(factorial_CE$residuals)
## 
##  Shapiro-Wilk normality test
## 
## data:  factorial_CE$residuals
## W = 0.95139, p-value = 0.4472

#PRUEBA HOMOCEDASTICIDAD (levene) factorial_CE

leveneTest(CE ~ BIOESTIMULANTE * SALINIDAD_AGUA, data = SUELO)
## Levene's Test for Homogeneity of Variance (center = median)
##       Df F value Pr(>F)
## group  5     0.6 0.7013
##       12

GRAFICO INTERACCION factorial_CE

emmip(factorial_CE, SALINIDAD_AGUA ~ BIOESTIMULANTE)

PRUEBAS POSTERIORI (tukey) factorial_CE

#EFECTO SALINIDAD EN AGUA
Tukey_CE_SAL <- HSD.test(factorial_CE, "SALINIDAD_AGUA") 
Tukey_CE_SAL
## $statistics
##      MSerror Df      Mean       CV       MSD
##   0.01333333 12 0.4944444 23.35349 0.1185995
## 
## $parameters
##    test         name.t ntr StudentizedRange alpha
##   Tukey SALINIDAD_AGUA   2         3.081307  0.05
## 
## $means
##            CE        std r         se Min Max Q25 Q50 Q75
## 0   0.2222222 0.08333333 9 0.03849002 0.1 0.3 0.2 0.2 0.3
## 3.6 0.7666667 0.12247449 9 0.03849002 0.5 0.9 0.7 0.8 0.8
## 
## $comparison
## NULL
## 
## $groups
##            CE groups
## 3.6 0.7666667      a
## 0   0.2222222      b
## 
## attr(,"class")
## [1] "group"

PRUEBAS POSTERIORI (fisher) factorial_CE (SALINIDAD EN AGUA)

#VARIABLE SALINIDAD EN AGUA 

#Test de Fisher (LSD) y Gráfico 

 Fisher_CE_SAL <- LSD.test(factorial_CE, "SALINIDAD_AGUA", p.adj = "none") 

 print(Fisher_CE_SAL) 
## $statistics
##      MSerror Df      Mean       CV  t.value       LSD
##   0.01333333 12 0.4944444 23.35349 2.178813 0.1185995
## 
## $parameters
##         test p.ajusted         name.t ntr alpha
##   Fisher-LSD      none SALINIDAD_AGUA   2  0.05
## 
## $means
##            CE        std r         se       LCL       UCL Min Max Q25 Q50 Q75
## 0   0.2222222 0.08333333 9 0.03849002 0.1383597 0.3060848 0.1 0.3 0.2 0.2 0.3
## 3.6 0.7666667 0.12247449 9 0.03849002 0.6828041 0.8505292 0.5 0.9 0.7 0.8 0.8
## 
## $comparison
## NULL
## 
## $groups
##            CE groups
## 3.6 0.7666667      a
## 0   0.2222222      b
## 
## attr(,"class")
## [1] "group"
plot(Fisher_CE_SAL, main = "Test de Fisher",   

xlab= "Salinidad en agua",  

ylab= "CE (dS/m)",  

ylim= c(0, 1)) 

GRAFICO PH x TRATAMIENTO

ggplot(SUELO %>% 
         mutate(TRATAMIENTOS_TOMATE = forcats::fct_explicit_na(
           as.factor(TRATAMIENTOS_TOMATE), na_level = "Testigo"
         )),
       aes(x = PH, y = TRATAMIENTOS_TOMATE, fill = TRATAMIENTOS_TOMATE)) +
  stat_summary(fun = mean,
               geom = "bar",
               position = position_dodge(width = 0.5)) +
  scale_fill_paletteer_d("RColorBrewer::RdYlGn", na.value = "black") +
  scale_x_continuous(breaks = seq(0, 14, 1)) +
  labs(
    x = "PH",
    y = "TRATAMIENTOS"
  ) +
  theme_classic()
## Warning: There was 1 warning in `mutate()`.
## ℹ In argument: `TRATAMIENTOS_TOMATE =
##   forcats::fct_explicit_na(as.factor(TRATAMIENTOS_TOMATE), na_level =
##   "Testigo")`.
## Caused by warning:
## ! `fct_explicit_na()` was deprecated in forcats 1.0.0.
## ℹ Please use `fct_na_value_to_level()` instead.

GRAFICO CE x TRATAMIENTO

ggplot(SUELO %>% 
         mutate(TRATAMIENTOS_TOMATE = forcats::fct_explicit_na(
           as.factor(TRATAMIENTOS_TOMATE), na_level = "Testigo"
         )),
       aes(x = CE, y = TRATAMIENTOS_TOMATE, fill = TRATAMIENTOS_TOMATE)) +
  stat_summary(fun = mean,
               geom = "bar",
               position = position_dodge(width = 0.5)) +
  scale_fill_paletteer_d("RColorBrewer::RdYlGn", na.value = "black") +
  scale_x_continuous(breaks = seq(0, 1, 0.1)) +
  labs(
    x = "CE",
    y = "TRATAMIENTOS"
  ) +
  theme_classic()