setwd("~/Library/CloudStorage/GoogleDrive-icarounam@gmail.com/Mi unidad/Agrosavia/Env_muestra/data")
datos<-read.table("testafin2.csv", header=T, sep=',')
datos$curva <- factor(datos$curva, levels = c("1", "2", "3"),
labels = c("P3", "P1","P2"))
datos$gen<-as.factor(datos$gen)
datos$curva<-as.factor(datos$curva)
datos$id<-as.factor(datos$id)
datos$muestra<-as.factor(datos$muestra)
datos$dia<-as.factor(datos$dia)
library(ggplot2)
library(Rmisc)
## Loading required package: lattice
## Loading required package: plyr
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:plyr':
##
## arrange, count, desc, failwith, id, mutate, rename, summarise,
## summarize
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
## ✓ tibble 3.1.6 ✓ purrr 0.3.4
## ✓ tidyr 1.1.4 ✓ stringr 1.4.0
## ✓ readr 2.1.1 ✓ forcats 0.5.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::arrange() masks plyr::arrange()
## x purrr::compact() masks plyr::compact()
## x dplyr::count() masks plyr::count()
## x dplyr::failwith() masks plyr::failwith()
## x dplyr::filter() masks stats::filter()
## x dplyr::id() masks plyr::id()
## x dplyr::lag() masks stats::lag()
## x dplyr::mutate() masks plyr::mutate()
## x dplyr::rename() masks plyr::rename()
## x dplyr::summarise() masks plyr::summarise()
## x dplyr::summarize() masks plyr::summarize()
library(ggpubr)
##
## Attaching package: 'ggpubr'
## The following object is masked from 'package:plyr':
##
## mutate
library(rstatix)
##
## Attaching package: 'rstatix'
## The following objects are masked from 'package:plyr':
##
## desc, mutate
## The following object is masked from 'package:stats':
##
## filter
##Summary statistics
summ<-datos %>%
group_by(curva, gen, dia) %>%
get_summary_stats(cd.testa, type = "mean_sd")
summ %>% as_tibble() %>% print(n=Inf)
## # A tibble: 36 × 7
## curva gen dia variable n mean sd
## <fct> <fct> <fct> <chr> <dbl> <dbl> <dbl>
## 1 P3 CCN51 0 cd.testa 3 3.76 0.107
## 2 P3 CCN51 2 cd.testa 3 5.86 1.17
## 3 P3 CCN51 5 cd.testa 3 10.3 1.80
## 4 P3 CCN51 6 cd.testa 3 12.3 0.987
## 5 P3 ICS95 0 cd.testa 3 5.55 0.618
## 6 P3 ICS95 2 cd.testa 3 8.38 1.00
## 7 P3 ICS95 5 cd.testa 3 13.4 1.07
## 8 P3 ICS95 6 cd.testa 3 14.9 0.442
## 9 P3 TCS01 0 cd.testa 3 2.83 0.288
## 10 P3 TCS01 2 cd.testa 3 5.00 1.05
## 11 P3 TCS01 5 cd.testa 3 6.87 0.768
## 12 P3 TCS01 6 cd.testa 3 7.83 1.11
## 13 P1 CCN51 0 cd.testa 3 5.96 1.99
## 14 P1 CCN51 2 cd.testa 3 8.88 1.39
## 15 P1 CCN51 5 cd.testa 3 13.4 1.84
## 16 P1 CCN51 6 cd.testa 3 13.8 0.37
## 17 P1 ICS95 0 cd.testa 3 6.37 0.255
## 18 P1 ICS95 2 cd.testa 3 7.68 0.589
## 19 P1 ICS95 5 cd.testa 3 9.33 0.373
## 20 P1 ICS95 6 cd.testa 3 9.52 0.84
## 21 P1 TCS01 0 cd.testa 3 3.75 0.335
## 22 P1 TCS01 2 cd.testa 3 5.08 0.931
## 23 P1 TCS01 5 cd.testa 3 6.53 0.432
## 24 P1 TCS01 6 cd.testa 3 7.30 0.898
## 25 P2 CCN51 0 cd.testa 3 5.09 0.202
## 26 P2 CCN51 2 cd.testa 3 5.18 0.403
## 27 P2 CCN51 5 cd.testa 3 9.80 0.949
## 28 P2 CCN51 6 cd.testa 3 8.67 0.552
## 29 P2 ICS95 0 cd.testa 3 6.87 0.575
## 30 P2 ICS95 2 cd.testa 3 9.03 0.559
## 31 P2 ICS95 5 cd.testa 3 8.10 0.561
## 32 P2 ICS95 6 cd.testa 3 10.1 1.08
## 33 P2 TCS01 0 cd.testa 3 4.02 0.178
## 34 P2 TCS01 2 cd.testa 3 5.13 0.402
## 35 P2 TCS01 5 cd.testa 3 7.42 0.497
## 36 P2 TCS01 6 cd.testa 3 8.39 1.67
##Visualization
bxp <- ggboxplot(
datos, x = "curva", y = "cd.testa",
color = "dia", palette = "jco",
facet.by = "gen"
)
bxp

