setwd("~/Library/CloudStorage/GoogleDrive-icarounam@gmail.com/Mi unidad/UIS/Pasantías")
library(rstatix)
## 
## Attaching package: 'rstatix'
## The following object is masked from 'package:stats':
## 
##     filter
library(ggplot2)
library(ggpubr)
library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
## ✓ tibble  3.1.6     ✓ dplyr   1.0.7
## ✓ tidyr   1.1.4     ✓ stringr 1.4.0
## ✓ readr   2.1.1     ✓ forcats 0.5.1
## ✓ purrr   0.3.4
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks rstatix::filter(), stats::filter()
## x dplyr::lag()    masks stats::lag()
cava <- read.table("dacava2.csv", header=T, sep=",")
res.alt <- t.test(alt ~ Tratamiento, data = cava, var.equal=FALSE)
res.LR <- t.test(LR ~ Tratamiento, data = cava, var.equal=FALSE)
res.diam <- t.test(diam ~ Tratamiento, data = cava, var.equal=FALSE)
res.AFE <- t.test(AFE ~ Tratamiento, data = cava, var.equal=FALSE)
res.PFE <- t.test(PFE ~ Tratamiento, data = cava, var.equal=FALSE)
res.MSR <- t.test(MSR ~ Tratamiento, data = cava, var.equal=FALSE)
res.MST <- t.test(MST ~ Tratamiento, data = cava, var.equal=FALSE)
res.MSF <- t.test(MSF ~ Tratamiento, data = cava, var.equal=FALSE)
res.MSPA <- t.test(MSPA ~ Tratamiento, data = cava, var.equal=FALSE)
res.MT <- t.test(MT ~ Tratamiento, data = cava, var.equal=FALSE)
res.FMR <- t.test(FMR ~ Tratamiento, data = cava, var.equal=FALSE)
res.FMT <- t.test(FMT ~ Tratamiento, data = cava, var.equal=FALSE)
res.FMF <- t.test(FMF ~ Tratamiento, data = cava, var.equal=FALSE)
res.RPA <- t.test(RPA ~ Tratamiento, data = cava, var.equal=FALSE)
res.RT <- t.test(RT ~ Tratamiento, data = cava, var.equal=FALSE)
res.RH <- t.test(RH ~ Tratamiento, data = cava, var.equal=FALSE)
res.TH <- t.test(TH ~ Tratamiento, data = cava, var.equal=FALSE)
res.esbeltez <- t.test(esbeltez ~ Tratamiento, data = cava, var.equal=FALSE)
res.dickson <- t.test(dickson ~ Tratamiento, data = cava, var.equal=FALSE)
res.alt
## 
##  Welch Two Sample t-test
## 
## data:  alt by Tratamiento
## t = 11.981, df = 6.4039, p-value = 1.271e-05
## alternative hypothesis: true difference in means between group 1 and group 2 is not equal to 0
## 95 percent confidence interval:
##  11.24089 16.90196
## sample estimates:
## mean in group 1 mean in group 2 
##        41.98571        27.91429
res.LR
## 
##  Welch Two Sample t-test
## 
## data:  LR by Tratamiento
## t = 1.4528, df = 11.785, p-value = 0.1724
## alternative hypothesis: true difference in means between group 1 and group 2 is not equal to 0
## 95 percent confidence interval:
##  -4.338684 21.595827
## sample estimates:
## mean in group 1 mean in group 2 
##        46.08571        37.45714
res.diam
## 
##  Welch Two Sample t-test
## 
## data:  diam by Tratamiento
## t = 6.6918, df = 10.708, p-value = 3.892e-05
## alternative hypothesis: true difference in means between group 1 and group 2 is not equal to 0
## 95 percent confidence interval:
##   7.730794 15.346349
## sample estimates:
## mean in group 1 mean in group 2 
##        37.08286        25.54429
res.AFE
## 
##  Welch Two Sample t-test
## 
## data:  AFE by Tratamiento
## t = -1.218, df = 11.427, p-value = 0.2478
## alternative hypothesis: true difference in means between group 1 and group 2 is not equal to 0
## 95 percent confidence interval:
##  -0.8992095  0.2566378
## sample estimates:
## mean in group 1 mean in group 2 
##        1.869981        2.191267
res.PFE
## 
##  Welch Two Sample t-test
## 
## data:  PFE by Tratamiento
## t = 1.3721, df = 11.991, p-value = 0.1952
## alternative hypothesis: true difference in means between group 1 and group 2 is not equal to 0
## 95 percent confidence interval:
##  -0.04554154  0.20042941
## sample estimates:
## mean in group 1 mean in group 2 
##       0.5555582       0.4781143
res.MSR
## 
##  Welch Two Sample t-test
## 
## data:  MSR by Tratamiento
## t = 6.1651, df = 7.7435, p-value = 0.0003077
## alternative hypothesis: true difference in means between group 1 and group 2 is not equal to 0
## 95 percent confidence interval:
##  10.90740 24.06402
## sample estimates:
## mean in group 1 mean in group 2 
##        27.52143        10.03571
res.MST
## 
##  Welch Two Sample t-test
## 
## data:  MST by Tratamiento
## t = 6.8004, df = 7.5146, p-value = 0.0001838
## alternative hypothesis: true difference in means between group 1 and group 2 is not equal to 0
## 95 percent confidence interval:
##   8.511627 17.396944
## sample estimates:
## mean in group 1 mean in group 2 
##       20.935714        7.981429
res.MSF
## 
##  Welch Two Sample t-test
## 
## data:  MSF by Tratamiento
## t = 5.0773, df = 6.6087, p-value = 0.001706
## alternative hypothesis: true difference in means between group 1 and group 2 is not equal to 0
## 95 percent confidence interval:
##   5.549096 15.445190
## sample estimates:
## mean in group 1 mean in group 2 
##       15.465714        4.968571
res.MSPA
## 
##  Welch Two Sample t-test
## 
## data:  MSPA by Tratamiento
## t = 6.4141, df = 6.9432, p-value = 0.0003749
## alternative hypothesis: true difference in means between group 1 and group 2 is not equal to 0
## 95 percent confidence interval:
##  14.79147 32.11139
## sample estimates:
## mean in group 1 mean in group 2 
##        36.40143        12.95000
res.MT
## 
##  Welch Two Sample t-test
## 
## data:  MT by Tratamiento
## t = 6.9089, df = 7.259, p-value = 0.0001943
## alternative hypothesis: true difference in means between group 1 and group 2 is not equal to 0
## 95 percent confidence interval:
##  27.02674 54.84755
## sample estimates:
## mean in group 1 mean in group 2 
##        63.92286        22.98571
res.FMR
## 
##  Welch Two Sample t-test
## 
## data:  FMR by Tratamiento
## t = -0.091936, df = 12, p-value = 0.9283
## alternative hypothesis: true difference in means between group 1 and group 2 is not equal to 0
## 95 percent confidence interval:
##  -0.06519907  0.05991962
## sample estimates:
## mean in group 1 mean in group 2 
##       0.4318555       0.4344953
res.FMT
## 
##  Welch Two Sample t-test
## 
## data:  FMT by Tratamiento
## t = -0.88446, df = 11.998, p-value = 0.3938
## alternative hypothesis: true difference in means between group 1 and group 2 is not equal to 0
## 95 percent confidence interval:
##  -0.06359336  0.02687121
## sample estimates:
## mean in group 1 mean in group 2 
##       0.3299907       0.3483518
res.FMF
## 
##  Welch Two Sample t-test
## 
## data:  FMF by Tratamiento
## t = 0.96437, df = 11.503, p-value = 0.3547
## alternative hypothesis: true difference in means between group 1 and group 2 is not equal to 0
## 95 percent confidence interval:
##  -0.0266750  0.0686766
## sample estimates:
## mean in group 1 mean in group 2 
##       0.2381537       0.2171529
res.RPA
## 
##  Welch Two Sample t-test
## 
## data:  RPA by Tratamiento
## t = -0.1021, df = 11.967, p-value = 0.9204
## alternative hypothesis: true difference in means between group 1 and group 2 is not equal to 0
## 95 percent confidence interval:
##  -0.2000787  0.1821721
## sample estimates:
## mean in group 1 mean in group 2 
##       0.7730241       0.7819774
res.RT
## 
##  Welch Two Sample t-test
## 
## data:  RT by Tratamiento
## t = 0.42105, df = 11.917, p-value = 0.6812
## alternative hypothesis: true difference in means between group 1 and group 2 is not equal to 0
## 95 percent confidence interval:
##  -0.2686185  0.3971826
## sample estimates:
## mean in group 1 mean in group 2 
##        1.335927        1.271645
res.RH
## 
##  Welch Two Sample t-test
## 
## data:  RH by Tratamiento
## t = -0.61856, df = 11.903, p-value = 0.5479
## alternative hypothesis: true difference in means between group 1 and group 2 is not equal to 0
## 95 percent confidence interval:
##  -0.8361277  0.4666168
## sample estimates:
## mean in group 1 mean in group 2 
##        1.896133        2.080888
res.TH
## 
##  Welch Two Sample t-test
## 
## data:  TH by Tratamiento
## t = -0.61856, df = 11.903, p-value = 0.5479
## alternative hypothesis: true difference in means between group 1 and group 2 is not equal to 0
## 95 percent confidence interval:
##  -0.8361277  0.4666168
## sample estimates:
## mean in group 1 mean in group 2 
##        1.896133        2.080888
res.esbeltez
## 
##  Welch Two Sample t-test
## 
## data:  esbeltez by Tratamiento
## t = -0.54544, df = 9.3049, p-value = 0.5983
## alternative hypothesis: true difference in means between group 1 and group 2 is not equal to 0
## 95 percent confidence interval:
##  -0.1437014  0.0876426
## sample estimates:
## mean in group 1 mean in group 2 
##       0.8854827       0.9135121
res.dickson
## 
##  Welch Two Sample t-test
## 
## data:  dickson by Tratamiento
## t = 7.5164, df = 9.1487, p-value = 3.319e-05
## alternative hypothesis: true difference in means between group 1 and group 2 is not equal to 0
## 95 percent confidence interval:
##  24.43568 45.40235
## sample estimates:
## mean in group 1 mean in group 2 
##        57.35265        22.43364
## Creando test especifico para las variables significativas (alt, diam, MSR, MST, MSF, MSPA, MT, dickson)
# alt
stat.test <- cava %>% 
  t_test(alt ~ Tratamiento) %>%
  add_significance()
