1.Crear mi diseño experimental => modelo estadístico 2.Colectar los datos 3.Importar y verificar los factores. 4.Análisis de Variancia (aov() o lm()) 5.Comparación de medias 6.Gráfico
Librerias
library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr 1.1.4 ✔ readr 2.1.5
✔ forcats 1.0.1 ✔ stringr 1.5.1
✔ ggplot2 4.0.0 ✔ tibble 3.3.0
✔ lubridate 1.9.4 ✔ tidyr 1.3.1
✔ purrr 1.0.4
── 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(googlesheets4)library(lme4)
Cargando paquete requerido: Matrix
Adjuntando el paquete: 'Matrix'
The following objects are masked from 'package:tidyr':
expand, pack, unpack
library(emmeans)
Welcome to emmeans.
Caution: You lose important information if you filter this package's results.
See '? untidy'
The following object is masked from 'package:dplyr':
select
Adjuntando el paquete: 'TH.data'
The following object is masked from 'package:MASS':
geyser
library(multcompView)library(ggplot2)library(dplyr)# Modelo mixtomd <-lmer(twue ~0+ (1|bloque) + riego*geno, data = fb)# ANOVA tipo II o III según interéslibrary(car)Anova(md, type =3)
# Medias ajustadas para la interacción riego:genoemm <-emmeans(md, ~ riego:geno)# Comparación de medias con ajuste de Tukeycomp <-pairs(emm, adjust ="tukey")# Generación de letras de significancialetras <- multcomp::cld(emm, adjust ="tukey", Letters = letters)
Note: adjust = "tukey" was changed to "sidak"
because "tukey" is only appropriate for one set of pairwise comparisons
letras
riego geno emmean SE df lower.CL upper.CL .group
sequia G06 1.52 0.409 58.3 0.171 2.86 a
irrigado G06 2.11 0.409 58.3 0.760 3.45 ab
irrigado G13 2.91 0.409 58.3 1.566 4.26 abc
sequia G08 3.31 0.409 58.3 1.960 4.65 abcd
sequia G13 3.42 0.409 58.3 2.070 4.76 abcde
irrigado G08 3.77 0.409 58.3 2.428 5.12 bcdef
irrigado G14 3.96 0.409 58.3 2.610 5.30 bcdefg
sequia G12 3.98 0.409 58.3 2.630 5.32 bcdefg
irrigado G02 4.01 0.409 58.3 2.664 5.36 bcdefg
sequia G02 4.28 0.409 58.3 2.930 5.62 cdefgh
irrigado G01 4.31 0.409 58.3 2.968 5.66 cdefgh
irrigado G12 4.57 0.409 58.3 3.226 5.92 cdefghi
sequia G01 4.61 0.409 58.3 3.265 5.96 cdefghi
sequia G14 4.63 0.409 58.3 3.284 5.98 cdefghij
irrigado G10 5.07 0.409 58.3 3.727 6.42 defghijk
sequia G05 5.27 0.409 58.3 3.929 6.62 defghijkl
irrigado G05 5.35 0.409 58.3 4.004 6.70 efghijklm
sequia G04 5.42 0.409 58.3 4.073 6.77 fghijklm
irrigado G04 5.52 0.409 58.3 4.174 6.87 fghijklmn
sequia G09 5.78 0.409 58.3 4.431 7.12 ghijklmno
irrigado G09 6.13 0.409 58.3 4.788 7.48 hijklmno
irrigado G07 6.53 0.409 58.3 5.185 7.88 ijklmno
sequia G10 6.61 0.409 58.3 5.267 7.96 jklmnop
irrigado G03 6.73 0.409 58.3 5.388 8.08 klmnop
sequia G15 7.10 0.409 58.3 5.750 8.44 lmnop
sequia G07 7.12 0.409 58.3 5.779 8.47 lmnop
irrigado G11 7.32 0.409 58.3 5.971 8.66 mnop
irrigado G15 7.47 0.409 58.3 6.124 8.82 nop
sequia G03 7.64 0.409 58.3 6.297 8.99 op
sequia G11 8.59 0.409 58.3 7.241 9.93 p
Degrees-of-freedom method: kenward-roger
Confidence level used: 0.95
Conf-level adjustment: sidak method for 30 estimates
P value adjustment: tukey method for comparing a family of 30 estimates
significance level used: alpha = 0.05
NOTE: If two or more means share the same grouping symbol,
then we cannot show them to be different.
But we also did not show them to be the same.
# Limpieza del data frame con letrasletras_df <- letras %>%as.data.frame() %>%mutate(riego =factor(riego, levels =unique(fb$riego)),geno =factor(geno, levels =unique(fb$geno)))
ggplot(letras_df, aes(x = geno, y = emmean, fill = riego)) +geom_col(position =position_dodge(width =0.8)) +geom_errorbar(aes(ymin = emmean - SE, ymax = emmean + SE),width =0.2, position =position_dodge(width =0.8)) +geom_text(aes(label = .group, y = emmean + SE +0.05),position =position_dodge(width =0.8),size =3, vjust =0, angle =90) +labs(x ="Genotipos", y ="TWUE (eficiencia del uso del agua total)",fill ="Riego") +theme_classic(base_size =14) +theme(axis.text.x =element_text(angle =45, hjust =1))
library(inti)
Cargando paquete requerido: shiny
letras_df %>%plot_smr(x ="geno", y ="emmean", group ="riego" , error ="SE", sig =".group")