##Check assumptions
##Outliers
datos %>%
group_by(curva, gen, dia) %>%
identify_outliers(cd.testa)
## [1] curva gen dia muestra id cd.testa is.outlier
## [8] is.extreme
## <0 rows> (or 0-length row.names)
##Normality assumption
##Compute Shapiro-Wilk test for each combinations of factor levels:
norm<-datos %>%
group_by(curva, gen, dia) %>%
shapiro_test(cd.testa)
norm %>% as_tibble() %>% print(n=Inf)
## # A tibble: 36 × 6
## curva gen dia variable statistic p
## <fct> <fct> <fct> <chr> <dbl> <dbl>
## 1 P3 CCN51 0 cd.testa 0.964 0.637
## 2 P3 CCN51 2 cd.testa 0.925 0.470
## 3 P3 CCN51 5 cd.testa 0.850 0.239
## 4 P3 CCN51 6 cd.testa 0.976 0.703
## 5 P3 ICS95 0 cd.testa 0.835 0.201
## 6 P3 ICS95 2 cd.testa 0.994 0.846
## 7 P3 ICS95 5 cd.testa 0.993 0.846
## 8 P3 ICS95 6 cd.testa 0.992 0.825
## 9 P3 TCS01 0 cd.testa 0.942 0.537
## 10 P3 TCS01 2 cd.testa 0.987 0.785
## 11 P3 TCS01 5 cd.testa 0.993 0.835
## 12 P3 TCS01 6 cd.testa 0.996 0.875
## 13 P1 CCN51 0 cd.testa 0.894 0.367
## 14 P1 CCN51 2 cd.testa 0.940 0.528
## 15 P1 CCN51 5 cd.testa 0.902 0.393
## 16 P1 CCN51 6 cd.testa 0.973 0.686
## 17 P1 ICS95 0 cd.testa 0.959 0.609
## 18 P1 ICS95 2 cd.testa 0.857 0.260
## 19 P1 ICS95 5 cd.testa 0.985 0.763
## 20 P1 ICS95 6 cd.testa 0.999 0.948
## 21 P1 TCS01 0 cd.testa 0.998 0.918
## 22 P1 TCS01 2 cd.testa 0.935 0.509
## 23 P1 TCS01 5 cd.testa 0.817 0.155
## 24 P1 TCS01 6 cd.testa 0.755 0.0106
## 25 P2 CCN51 0 cd.testa 0.883 0.332
## 26 P2 CCN51 2 cd.testa 0.891 0.358
## 27 P2 CCN51 5 cd.testa 0.869 0.293
## 28 P2 CCN51 6 cd.testa 0.920 0.454
## 29 P2 ICS95 0 cd.testa 0.915 0.436
## 30 P2 ICS95 2 cd.testa 0.880 0.326
## 31 P2 ICS95 5 cd.testa 0.962 0.624
## 32 P2 ICS95 6 cd.testa 0.859 0.265
## 33 P2 TCS01 0 cd.testa 0.968 0.657
## 34 P2 TCS01 2 cd.testa 0.802 0.119
## 35 P2 TCS01 5 cd.testa 0.992 0.833
## 36 P2 TCS01 6 cd.testa 0.934 0.503
##Create QQ plot for each cell of design:
ggqqplot(datos, "cd.testa", ggtheme = theme_bw()) +
facet_grid(dia~ curva*gen, labeller = "label_both")