stat.test
## # A tibble: 1 × 9
##   .y.   group1 group2    n1    n2 statistic    df         p p.signif
## * <chr> <chr>  <chr>  <int> <int>     <dbl> <dbl>     <dbl> <chr>   
## 1 alt   1      2          7     7      12.0  6.40 0.0000127 ****
# Creando box-plot para variables significativas
bxp <- ggboxplot(
  cava, x = "Tratamiento", y = "alt", 
  ylab = "Altura planta (cm)", xlab = "Tratamientos", add = "jitter"
)
# Add p-value and significance levels
stat.test <- stat.test %>% add_xy_position(x = "Tratamiento")
bxp + 
  stat_pvalue_manual(stat.test, tip.length = 0) +
  labs(subtitle = get_test_label(stat.test, detailed = TRUE))

# diam
stat.test <- cava %>% 
  t_test(diam ~ Tratamiento) %>%
  add_significance()
stat.test
## # A tibble: 1 × 9
##   .y.   group1 group2    n1    n2 statistic    df         p p.signif
## * <chr> <chr>  <chr>  <int> <int>     <dbl> <dbl>     <dbl> <chr>   
## 1 diam  1      2          7     7      6.69  10.7 0.0000389 ****
# Creando box-plot para variables significativas
bxp <- ggboxplot(
  cava, x = "Tratamiento", y = "diam", 
  ylab = "Diametro base tallo (mm)", xlab = "Tratamientos", add = "jitter"
)
# Add p-value and significance levels
stat.test <- stat.test %>% add_xy_position(x = "Tratamiento")
bxp + 
  stat_pvalue_manual(stat.test, tip.length = 0) +
  labs(subtitle = get_test_label(stat.test, detailed = TRUE))

# MSR
stat.test <- cava %>% 
  t_test(MSR ~ Tratamiento) %>%
  add_significance()
stat.test
## # A tibble: 1 × 9
##   .y.   group1 group2    n1    n2 statistic    df        p p.signif
## * <chr> <chr>  <chr>  <int> <int>     <dbl> <dbl>    <dbl> <chr>   
## 1 MSR   1      2          7     7      6.17  7.74 0.000308 ***
# Creando box-plot para variables significativas
bxp <- ggboxplot(
  cava, x = "Tratamiento", y = "MSR", 
  ylab = "Biomasa seca raíz (g)", xlab = "Tratamientos", add = "jitter"
)
# Add p-value and significance levels
stat.test <- stat.test %>% add_xy_position(x = "Tratamiento")
bxp + 
  stat_pvalue_manual(stat.test, tip.length = 0) +
  labs(subtitle = get_test_label(stat.test, detailed = TRUE))

# MST
stat.test <- cava %>% 
  t_test(MST ~ Tratamiento) %>%
  add_significance()
stat.test
## # A tibble: 1 × 9
##   .y.   group1 group2    n1    n2 statistic    df        p p.signif
## * <chr> <chr>  <chr>  <int> <int>     <dbl> <dbl>    <dbl> <chr>   
## 1 MST   1      2          7     7      6.80  7.51 0.000184 ***
# Creando box-plot para variables significativas
bxp <- ggboxplot(
  cava, x = "Tratamiento", y = "MST", 
  ylab = "Biomasa seca tallo (g)", xlab = "Tratamientos", add = "jitter"
)
# Add p-value and significance levels
stat.test <- stat.test %>% add_xy_position(x = "Tratamiento")
bxp + 
  stat_pvalue_manual(stat.test, tip.length = 0) +
  labs(subtitle = get_test_label(stat.test, detailed = TRUE))