##Homogneity of variance assumption
##Compute the Levene’s test at each level of the within-subjects factor, here time variable:
lev<-datos %>%
group_by(dia) %>%
levene_test(cd.testa ~ curva*gen)
lev %>% as_tibble() %>% print(n=Inf)
## # A tibble: 4 × 5
## dia df1 df2 statistic p
## <fct> <int> <int> <dbl> <dbl>
## 1 0 8 18 1.18 0.365
## 2 2 8 18 0.432 0.887
## 3 5 8 18 0.537 0.814
## 4 6 8 18 0.410 0.900
##Computation
res.aov <- anova_test(
data = datos, dv = cd.testa, wid = id,
within = dia, between = c(curva, gen)
)
get_anova_table(res.aov)
## ANOVA Table (type II tests)
##
## Effect DFn DFd F p p<.05 ges
## 1 curva 2 18 5.325 1.50e-02 * 0.198
## 2 gen 2 18 77.179 1.48e-09 * 0.782
## 3 dia 3 54 252.797 9.35e-32 * 0.891
## 4 curva:gen 4 18 17.181 5.81e-06 * 0.615
## 5 curva:dia 6 54 11.339 3.68e-08 * 0.423
## 6 gen:dia 6 54 8.561 1.51e-06 * 0.356
## 7 curva:gen:dia 12 54 5.894 2.08e-06 * 0.433
##Splitting dataframe by temperature ramp
## Protocol 3 (P3)
datos.curve1<-filter(datos, curva=="P3")
##Check assumptions
##Outliers
datos.curve1 %>%
group_by(gen, dia) %>%
identify_outliers(cd.testa)
## [1] gen dia curva muestra id cd.testa is.outlier
## [8] is.extreme
## <0 rows> (or 0-length row.names)
##Normality assumption
##Compute Shapiro-Wilk test for each combinations of factor levels:
norm1<-datos.curve1 %>%
group_by(gen, dia) %>%
shapiro_test(cd.testa)
norm1 %>% as_tibble() %>% print(n=Inf)
## # A tibble: 12 × 5
## gen dia variable statistic p
## <fct> <fct> <chr> <dbl> <dbl>
## 1 CCN51 0 cd.testa 0.964 0.637
## 2 CCN51 2 cd.testa 0.925 0.470
## 3 CCN51 5 cd.testa 0.850 0.239
## 4 CCN51 6 cd.testa 0.976 0.703
## 5 ICS95 0 cd.testa 0.835 0.201
## 6 ICS95 2 cd.testa 0.994 0.846
## 7 ICS95 5 cd.testa 0.993 0.846
## 8 ICS95 6 cd.testa 0.992 0.825
## 9 TCS01 0 cd.testa 0.942 0.537
## 10 TCS01 2 cd.testa 0.987 0.785
## 11 TCS01 5 cd.testa 0.993 0.835
## 12 TCS01 6 cd.testa 0.996 0.875
##Create QQ plot for each cell of design:
ggqqplot(datos.curve1, "cd.testa", ggtheme = theme_bw()) +
facet_grid(dia~ curva*gen, labeller = "label_both")

##Homogneity of variance assumption
##Compute the Levene’s test at each level of the within-subjects factor, here time variable:
lev1<-datos.curve1 %>%
group_by(dia) %>%
levene_test(cd.testa ~ gen)
lev1 %>% as_tibble() %>% print(n=Inf)
## # A tibble: 4 × 5
## dia df1 df2 statistic p
## <fct> <int> <int> <dbl> <dbl>
## 1 0 2 6 0.632 0.563
## 2 2 2 6 0.0108 0.989
## 3 5 2 6 0.276 0.768
## 4 6 2 6 0.565 0.596
##Computation
res.aov1 <- anova_test(
data = datos.curve1, dv = cd.testa, wid = id,
within = dia, between = gen
)
get_anova_table(res.aov1)
## ANOVA Table (type II tests)
##
## Effect DFn DFd F p p<.05 ges
## 1 gen 2.00 6.00 89.883 3.37e-05 * 0.865
## 2 dia 1.21 7.23 110.375 8.80e-06 * 0.935
## 3 gen:dia 2.41 7.23 4.232 5.60e-02 0.526
#CCN51
datos.ccn<-filter(datos.curve1, gen=="CCN51")
res.aov.ccn1 <- anova_test(
data = datos.ccn, dv = cd.testa, wid = id,
within = dia
)
get_anova_table(res.aov.ccn1)
## ANOVA Table (type III tests)
##
## Effect DFn DFd F p p<.05 ges
## 1 dia 3 6 32.05 0.000433 * 0.926
#ICS95
datos.ics<-filter(datos.curve1, gen=="ICS95")
res.aov.ics1 <- anova_test(
data = datos.ics, dv = cd.testa, wid = id,
within = dia
)
get_anova_table(res.aov.ics1)
## ANOVA Table (type III tests)
##
## Effect DFn DFd F p p<.05 ges
## 1 dia 3 6 101.961 1.55e-05 * 0.969
#TCS01
datos.tcs<-filter(datos.curve1, gen=="TCS01")
res.aov.tcs1 <- anova_test(
data = datos.tcs, dv = cd.testa, wid = id,
within = dia
)
get_anova_table(res.aov.tcs1)
## ANOVA Table (type III tests)
##
## Effect DFn DFd F p p<.05 ges
## 1 dia 3 6 15.123 0.003 * 0.879
## Protocol 1 (P1)
datos.curve2<-filter(datos, curva=="P1")
##Check assumptions
##Outliers
datos.curve2 %>%
group_by(gen, dia) %>%
identify_outliers(cd.testa)
## [1] gen dia curva muestra id cd.testa is.outlier
## [8] is.extreme
## <0 rows> (or 0-length row.names)
##Normality assumption
##Compute Shapiro-Wilk test for each combinations of factor levels:
norm2<-datos.curve2 %>%
group_by(gen, dia) %>%
shapiro_test(cd.testa)
norm2 %>% as_tibble() %>% print(n=Inf)
## # A tibble: 12 × 5
## gen dia variable statistic p
## <fct> <fct> <chr> <dbl> <dbl>
## 1 CCN51 0 cd.testa 0.894 0.367
## 2 CCN51 2 cd.testa 0.940 0.528
## 3 CCN51 5 cd.testa 0.902 0.393
## 4 CCN51 6 cd.testa 0.973 0.686
## 5 ICS95 0 cd.testa 0.959 0.609
## 6 ICS95 2 cd.testa 0.857 0.260
## 7 ICS95 5 cd.testa 0.985 0.763
## 8 ICS95 6 cd.testa 0.999 0.948
## 9 TCS01 0 cd.testa 0.998 0.918
## 10 TCS01 2 cd.testa 0.935 0.509
## 11 TCS01 5 cd.testa 0.817 0.155
## 12 TCS01 6 cd.testa 0.755 0.0106
##Create QQ plot for each cell of design:
ggqqplot(datos.curve2, "cd.testa", ggtheme = theme_bw()) +
facet_grid(dia~ curva*gen, labeller = "label_both")