# MSF
stat.test <- cava %>% 
  t_test(MSF ~ Tratamiento) %>%
  add_significance()
stat.test
## # A tibble: 1 × 9
##   .y.   group1 group2    n1    n2 statistic    df       p p.signif
## * <chr> <chr>  <chr>  <int> <int>     <dbl> <dbl>   <dbl> <chr>   
## 1 MSF   1      2          7     7      5.08  6.61 0.00171 **
# Creando box-plot para variables significativas
bxp <- ggboxplot(
  cava, x = "Tratamiento", y = "MSF", 
  ylab = "Biomasa seca foliar (g)", xlab = "Tratamientos", add = "jitter"
)
# Add p-value and significance levels
stat.test <- stat.test %>% add_xy_position(x = "Tratamiento")
bxp + 
  stat_pvalue_manual(stat.test, tip.length = 0) +
  labs(subtitle = get_test_label(stat.test, detailed = TRUE))

# MSPA
stat.test <- cava %>% 
  t_test(MSPA ~ Tratamiento) %>%
  add_significance()
stat.test
## # A tibble: 1 × 9
##   .y.   group1 group2    n1    n2 statistic    df        p p.signif
## * <chr> <chr>  <chr>  <int> <int>     <dbl> <dbl>    <dbl> <chr>   
## 1 MSPA  1      2          7     7      6.41  6.94 0.000375 ***
# Creando box-plot para variables significativas
bxp <- ggboxplot(
  cava, x = "Tratamiento", y = "MSPA", 
  ylab = "Biomasa seca parte aérea (g)", xlab = "Tratamientos", add = "jitter"
)
# Add p-value and significance levels
stat.test <- stat.test %>% add_xy_position(x = "Tratamiento")
bxp + 
  stat_pvalue_manual(stat.test, tip.length = 0) +
  labs(subtitle = get_test_label(stat.test, detailed = TRUE))

# MT
stat.test <- cava %>% 
  t_test(MT ~ Tratamiento) %>%
  add_significance()
stat.test
## # A tibble: 1 × 9
##   .y.   group1 group2    n1    n2 statistic    df        p p.signif
## * <chr> <chr>  <chr>  <int> <int>     <dbl> <dbl>    <dbl> <chr>   
## 1 MT    1      2          7     7      6.91  7.26 0.000194 ***
# Creando box-plot para variables significativas
bxp <- ggboxplot(
  cava, x = "Tratamiento", y = "MT", 
  ylab = "Biomasa seca total (g)", xlab = "Tratamientos", add = "jitter"
)
# Add p-value and significance levels
stat.test <- stat.test %>% add_xy_position(x = "Tratamiento")
bxp + 
  stat_pvalue_manual(stat.test, tip.length = 0) +
  labs(subtitle = get_test_label(stat.test, detailed = TRUE))

# dickson
stat.test <- cava %>% 
  t_test(dickson ~ Tratamiento) %>%
  add_significance()
stat.test
## # A tibble: 1 × 9
##   .y.     group1 group2    n1    n2 statistic    df         p p.signif
## * <chr>   <chr>  <chr>  <int> <int>     <dbl> <dbl>     <dbl> <chr>   
## 1 dickson 1      2          7     7      7.52  9.15 0.0000332 ****
# Creando box-plot para variables significativas
bxp <- ggboxplot(
  cava, x = "Tratamiento", y = "dickson", 
  ylab = "Índice de Dickson", xlab = "Tratamientos", add = "jitter"
)
# Add p-value and significance levels
stat.test <- stat.test %>% add_xy_position(x = "Tratamiento")
bxp + 
  stat_pvalue_manual(stat.test, tip.length = 0) +
  labs(subtitle = get_test_label(stat.test, detailed = TRUE))