##Homogneity of variance assumption
##Compute the Levene’s test at each level of the within-subjects factor, here time variable:
lev2<-datos.curve2 %>%
group_by(dia) %>%
levene_test(cd.testa ~ gen)
lev2 %>% as_tibble() %>% print(n=Inf)
## # A tibble: 4 × 5
## dia df1 df2 statistic p
## <fct> <int> <int> <dbl> <dbl>
## 1 0 2 6 1.35 0.329
## 2 2 2 6 0.397 0.689
## 3 5 2 6 1.12 0.385
## 4 6 2 6 0.246 0.789
##Computation
res.aov2 <- anova_test(
data = datos.curve2, dv = cd.testa, wid = id,
within = dia, between = gen
)
get_anova_table(res.aov2)
## ANOVA Table (type II tests)
##
## Effect DFn DFd F p p<.05 ges
## 1 gen 2 6 33.644 5.49e-04 * 0.849
## 2 dia 3 18 66.218 6.39e-10 * 0.847
## 3 gen:dia 6 18 7.330 4.41e-04 * 0.550
#CCN51
datos.ccn<-filter(datos.curve2, gen=="CCN51")
res.aov.ccn2 <- anova_test(
data = datos.ccn, dv = cd.testa, wid = id,
within = dia
)
get_anova_table(res.aov.ccn2)
## ANOVA Table (type III tests)
##
## Effect DFn DFd F p p<.05 ges
## 1 dia 3 6 29.892 0.000527 * 0.872
#ICS95
datos.ics<-filter(datos.curve2, gen=="ICS95")
res.aov.ics2 <- anova_test(
data = datos.ics, dv = cd.testa, wid = id,
within = dia
)
get_anova_table(res.aov.ics2)
## ANOVA Table (type III tests)
##
## Effect DFn DFd F p p<.05 ges
## 1 dia 3 6 26.763 0.000716 * 0.888
#TCS01
datos.tcs<-filter(datos.curve2, gen=="TCS01")
res.aov.tcs2 <- anova_test(
data = datos.tcs, dv = cd.testa, wid = id,
within = dia
)
get_anova_table(res.aov.tcs2)
## ANOVA Table (type III tests)
##
## Effect DFn DFd F p p<.05 ges
## 1 dia 3 6 17.325 0.002 * 0.85
## Protocol 2 (P2)
datos.curve3<-filter(datos, curva=="P2")
##Check assumptions
##Outliers
datos.curve3 %>%
group_by(gen, dia) %>%
identify_outliers(cd.testa)
## [1] gen dia curva muestra id cd.testa is.outlier
## [8] is.extreme
## <0 rows> (or 0-length row.names)
##Normality assumption
##Compute Shapiro-Wilk test for each combinations of factor levels:
norm2<-datos.curve3 %>%
group_by(gen, dia) %>%
shapiro_test(cd.testa)
norm2 %>% as_tibble() %>% print(n=Inf)
## # A tibble: 12 × 5
## gen dia variable statistic p
## <fct> <fct> <chr> <dbl> <dbl>
## 1 CCN51 0 cd.testa 0.883 0.332
## 2 CCN51 2 cd.testa 0.891 0.358
## 3 CCN51 5 cd.testa 0.869 0.293
## 4 CCN51 6 cd.testa 0.920 0.454
## 5 ICS95 0 cd.testa 0.915 0.436
## 6 ICS95 2 cd.testa 0.880 0.326
## 7 ICS95 5 cd.testa 0.962 0.624
## 8 ICS95 6 cd.testa 0.859 0.265
## 9 TCS01 0 cd.testa 0.968 0.657
## 10 TCS01 2 cd.testa 0.802 0.119
## 11 TCS01 5 cd.testa 0.992 0.833
## 12 TCS01 6 cd.testa 0.934 0.503
##Create QQ plot for each cell of design:
ggqqplot(datos.curve3, "cd.testa", ggtheme = theme_bw()) +
facet_grid(dia~ curva*gen, labeller = "label_both")

##Homogneity of variance assumption
##Compute the Levene’s test at each level of the within-subjects factor, here time variable:
lev2<-datos.curve3 %>%
group_by(dia) %>%
levene_test(cd.testa ~ gen)
lev2 %>% as_tibble() %>% print(n=Inf)
## # A tibble: 4 × 5
## dia df1 df2 statistic p
## <fct> <int> <int> <dbl> <dbl>
## 1 0 2 6 0.803 0.491
## 2 2 2 6 0.0730 0.930
## 3 5 2 6 0.212 0.815
## 4 6 2 6 0.488 0.636
##Computation
res.aov2 <- anova_test(
data = datos.curve3, dv = cd.testa, wid = id,
within = dia, between = gen
)
get_anova_table(res.aov2)
## ANOVA Table (type II tests)
##
## Effect DFn DFd F p p<.05 ges
## 1 gen 2 6 11.505 9.00e-03 * 0.699
## 2 dia 3 18 90.448 4.78e-11 * 0.856
## 3 gen:dia 6 18 14.004 6.45e-06 * 0.648
#CCN51
datos.ccn<-filter(datos.curve3, gen=="CCN51")
res.aov.ccn2 <- anova_test(
data = datos.ccn, dv = cd.testa, wid = id,
within = dia
)
get_anova_table(res.aov.ccn2)
## ANOVA Table (type III tests)
##
## Effect DFn DFd F p p<.05 ges
## 1 dia 3 6 62.105 6.56e-05 * 0.949
#ICS95
datos.ics<-filter(datos.curve3, gen=="ICS95")
res.aov.ics2 <- anova_test(
data = datos.ics, dv = cd.testa, wid = id,
within = dia
)
get_anova_table(res.aov.ics2)
## ANOVA Table (type III tests)
##
## Effect DFn DFd F p p<.05 ges
## 1 dia 3 6 40.072 0.000231 * 0.795
#TCS01
datos.tcs<-filter(datos.curve3, gen=="TCS01")
res.aov.tcs2 <- anova_test(
data = datos.tcs, dv = cd.testa, wid = id,
within = dia
)
get_anova_table(res.aov.tcs2)
## ANOVA Table (type III tests)
##
## Effect DFn DFd F p p<.05 ges
## 1 dia 3 6 25.837 0.000789 * 0.85
## Gráficas por réplica y genotipo
datos$dia<-as.numeric(as.character(datos$dia))
##Gráfica por réplica compuesta
pht<- ggplot(datos, aes(x = dia)) +
facet_grid(curva~gen*muestra) +
geom_line(aes(y=cd.testa)) +
geom_point(aes(y=cd.testa)) +
scale_y_continuous(name = expression("Cd (mg*Kg"^"-1)")) + # Etiqueta de la variable continua
scale_x_continuous(name = "dÃa", breaks=seq(0,7,1)) + # Etiqueta de los grupos
theme(axis.line = element_line(colour = "black", # Personalización del tema
size = 0.25)) +
theme(text = element_text(size = 12))
pht

## Gráfica por genotipo
datos2<-summarySE (datos, measurevar = "cd.testa", groupvars = c("curva", "gen","dia"))
write.csv(datos2, "~/Library/CloudStorage/GoogleDrive-icarounam@gmail.com/Mi unidad/Agrosavia/Env_muestra/data/datos_mean.csv")
pht2<- ggplot(datos2, aes(x = dia)) +
facet_grid(curva~gen) +
geom_errorbar(aes(ymin=cd.testa-ci, ymax=cd.testa+ci), width=.1) +
geom_line(aes(y=cd.testa)) +
geom_point(aes(y=cd.testa)) +
scale_y_continuous(name = expression("Cd (mg*Kg"^"-1)")) + # Etiqueta de la variable continua
scale_x_continuous(name = "dÃa", breaks=seq(0,7,1)) + # Etiqueta de los grupos
theme(axis.line = element_line(colour = "black", # Personalización del tema
size = 0.25)) +
theme(text = element_text(size = 15))
pht2
