setwd("G:/Mi unidad/Agrosavia/FeCa/Fenoma/Análisis/Carbono")
datos<-read.table("carbonf2.csv", header=T, sep=';')
##Librerias

library(lme4)
## Cargando paquete requerido: Matrix
library(lmerTest)   # p-values
## Warning: package 'lmerTest' was built under R version 4.4.3
## 
## Adjuntando el paquete: 'lmerTest'
## The following object is masked from 'package:lme4':
## 
##     lmer
## The following object is masked from 'package:stats':
## 
##     step
library(emmeans)    # post hoc
## Welcome to emmeans.
## Caution: You lose important information if you filter this package's results.
## See '? untidy'
library(dplyr)
## 
## Adjuntando el paquete: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(tidyr)
## 
## Adjuntando el paquete: 'tidyr'
## The following objects are masked from 'package:Matrix':
## 
##     expand, pack, unpack
library(agricolae)
## Warning: package 'agricolae' was built under R version 4.4.3
library(rgl)
## Warning: package 'rgl' was built under R version 4.4.3
library(tkrplot)
## Warning: package 'tkrplot' was built under R version 4.4.3
## Cargando paquete requerido: tcltk
library(GGEBiplots)
## Warning: package 'GGEBiplots' was built under R version 4.4.3
library(metan)
## Warning: package 'metan' was built under R version 4.4.3
## |=========================================================|
## | Multi-Environment Trial Analysis (metan) v1.19.0        |
## | Author: Tiago Olivoto                                   |
## | Type 'citation('metan')' to know how to cite metan      |
## | Type 'vignette('metan_start')' for a short tutorial     |
## | Visit 'https://bit.ly/metanpkg' for a complete tutorial |
## |=========================================================|
## 
## Adjuntando el paquete: 'metan'
## The following object is masked from 'package:tidyr':
## 
##     replace_na
## The following object is masked from 'package:dplyr':
## 
##     recode_factor
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.4.3
##Convertir a factor
datos$gen <- factor(datos$gen)
datos$municipio  <- factor(datos$municipio)
datos$mun  <- factor(datos$mun)
datos$reg  <- factor(datos$reg)

#Modelo 0
modelo <- lm (log(total_alt_co2) ~ gen * mun,
               data = datos)
anova(modelo)
## Analysis of Variance Table
## 
## Response: log(total_alt_co2)
##            Df Sum Sq Mean Sq F value    Pr(>F)    
## gen         7  5.767  0.8239  3.5647  0.001163 ** 
## mun         9 76.338  8.4820 36.7007 < 2.2e-16 ***
## gen:mun    60 18.987  0.3165  1.3693  0.052954 .  
## Residuals 231 53.387  0.2311                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#Modelo bruto
modelo <- lm ((total_alt_co2) ~ gen * mun,
              data = datos)
anova(modelo)
## Analysis of Variance Table
## 
## Response: (total_alt_co2)
##            Df Sum Sq Mean Sq F value  Pr(>F)    
## gen         7  243.1   34.72  2.4964 0.01723 *  
## mun         9 6505.9  722.88 51.9710 < 2e-16 ***
## gen:mun    60 1017.1   16.95  1.2187 0.15344    
## Residuals 231 3213.0   13.91                    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##Contrastes a posteriori
#Genotipos
g<-emmeans(modelo, pairwise ~ gen)
## NOTE: Results may be misleading due to involvement in interactions
g
## $emmeans
##  gen    emmean   SE  df lower.CL upper.CL
##  CNCH12   7.70 0.59 231     6.53     8.86
##  CNCH13   9.06 0.59 231     7.90    10.22
##  FBO1     7.83 0.59 231     6.67     8.99
##  FCHI8  nonEst   NA  NA       NA       NA
##  FEAR5    9.59 0.59 231     8.43    10.76
##  FGI4     8.29 0.59 231     7.13     9.45
##  FMA7     6.92 0.59 231     5.76     8.08
##  FSV1   nonEst   NA  NA       NA       NA
## 
## Results are averaged over the levels of: mun 
## Results are given on the ( (not the response) scale. 
## Confidence level used: 0.95 
## 
## $contrasts
##  contrast        estimate    SE  df t.ratio p.value
##  CNCH12 - CNCH13   -1.365 0.834 231  -1.637  0.5750
##  CNCH12 - FBO1     -0.133 0.834 231  -0.159  1.0000
##  CNCH12 - FCHI8    nonEst    NA  NA      NA      NA
##  CNCH12 - FEAR5    -1.898 0.834 231  -2.276  0.2080
##  CNCH12 - FGI4     -0.595 0.834 231  -0.713  0.9802
##  CNCH12 - FMA7      0.779 0.834 231   0.934  0.9374
##  CNCH12 - FSV1     nonEst    NA  NA      NA      NA
##  CNCH13 - FBO1      1.232 0.834 231   1.477  0.6791
##  CNCH13 - FCHI8    nonEst    NA  NA      NA      NA
##  CNCH13 - FEAR5    -0.533 0.834 231  -0.640  0.9879
##  CNCH13 - FGI4      0.770 0.834 231   0.923  0.9402
##  CNCH13 - FMA7      2.144 0.834 231   2.571  0.1088
##  CNCH13 - FSV1     nonEst    NA  NA      NA      NA
##  FBO1 - FCHI8      nonEst    NA  NA      NA      NA
##  FBO1 - FEAR5      -1.765 0.834 231  -2.117  0.2822
##  FBO1 - FGI4       -0.462 0.834 231  -0.554  0.9938
##  FBO1 - FMA7        0.912 0.834 231   1.093  0.8837
##  FBO1 - FSV1       nonEst    NA  NA      NA      NA
##  FCHI8 - FEAR5     nonEst    NA  NA      NA      NA
##  FCHI8 - FGI4      nonEst    NA  NA      NA      NA
##  FCHI8 - FMA7      nonEst    NA  NA      NA      NA
##  FCHI8 - FSV1      nonEst    NA  NA      NA      NA
##  FEAR5 - FGI4       1.303 0.834 231   1.563  0.6238
##  FEAR5 - FMA7       2.677 0.834 231   3.210  0.0187
##  FEAR5 - FSV1      nonEst    NA  NA      NA      NA
##  FGI4 - FMA7        1.374 0.834 231   1.647  0.5682
##  FGI4 - FSV1       nonEst    NA  NA      NA      NA
##  FMA7 - FSV1       nonEst    NA  NA      NA      NA
## 
## Results are averaged over the levels of: mun 
## Note: contrasts are still on the ( scale. Consider using
##       regrid() if you want contrasts of back-transformed estimates. 
## P value adjustment: tukey method for comparing a family of 6 estimates
multcomp::cld(g, Letters = LETTERS)
##  gen    emmean   SE  df lower.CL upper.CL .group
##  FMA7     6.92 0.59 231     5.76     8.08  A    
##  CNCH12   7.70 0.59 231     6.53     8.86  AB   
##  FBO1     7.83 0.59 231     6.67     8.99  AB   
##  FGI4     8.29 0.59 231     7.13     9.45  AB   
##  CNCH13   9.06 0.59 231     7.90    10.22  AB   
##  FEAR5    9.59 0.59 231     8.43    10.76   B   
##  FCHI8  nonEst   NA  NA       NA       NA       
##  FSV1   nonEst   NA  NA       NA       NA       
## 
## Results are averaged over the levels of: mun 
## Results are given on the ( (not the response) scale. 
## Confidence level used: 0.95 
## Note: contrasts are still on the ( scale. Consider using
##       regrid() if you want contrasts of back-transformed estimates. 
## P value adjustment: tukey method for comparing a family of 6 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.
pwpp(g, type = "response")
## Warning: `aes_()` was deprecated in ggplot2 3.0.0.
## ℹ Please use tidy evaluation idioms with `aes()`
## ℹ The deprecated feature was likely used in the emmeans package.
##   Please report the issue at <https://github.com/rvlenth/emmeans/issues>.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## Warning: Removed 26 rows containing missing values or values outside the scale range
## (`geom_point()`).
## Warning: Removed 26 rows containing missing values or values outside the scale range
## (`geom_segment()`).

#Municipios
m<-emmeans(modelo, pairwise ~ mun)
## NOTE: Results may be misleading due to involvement in interactions
m
## $emmeans
##  mun              emmean    SE  df lower.CL upper.CL
##  Chi                3.53 0.659 231     2.23     4.83
##  Gig                5.19 0.659 231     3.90     6.49
##  HtC                5.98 0.659 231     4.68     7.28
##  Jam              nonEst    NA  NA       NA       NA
##  PtR              nonEst    NA  NA       NA       NA
##  RiN                6.58 0.659 231     5.28     7.88
##  SnV                3.35 0.659 231     2.05     4.65
##  Tam               19.96 0.659 231    18.66    21.25
##  ViG                9.21 0.659 231     7.91    10.51
##  Yac                8.41 0.659 231     7.11     9.70
## 
## Results are averaged over the levels of: gen 
## Results are given on the ( (not the response) scale. 
## Confidence level used: 0.95 
## 
## $contrasts
##  contrast               estimate    SE  df t.ratio p.value
##  Chi - Gig                -1.664 0.932 231  -1.784  0.6312
##  Chi - HtC                -2.449 0.932 231  -2.626  0.1519
##  Chi - Jam                nonEst    NA  NA      NA      NA
##  Chi - PtR                nonEst    NA  NA      NA      NA
##  Chi - RiN                -3.052 0.932 231  -3.273  0.0265
##  Chi - SnV                 0.178 0.932 231   0.191  1.0000
##  Chi - Tam               -16.426 0.932 231 -17.617  <.0001
##  Chi - ViG                -5.676 0.932 231  -6.088  <.0001
##  Chi - Yac                -4.875 0.932 231  -5.229  <.0001
##  Gig - HtC                -0.785 0.932 231  -0.842  0.9905
##  Gig - Jam                nonEst    NA  NA      NA      NA
##  Gig - PtR                nonEst    NA  NA      NA      NA
##  Gig - RiN                -1.388 0.932 231  -1.489  0.8129
##  Gig - SnV                 1.841 0.932 231   1.975  0.5010
##  Gig - Tam               -14.762 0.932 231 -15.832  <.0001
##  Gig - ViG                -4.013 0.932 231  -4.304  0.0006
##  Gig - Yac                -3.212 0.932 231  -3.444  0.0154
##  HtC - Jam                nonEst    NA  NA      NA      NA
##  HtC - PtR                nonEst    NA  NA      NA      NA
##  HtC - RiN                -0.603 0.932 231  -0.647  0.9981
##  HtC - SnV                 2.626 0.932 231   2.817  0.0959
##  HtC - Tam               -13.977 0.932 231 -14.991  <.0001
##  HtC - ViG                -3.228 0.932 231  -3.462  0.0146
##  HtC - Yac                -2.427 0.932 231  -2.603  0.1603
##  Jam - PtR                nonEst    NA  NA      NA      NA
##  Jam - RiN                nonEst    NA  NA      NA      NA
##  Jam - SnV                nonEst    NA  NA      NA      NA
##  Jam - Tam                nonEst    NA  NA      NA      NA
##  Jam - ViG                nonEst    NA  NA      NA      NA
##  Jam - Yac                nonEst    NA  NA      NA      NA
##  PtR - RiN                nonEst    NA  NA      NA      NA
##  PtR - SnV                nonEst    NA  NA      NA      NA
##  PtR - Tam                nonEst    NA  NA      NA      NA
##  PtR - ViG                nonEst    NA  NA      NA      NA
##  PtR - Yac                nonEst    NA  NA      NA      NA
##  RiN              - SnV    3.230 0.932 231   3.464  0.0145
##  RiN              - Tam  -13.374 0.932 231 -14.344  <.0001
##  RiN              - ViG   -2.624 0.932 231  -2.815  0.0963
##  RiN              - Yac   -1.824 0.932 231  -1.956  0.5141
##  SnV - Tam               -16.603 0.932 231 -17.807  <.0001
##  SnV - ViG                -5.854 0.932 231  -6.279  <.0001
##  SnV - Yac                -5.053 0.932 231  -5.420  <.0001
##  Tam - ViG                10.749 0.932 231  11.529  <.0001
##  Tam - Yac                11.550 0.932 231  12.388  <.0001
##  ViG - Yac                 0.801 0.932 231   0.859  0.9892
## 
## Results are averaged over the levels of: gen 
## Note: contrasts are still on the ( scale. Consider using
##       regrid() if you want contrasts of back-transformed estimates. 
## P value adjustment: tukey method for comparing a family of 8 estimates
multcomp::cld(m, Letters = LETTERS)
##  mun              emmean    SE  df lower.CL upper.CL .group
##  SnV                3.35 0.659 231     2.05     4.65  A    
##  Chi                3.53 0.659 231     2.23     4.83  A    
##  Gig                5.19 0.659 231     3.90     6.49  AB   
##  HtC                5.98 0.659 231     4.68     7.28  ABC  
##  RiN                6.58 0.659 231     5.28     7.88   BCD 
##  Yac                8.41 0.659 231     7.11     9.70    CD 
##  ViG                9.21 0.659 231     7.91    10.51     D 
##  Tam               19.96 0.659 231    18.66    21.25      E
##  Jam              nonEst    NA  NA       NA       NA       
##  PtR              nonEst    NA  NA       NA       NA       
## 
## Results are averaged over the levels of: gen 
## Results are given on the ( (not the response) scale. 
## Confidence level used: 0.95 
## Note: contrasts are still on the ( scale. Consider using
##       regrid() if you want contrasts of back-transformed estimates. 
## P value adjustment: tukey method for comparing a family of 8 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.
#Interacción
gm<-emmeans(modelo, pairwise ~ gen|mun)
gm
## $emmeans
## mun = Chi:
##  gen    emmean   SE  df lower.CL upper.CL
##  CNCH12   3.09 1.86 231   -0.585     6.76
##  CNCH13   4.70 1.86 231    1.027     8.38
##  FBO1     4.35 1.86 231    0.672     8.02
##  FCHI8    2.02 1.86 231   -1.657     5.69
##  FEAR5    4.45 1.86 231    0.780     8.13
##  FGI4     3.18 1.86 231   -0.497     6.85
##  FMA7     3.30 1.86 231   -0.374     6.97
##  FSV1     3.16 1.86 231   -0.516     6.83
## 
## mun = Gig:
##  gen    emmean   SE  df lower.CL upper.CL
##  CNCH12   2.82 1.86 231   -0.858     6.49
##  CNCH13   5.88 1.86 231    2.210     9.56
##  FBO1     5.60 1.86 231    1.924     9.27
##  FCHI8    7.53 1.86 231    3.858    11.21
##  FEAR5    6.39 1.86 231    2.715    10.06
##  FGI4     4.72 1.86 231    1.046     8.39
##  FMA7     4.81 1.86 231    1.138     8.49
##  FSV1     3.80 1.86 231    0.127     7.48
## 
## mun = HtC:
##  gen    emmean   SE  df lower.CL upper.CL
##  CNCH12   5.94 1.86 231    2.269     9.62
##  CNCH13   5.66 1.86 231    1.987     9.34
##  FBO1     6.19 1.86 231    2.518     9.87
##  FCHI8    5.14 1.86 231    1.464     8.81
##  FEAR5    6.39 1.86 231    2.714    10.06
##  FGI4     5.94 1.86 231    2.267     9.62
##  FMA7     6.00 1.86 231    2.326     9.67
##  FSV1     6.57 1.86 231    2.895    10.24
## 
## mun = Jam:
##  gen    emmean   SE  df lower.CL upper.CL
##  CNCH12  10.59 1.86 231    6.914    14.26
##  CNCH13  12.90 1.86 231    9.230    16.58
##  FBO1     8.12 1.86 231    4.444    11.79
##  FCHI8  nonEst   NA  NA       NA       NA
##  FEAR5   12.41 1.86 231    8.740    16.09
##  FGI4     9.89 1.86 231    6.215    13.56
##  FMA7     7.81 1.86 231    4.135    11.48
##  FSV1   nonEst   NA  NA       NA       NA
## 
## mun = PtR:
##  gen    emmean   SE  df lower.CL upper.CL
##  CNCH12   8.48 1.86 231    4.802    12.15
##  CNCH13   8.21 1.86 231    4.540    11.89
##  FBO1     9.41 1.86 231    5.732    13.08
##  FCHI8  nonEst   NA  NA       NA       NA
##  FEAR5   10.82 1.86 231    7.149    14.50
##  FGI4     6.79 1.86 231    3.121    10.47
##  FMA7     6.25 1.86 231    2.580     9.93
##  FSV1     7.31 1.86 231    3.635    10.98
## 
## mun = RiN             :
##  gen    emmean   SE  df lower.CL upper.CL
##  CNCH12   7.41 1.86 231    3.735    11.08
##  CNCH13   7.19 1.86 231    3.516    10.86
##  FBO1     7.76 1.86 231    4.091    11.44
##  FCHI8    5.30 1.86 231    1.629     8.98
##  FEAR5    6.20 1.86 231    2.527     9.87
##  FGI4     4.78 1.86 231    1.110     8.46
##  FMA7     9.17 1.86 231    5.492    12.84
##  FSV1     4.84 1.86 231    1.166     8.51
## 
## mun = SnV:
##  gen    emmean   SE  df lower.CL upper.CL
##  CNCH12   3.08 1.86 231   -0.595     6.75
##  CNCH13   4.03 1.86 231    0.353     7.70
##  FBO1     2.73 1.86 231   -0.942     6.41
##  FCHI8    2.65 1.86 231   -1.027     6.32
##  FEAR5    5.55 1.86 231    1.876     9.22
##  FGI4     2.43 1.86 231   -1.242     6.11
##  FMA7     3.90 1.86 231    0.222     7.57
##  FSV1     2.46 1.86 231   -1.215     6.13
## 
## mun = Tam:
##  gen    emmean   SE  df lower.CL upper.CL
##  CNCH12  20.08 1.86 231   16.407    23.75
##  CNCH13  23.68 1.86 231   20.010    27.36
##  FBO1    20.98 1.86 231   17.302    24.65
##  FCHI8   19.95 1.86 231   16.273    23.62
##  FEAR5   16.66 1.86 231   12.990    20.34
##  FGI4    24.03 1.86 231   20.357    27.71
##  FMA7    13.53 1.86 231    9.858    17.21
##  FSV1    20.73 1.86 231   17.059    24.41
## 
## mun = ViG:
##  gen    emmean   SE  df lower.CL upper.CL
##  CNCH12   6.10 1.86 231    2.424     9.77
##  CNCH13  12.32 1.86 231    8.647    16.00
##  FBO1     6.05 1.86 231    2.379     9.73
##  FCHI8    5.78 1.86 231    2.102     9.45
##  FEAR5   16.73 1.86 231   13.060    20.41
##  FGI4     8.56 1.86 231    4.883    12.23
##  FMA7     8.90 1.86 231    5.222    12.57
##  FSV1     9.22 1.86 231    5.543    12.89
## 
## mun = Yac:
##  gen    emmean   SE  df lower.CL upper.CL
##  CNCH12   9.38 1.86 231    5.706    13.05
##  CNCH13   6.02 1.86 231    2.350     9.70
##  FBO1     7.11 1.86 231    3.431    10.78
##  FCHI8    9.42 1.86 231    5.747    13.10
##  FEAR5   10.33 1.86 231    6.653    14.00
##  FGI4    12.58 1.86 231    8.909    16.26
##  FMA7     5.51 1.86 231    1.835     9.18
##  FSV1     6.90 1.86 231    3.223    10.57
## 
## Results are given on the ( (not the response) scale. 
## Confidence level used: 0.95 
## 
## $contrasts
## mun = Chi:
##  contrast        estimate   SE  df t.ratio p.value
##  CNCH12 - CNCH13  -1.6122 2.64 231  -0.611  0.9987
##  CNCH12 - FBO1    -1.2566 2.64 231  -0.476  0.9997
##  CNCH12 - FCHI8    1.0724 2.64 231   0.407  0.9999
##  CNCH12 - FEAR5   -1.3644 2.64 231  -0.517  0.9996
##  CNCH12 - FGI4    -0.0880 2.64 231  -0.033  1.0000
##  CNCH12 - FMA7    -0.2110 2.64 231  -0.080  1.0000
##  CNCH12 - FSV1    -0.0683 2.64 231  -0.026  1.0000
##  CNCH13 - FBO1     0.3556 2.64 231   0.135  1.0000
##  CNCH13 - FCHI8    2.6845 2.64 231   1.018  0.9714
##  CNCH13 - FEAR5    0.2477 2.64 231   0.094  1.0000
##  CNCH13 - FGI4     1.5242 2.64 231   0.578  0.9991
##  CNCH13 - FMA7     1.4011 2.64 231   0.531  0.9995
##  CNCH13 - FSV1     1.5439 2.64 231   0.585  0.9990
##  FBO1 - FCHI8      2.3290 2.64 231   0.883  0.9873
##  FBO1 - FEAR5     -0.1079 2.64 231  -0.041  1.0000
##  FBO1 - FGI4       1.1686 2.64 231   0.443  0.9998
##  FBO1 - FMA7       1.0455 2.64 231   0.396  0.9999
##  FBO1 - FSV1       1.1883 2.64 231   0.451  0.9998
##  FCHI8 - FEAR5    -2.4368 2.64 231  -0.924  0.9835
##  FCHI8 - FGI4     -1.1604 2.64 231  -0.440  0.9999
##  FCHI8 - FMA7     -1.2834 2.64 231  -0.487  0.9997
##  FCHI8 - FSV1     -1.1407 2.64 231  -0.433  0.9999
##  FEAR5 - FGI4      1.2764 2.64 231   0.484  0.9997
##  FEAR5 - FMA7      1.1534 2.64 231   0.437  0.9999
##  FEAR5 - FSV1      1.2962 2.64 231   0.491  0.9997
##  FGI4 - FMA7      -0.1231 2.64 231  -0.047  1.0000
##  FGI4 - FSV1       0.0197 2.64 231   0.007  1.0000
##  FMA7 - FSV1       0.1428 2.64 231   0.054  1.0000
## 
## mun = Gig:
##  contrast        estimate   SE  df t.ratio p.value
##  CNCH12 - CNCH13  -3.0684 2.64 231  -1.164  0.9413
##  CNCH12 - FBO1    -2.7817 2.64 231  -1.055  0.9652
##  CNCH12 - FCHI8   -4.7163 2.64 231  -1.788  0.6286
##  CNCH12 - FEAR5   -3.5731 2.64 231  -1.355  0.8764
##  CNCH12 - FGI4    -1.9040 2.64 231  -0.722  0.9963
##  CNCH12 - FMA7    -1.9960 2.64 231  -0.757  0.9950
##  CNCH12 - FSV1    -0.9850 2.64 231  -0.373  1.0000
##  CNCH13 - FBO1     0.2867 2.64 231   0.109  1.0000
##  CNCH13 - FCHI8   -1.6479 2.64 231  -0.625  0.9985
##  CNCH13 - FEAR5   -0.5047 2.64 231  -0.191  1.0000
##  CNCH13 - FGI4     1.1643 2.64 231   0.442  0.9998
##  CNCH13 - FMA7     1.0724 2.64 231   0.407  0.9999
##  CNCH13 - FSV1     2.0834 2.64 231   0.790  0.9935
##  FBO1 - FCHI8     -1.9346 2.64 231  -0.734  0.9959
##  FBO1 - FEAR5     -0.7914 2.64 231  -0.300  1.0000
##  FBO1 - FGI4       0.8777 2.64 231   0.333  1.0000
##  FBO1 - FMA7       0.7857 2.64 231   0.298  1.0000
##  FBO1 - FSV1       1.7968 2.64 231   0.681  0.9974
##  FCHI8 - FEAR5     1.1432 2.64 231   0.433  0.9999
##  FCHI8 - FGI4      2.8122 2.64 231   1.066  0.9630
##  FCHI8 - FMA7      2.7203 2.64 231   1.032  0.9692
##  FCHI8 - FSV1      3.7313 2.64 231   1.415  0.8497
##  FEAR5 - FGI4      1.6691 2.64 231   0.633  0.9984
##  FEAR5 - FMA7      1.5771 2.64 231   0.598  0.9989
##  FEAR5 - FSV1      2.5881 2.64 231   0.981  0.9767
##  FGI4 - FMA7      -0.0919 2.64 231  -0.035  1.0000
##  FGI4 - FSV1       0.9191 2.64 231   0.349  1.0000
##  FMA7 - FSV1       1.0110 2.64 231   0.383  0.9999
## 
## mun = HtC:
##  contrast        estimate   SE  df t.ratio p.value
##  CNCH12 - CNCH13   0.2826 2.64 231   0.107  1.0000
##  CNCH12 - FBO1    -0.2490 2.64 231  -0.094  1.0000
##  CNCH12 - FCHI8    0.8058 2.64 231   0.306  1.0000
##  CNCH12 - FEAR5   -0.4449 2.64 231  -0.169  1.0000
##  CNCH12 - FGI4     0.0022 2.64 231   0.001  1.0000
##  CNCH12 - FMA7    -0.0561 2.64 231  -0.021  1.0000
##  CNCH12 - FSV1    -0.6251 2.64 231  -0.237  1.0000
##  CNCH13 - FBO1    -0.5316 2.64 231  -0.202  1.0000
##  CNCH13 - FCHI8    0.5232 2.64 231   0.198  1.0000
##  CNCH13 - FEAR5   -0.7275 2.64 231  -0.276  1.0000
##  CNCH13 - FGI4    -0.2804 2.64 231  -0.106  1.0000
##  CNCH13 - FMA7    -0.3387 2.64 231  -0.128  1.0000
##  CNCH13 - FSV1    -0.9077 2.64 231  -0.344  1.0000
##  FBO1 - FCHI8      1.0548 2.64 231   0.400  0.9999
##  FBO1 - FEAR5     -0.1959 2.64 231  -0.074  1.0000
##  FBO1 - FGI4       0.2512 2.64 231   0.095  1.0000
##  FBO1 - FMA7       0.1929 2.64 231   0.073  1.0000
##  FBO1 - FSV1      -0.3761 2.64 231  -0.143  1.0000
##  FCHI8 - FEAR5    -1.2508 2.64 231  -0.474  0.9998
##  FCHI8 - FGI4     -0.8036 2.64 231  -0.305  1.0000
##  FCHI8 - FMA7     -0.8619 2.64 231  -0.327  1.0000
##  FCHI8 - FSV1     -1.4309 2.64 231  -0.543  0.9994
##  FEAR5 - FGI4      0.4471 2.64 231   0.170  1.0000
##  FEAR5 - FMA7      0.3889 2.64 231   0.147  1.0000
##  FEAR5 - FSV1     -0.1802 2.64 231  -0.068  1.0000
##  FGI4 - FMA7      -0.0583 2.64 231  -0.022  1.0000
##  FGI4 - FSV1      -0.6273 2.64 231  -0.238  1.0000
##  FMA7 - FSV1      -0.5690 2.64 231  -0.216  1.0000
## 
## mun = Jam:
##  contrast        estimate   SE  df t.ratio p.value
##  CNCH12 - CNCH13  -2.3159 2.64 231  -0.878  0.9514
##  CNCH12 - FBO1     2.4705 2.64 231   0.937  0.9366
##  CNCH12 - FCHI8    nonEst   NA  NA      NA      NA
##  CNCH12 - FEAR5   -1.8259 2.64 231  -0.692  0.9827
##  CNCH12 - FGI4     0.6985 2.64 231   0.265  0.9998
##  CNCH12 - FMA7     2.7793 2.64 231   1.054  0.8989
##  CNCH12 - FSV1     nonEst   NA  NA      NA      NA
##  CNCH13 - FBO1     4.7864 2.64 231   1.815  0.4581
##  CNCH13 - FCHI8    nonEst   NA  NA      NA      NA
##  CNCH13 - FEAR5    0.4900 2.64 231   0.186  1.0000
##  CNCH13 - FGI4     3.0145 2.64 231   1.143  0.8628
##  CNCH13 - FMA7     5.0953 2.64 231   1.932  0.3853
##  CNCH13 - FSV1     nonEst   NA  NA      NA      NA
##  FBO1 - FCHI8      nonEst   NA  NA      NA      NA
##  FBO1 - FEAR5     -4.2964 2.64 231  -1.629  0.5801
##  FBO1 - FGI4      -1.7719 2.64 231  -0.672  0.9849
##  FBO1 - FMA7       0.3089 2.64 231   0.117  1.0000
##  FBO1 - FSV1       nonEst   NA  NA      NA      NA
##  FCHI8 - FEAR5     nonEst   NA  NA      NA      NA
##  FCHI8 - FGI4      nonEst   NA  NA      NA      NA
##  FCHI8 - FMA7      nonEst   NA  NA      NA      NA
##  FCHI8 - FSV1      nonEst   NA  NA      NA      NA
##  FEAR5 - FGI4      2.5244 2.64 231   0.957  0.9308
##  FEAR5 - FMA7      4.6052 2.64 231   1.746  0.5027
##  FEAR5 - FSV1      nonEst   NA  NA      NA      NA
##  FGI4 - FMA7       2.0808 2.64 231   0.789  0.9692
##  FGI4 - FSV1       nonEst   NA  NA      NA      NA
##  FMA7 - FSV1       nonEst   NA  NA      NA      NA
## 
## mun = PtR:
##  contrast        estimate   SE  df t.ratio p.value
##  CNCH12 - CNCH13   0.2620 2.64 231   0.099  1.0000
##  CNCH12 - FBO1    -0.9295 2.64 231  -0.352  0.9998
##  CNCH12 - FCHI8    nonEst   NA  NA      NA      NA
##  CNCH12 - FEAR5   -2.3466 2.64 231  -0.890  0.9738
##  CNCH12 - FGI4     1.6814 2.64 231   0.638  0.9955
##  CNCH12 - FMA7     2.2219 2.64 231   0.843  0.9801
##  CNCH12 - FSV1     1.1670 2.64 231   0.443  0.9994
##  CNCH13 - FBO1    -1.1914 2.64 231  -0.452  0.9993
##  CNCH13 - FCHI8    nonEst   NA  NA      NA      NA
##  CNCH13 - FEAR5   -2.6085 2.64 231  -0.989  0.9560
##  CNCH13 - FGI4     1.4195 2.64 231   0.538  0.9982
##  CNCH13 - FMA7     1.9599 2.64 231   0.743  0.9897
##  CNCH13 - FSV1     0.9051 2.64 231   0.343  0.9999
##  FBO1 - FCHI8      nonEst   NA  NA      NA      NA
##  FBO1 - FEAR5     -1.4171 2.64 231  -0.537  0.9983
##  FBO1 - FGI4       2.6109 2.64 231   0.990  0.9558
##  FBO1 - FMA7       3.1513 2.64 231   1.195  0.8955
##  FBO1 - FSV1       2.0965 2.64 231   0.795  0.9853
##  FCHI8 - FEAR5     nonEst   NA  NA      NA      NA
##  FCHI8 - FGI4      nonEst   NA  NA      NA      NA
##  FCHI8 - FMA7      nonEst   NA  NA      NA      NA
##  FCHI8 - FSV1      nonEst   NA  NA      NA      NA
##  FEAR5 - FGI4      4.0280 2.64 231   1.527  0.7281
##  FEAR5 - FMA7      4.5684 2.64 231   1.732  0.5951
##  FEAR5 - FSV1      3.5136 2.64 231   1.332  0.8361
##  FGI4 - FMA7       0.5404 2.64 231   0.205  1.0000
##  FGI4 - FSV1      -0.5144 2.64 231  -0.195  1.0000
##  FMA7 - FSV1      -1.0548 2.64 231  -0.400  0.9997
## 
## mun = RiN             :
##  contrast        estimate   SE  df t.ratio p.value
##  CNCH12 - CNCH13   0.2198 2.64 231   0.083  1.0000
##  CNCH12 - FBO1    -0.3554 2.64 231  -0.135  1.0000
##  CNCH12 - FCHI8    2.1064 2.64 231   0.799  0.9931
##  CNCH12 - FEAR5    1.2087 2.64 231   0.458  0.9998
##  CNCH12 - FGI4     2.6258 2.64 231   0.996  0.9747
##  CNCH12 - FMA7    -1.7569 2.64 231  -0.666  0.9978
##  CNCH12 - FSV1     2.5699 2.64 231   0.974  0.9776
##  CNCH13 - FBO1    -0.5751 2.64 231  -0.218  1.0000
##  CNCH13 - FCHI8    1.8867 2.64 231   0.715  0.9965
##  CNCH13 - FEAR5    0.9889 2.64 231   0.375  0.9999
##  CNCH13 - FGI4     2.4060 2.64 231   0.912  0.9847
##  CNCH13 - FMA7    -1.9767 2.64 231  -0.750  0.9953
##  CNCH13 - FSV1     2.3501 2.64 231   0.891  0.9866
##  FBO1 - FCHI8      2.4618 2.64 231   0.933  0.9825
##  FBO1 - FEAR5      1.5640 2.64 231   0.593  0.9989
##  FBO1 - FGI4       2.9812 2.64 231   1.130  0.9495
##  FBO1 - FMA7      -1.4016 2.64 231  -0.531  0.9995
##  FBO1 - FSV1       2.9252 2.64 231   1.109  0.9543
##  FCHI8 - FEAR5    -0.8977 2.64 231  -0.340  1.0000
##  FCHI8 - FGI4      0.5194 2.64 231   0.197  1.0000
##  FCHI8 - FMA7     -3.8634 2.64 231  -1.465  0.8252
##  FCHI8 - FSV1      0.4635 2.64 231   0.176  1.0000
##  FEAR5 - FGI4      1.4171 2.64 231   0.537  0.9994
##  FEAR5 - FMA7     -2.9656 2.64 231  -1.125  0.9509
##  FEAR5 - FSV1      1.3612 2.64 231   0.516  0.9996
##  FGI4 - FMA7      -4.3827 2.64 231  -1.662  0.7117
##  FGI4 - FSV1      -0.0559 2.64 231  -0.021  1.0000
##  FMA7 - FSV1       4.3268 2.64 231   1.641  0.7250
## 
## mun = SnV:
##  contrast        estimate   SE  df t.ratio p.value
##  CNCH12 - CNCH13  -0.9477 2.64 231  -0.359  1.0000
##  CNCH12 - FBO1     0.3474 2.64 231   0.132  1.0000
##  CNCH12 - FCHI8    0.4322 2.64 231   0.164  1.0000
##  CNCH12 - FEAR5   -2.4711 2.64 231  -0.937  0.9821
##  CNCH12 - FGI4     0.6473 2.64 231   0.245  1.0000
##  CNCH12 - FMA7    -0.8167 2.64 231  -0.310  1.0000
##  CNCH12 - FSV1     0.6204 2.64 231   0.235  1.0000
##  CNCH13 - FBO1     1.2951 2.64 231   0.491  0.9997
##  CNCH13 - FCHI8    1.3800 2.64 231   0.523  0.9995
##  CNCH13 - FEAR5   -1.5234 2.64 231  -0.578  0.9991
##  CNCH13 - FGI4     1.5950 2.64 231   0.605  0.9988
##  CNCH13 - FMA7     0.1310 2.64 231   0.050  1.0000
##  CNCH13 - FSV1     1.5681 2.64 231   0.595  0.9989
##  FBO1 - FCHI8      0.0849 2.64 231   0.032  1.0000
##  FBO1 - FEAR5     -2.8185 2.64 231  -1.069  0.9626
##  FBO1 - FGI4       0.2999 2.64 231   0.114  1.0000
##  FBO1 - FMA7      -1.1641 2.64 231  -0.441  0.9998
##  FBO1 - FSV1       0.2730 2.64 231   0.104  1.0000
##  FCHI8 - FEAR5    -2.9034 2.64 231  -1.101  0.9561
##  FCHI8 - FGI4      0.2150 2.64 231   0.082  1.0000
##  FCHI8 - FMA7     -1.2490 2.64 231  -0.474  0.9998
##  FCHI8 - FSV1      0.1882 2.64 231   0.071  1.0000
##  FEAR5 - FGI4      3.1184 2.64 231   1.182  0.9363
##  FEAR5 - FMA7      1.6544 2.64 231   0.627  0.9985
##  FEAR5 - FSV1      3.0915 2.64 231   1.172  0.9390
##  FGI4 - FMA7      -1.4640 2.64 231  -0.555  0.9993
##  FGI4 - FSV1      -0.0269 2.64 231  -0.010  1.0000
##  FMA7 - FSV1       1.4371 2.64 231   0.545  0.9994
## 
## mun = Tam:
##  contrast        estimate   SE  df t.ratio p.value
##  CNCH12 - CNCH13  -3.6028 2.64 231  -1.366  0.8716
##  CNCH12 - FBO1    -0.8956 2.64 231  -0.340  1.0000
##  CNCH12 - FCHI8    0.1341 2.64 231   0.051  1.0000
##  CNCH12 - FEAR5    3.4166 2.64 231   1.296  0.8998
##  CNCH12 - FGI4    -3.9506 2.64 231  -1.498  0.8079
##  CNCH12 - FMA7     6.5490 2.64 231   2.483  0.2078
##  CNCH12 - FSV1    -0.6523 2.64 231  -0.247  1.0000
##  CNCH13 - FBO1     2.7072 2.64 231   1.027  0.9700
##  CNCH13 - FCHI8    3.7370 2.64 231   1.417  0.8487
##  CNCH13 - FEAR5    7.0194 2.64 231   2.662  0.1399
##  CNCH13 - FGI4    -0.3478 2.64 231  -0.132  1.0000
##  CNCH13 - FMA7    10.1518 2.64 231   3.850  0.0038
##  CNCH13 - FSV1     2.9506 2.64 231   1.119  0.9522
##  FBO1 - FCHI8      1.0298 2.64 231   0.390  0.9999
##  FBO1 - FEAR5      4.3123 2.64 231   1.635  0.7285
##  FBO1 - FGI4      -3.0550 2.64 231  -1.158  0.9426
##  FBO1 - FMA7       7.4447 2.64 231   2.823  0.0944
##  FBO1 - FSV1       0.2434 2.64 231   0.092  1.0000
##  FCHI8 - FEAR5     3.2825 2.64 231   1.245  0.9175
##  FCHI8 - FGI4     -4.0847 2.64 231  -1.549  0.7799
##  FCHI8 - FMA7      6.4149 2.64 231   2.432  0.2308
##  FCHI8 - FSV1     -0.7864 2.64 231  -0.298  1.0000
##  FEAR5 - FGI4     -7.3672 2.64 231  -2.794  0.1016
##  FEAR5 - FMA7      3.1324 2.64 231   1.188  0.9348
##  FEAR5 - FSV1     -4.0689 2.64 231  -1.543  0.7833
##  FGI4 - FMA7      10.4996 2.64 231   3.981  0.0023
##  FGI4 - FSV1       3.2983 2.64 231   1.251  0.9155
##  FMA7 - FSV1      -7.2013 2.64 231  -2.731  0.1187
## 
## mun = ViG:
##  contrast        estimate   SE  df t.ratio p.value
##  CNCH12 - CNCH13  -6.2229 2.64 231  -2.360  0.2665
##  CNCH12 - FBO1     0.0454 2.64 231   0.017  1.0000
##  CNCH12 - FCHI8    0.3218 2.64 231   0.122  1.0000
##  CNCH12 - FEAR5  -10.6361 2.64 231  -4.033  0.0019
##  CNCH12 - FGI4    -2.4589 2.64 231  -0.932  0.9826
##  CNCH12 - FMA7    -2.7981 2.64 231  -1.061  0.9640
##  CNCH12 - FSV1    -3.1189 2.64 231  -1.183  0.9362
##  CNCH13 - FBO1     6.2684 2.64 231   2.377  0.2577
##  CNCH13 - FCHI8    6.5447 2.64 231   2.482  0.2085
##  CNCH13 - FEAR5   -4.4131 2.64 231  -1.673  0.7044
##  CNCH13 - FGI4     3.7641 2.64 231   1.427  0.8438
##  CNCH13 - FMA7     3.4248 2.64 231   1.299  0.8987
##  CNCH13 - FSV1     3.1040 2.64 231   1.177  0.9377
##  FBO1 - FCHI8      0.2763 2.64 231   0.105  1.0000
##  FBO1 - FEAR5    -10.6815 2.64 231  -4.050  0.0018
##  FBO1 - FGI4      -2.5043 2.64 231  -0.950  0.9807
##  FBO1 - FMA7      -2.8435 2.64 231  -1.078  0.9608
##  FBO1 - FSV1      -3.1644 2.64 231  -1.200  0.9313
##  FCHI8 - FEAR5   -10.9578 2.64 231  -4.155  0.0012
##  FCHI8 - FGI4     -2.7806 2.64 231  -1.054  0.9653
##  FCHI8 - FMA7     -3.1199 2.64 231  -1.183  0.9361
##  FCHI8 - FSV1     -3.4407 2.64 231  -1.305  0.8964
##  FEAR5 - FGI4      8.1772 2.64 231   3.101  0.0444
##  FEAR5 - FMA7      7.8380 2.64 231   2.972  0.0637
##  FEAR5 - FSV1      7.5171 2.64 231   2.850  0.0879
##  FGI4 - FMA7      -0.3392 2.64 231  -0.129  1.0000
##  FGI4 - FSV1      -0.6601 2.64 231  -0.250  1.0000
##  FMA7 - FSV1      -0.3208 2.64 231  -0.122  1.0000
## 
## mun = Yac:
##  contrast        estimate   SE  df t.ratio p.value
##  CNCH12 - CNCH13   3.3555 2.64 231   1.272  0.9082
##  CNCH12 - FBO1     2.2745 2.64 231   0.862  0.9890
##  CNCH12 - FCHI8   -0.0412 2.64 231  -0.016  1.0000
##  CNCH12 - FEAR5   -0.9467 2.64 231  -0.359  1.0000
##  CNCH12 - FGI4    -3.2028 2.64 231  -1.214  0.9270
##  CNCH12 - FMA7     3.8714 2.64 231   1.468  0.8236
##  CNCH12 - FSV1     2.4832 2.64 231   0.942  0.9816
##  CNCH13 - FBO1    -1.0810 2.64 231  -0.410  0.9999
##  CNCH13 - FCHI8   -3.3966 2.64 231  -1.288  0.9026
##  CNCH13 - FEAR5   -4.3021 2.64 231  -1.631  0.7309
##  CNCH13 - FGI4    -6.5583 2.64 231  -2.487  0.2063
##  CNCH13 - FMA7     0.5159 2.64 231   0.196  1.0000
##  CNCH13 - FSV1    -0.8722 2.64 231  -0.331  1.0000
##  FBO1 - FCHI8     -2.3157 2.64 231  -0.878  0.9877
##  FBO1 - FEAR5     -3.2212 2.64 231  -1.221  0.9249
##  FBO1 - FGI4      -5.4773 2.64 231  -2.077  0.4330
##  FBO1 - FMA7       1.5969 2.64 231   0.606  0.9988
##  FBO1 - FSV1       0.2087 2.64 231   0.079  1.0000
##  FCHI8 - FEAR5    -0.9055 2.64 231  -0.343  1.0000
##  FCHI8 - FGI4     -3.1616 2.64 231  -1.199  0.9316
##  FCHI8 - FMA7      3.9125 2.64 231   1.484  0.8155
##  FCHI8 - FSV1      2.5244 2.64 231   0.957  0.9798
##  FEAR5 - FGI4     -2.2561 2.64 231  -0.856  0.9895
##  FEAR5 - FMA7      4.8180 2.64 231   1.827  0.6024
##  FEAR5 - FSV1      3.4299 2.64 231   1.301  0.8979
##  FGI4 - FMA7       7.0742 2.64 231   2.682  0.1333
##  FGI4 - FSV1       5.6860 2.64 231   2.156  0.3825
##  FMA7 - FSV1      -1.3881 2.64 231  -0.526  0.9995
## 
## Note: contrasts are still on the ( scale. Consider using
##       regrid() if you want contrasts of back-transformed estimates. 
## P value adjustment: tukey method for varying family sizes
multcomp::cld(gm, Letters = LETTERS)
## mun = Chi:
##  gen    emmean   SE  df lower.CL upper.CL .group
##  FCHI8    2.02 1.86 231   -1.657     5.69  A    
##  CNCH12   3.09 1.86 231   -0.585     6.76  A    
##  FSV1     3.16 1.86 231   -0.516     6.83  A    
##  FGI4     3.18 1.86 231   -0.497     6.85  A    
##  FMA7     3.30 1.86 231   -0.374     6.97  A    
##  FBO1     4.35 1.86 231    0.672     8.02  A    
##  FEAR5    4.45 1.86 231    0.780     8.13  A    
##  CNCH13   4.70 1.86 231    1.027     8.38  A    
## 
## mun = Gig:
##  gen    emmean   SE  df lower.CL upper.CL .group
##  CNCH12   2.82 1.86 231   -0.858     6.49  A    
##  FSV1     3.80 1.86 231    0.127     7.48  A    
##  FGI4     4.72 1.86 231    1.046     8.39  A    
##  FMA7     4.81 1.86 231    1.138     8.49  A    
##  FBO1     5.60 1.86 231    1.924     9.27  A    
##  CNCH13   5.88 1.86 231    2.210     9.56  A    
##  FEAR5    6.39 1.86 231    2.715    10.06  A    
##  FCHI8    7.53 1.86 231    3.858    11.21  A    
## 
## mun = HtC:
##  gen    emmean   SE  df lower.CL upper.CL .group
##  FCHI8    5.14 1.86 231    1.464     8.81  A    
##  CNCH13   5.66 1.86 231    1.987     9.34  A    
##  FGI4     5.94 1.86 231    2.267     9.62  A    
##  CNCH12   5.94 1.86 231    2.269     9.62  A    
##  FMA7     6.00 1.86 231    2.326     9.67  A    
##  FBO1     6.19 1.86 231    2.518     9.87  A    
##  FEAR5    6.39 1.86 231    2.714    10.06  A    
##  FSV1     6.57 1.86 231    2.895    10.24  A    
## 
## mun = Jam:
##  gen    emmean   SE  df lower.CL upper.CL .group
##  FMA7     7.81 1.86 231    4.135    11.48  A    
##  FBO1     8.12 1.86 231    4.444    11.79  A    
##  FGI4     9.89 1.86 231    6.215    13.56  A    
##  CNCH12  10.59 1.86 231    6.914    14.26  A    
##  FEAR5   12.41 1.86 231    8.740    16.09  A    
##  CNCH13  12.90 1.86 231    9.230    16.58  A    
##  FCHI8  nonEst   NA  NA       NA       NA       
##  FSV1   nonEst   NA  NA       NA       NA       
## 
## mun = PtR:
##  gen    emmean   SE  df lower.CL upper.CL .group
##  FMA7     6.25 1.86 231    2.580     9.93  A    
##  FGI4     6.79 1.86 231    3.121    10.47  A    
##  FSV1     7.31 1.86 231    3.635    10.98  A    
##  CNCH13   8.21 1.86 231    4.540    11.89  A    
##  CNCH12   8.48 1.86 231    4.802    12.15  A    
##  FBO1     9.41 1.86 231    5.732    13.08  A    
##  FEAR5   10.82 1.86 231    7.149    14.50  A    
##  FCHI8  nonEst   NA  NA       NA       NA       
## 
## mun = RiN             :
##  gen    emmean   SE  df lower.CL upper.CL .group
##  FGI4     4.78 1.86 231    1.110     8.46  A    
##  FSV1     4.84 1.86 231    1.166     8.51  A    
##  FCHI8    5.30 1.86 231    1.629     8.98  A    
##  FEAR5    6.20 1.86 231    2.527     9.87  A    
##  CNCH13   7.19 1.86 231    3.516    10.86  A    
##  CNCH12   7.41 1.86 231    3.735    11.08  A    
##  FBO1     7.76 1.86 231    4.091    11.44  A    
##  FMA7     9.17 1.86 231    5.492    12.84  A    
## 
## mun = SnV:
##  gen    emmean   SE  df lower.CL upper.CL .group
##  FGI4     2.43 1.86 231   -1.242     6.11  A    
##  FSV1     2.46 1.86 231   -1.215     6.13  A    
##  FCHI8    2.65 1.86 231   -1.027     6.32  A    
##  FBO1     2.73 1.86 231   -0.942     6.41  A    
##  CNCH12   3.08 1.86 231   -0.595     6.75  A    
##  FMA7     3.90 1.86 231    0.222     7.57  A    
##  CNCH13   4.03 1.86 231    0.353     7.70  A    
##  FEAR5    5.55 1.86 231    1.876     9.22  A    
## 
## mun = Tam:
##  gen    emmean   SE  df lower.CL upper.CL .group
##  FMA7    13.53 1.86 231    9.858    17.21  A    
##  FEAR5   16.66 1.86 231   12.990    20.34  AB   
##  FCHI8   19.95 1.86 231   16.273    23.62  AB   
##  CNCH12  20.08 1.86 231   16.407    23.75  AB   
##  FSV1    20.73 1.86 231   17.059    24.41  AB   
##  FBO1    20.98 1.86 231   17.302    24.65  AB   
##  CNCH13  23.68 1.86 231   20.010    27.36   B   
##  FGI4    24.03 1.86 231   20.357    27.71   B   
## 
## mun = ViG:
##  gen    emmean   SE  df lower.CL upper.CL .group
##  FCHI8    5.78 1.86 231    2.102     9.45  A    
##  FBO1     6.05 1.86 231    2.379     9.73  A    
##  CNCH12   6.10 1.86 231    2.424     9.77  A    
##  FGI4     8.56 1.86 231    4.883    12.23  A    
##  FMA7     8.90 1.86 231    5.222    12.57  AB   
##  FSV1     9.22 1.86 231    5.543    12.89  AB   
##  CNCH13  12.32 1.86 231    8.647    16.00  AB   
##  FEAR5   16.73 1.86 231   13.060    20.41   B   
## 
## mun = Yac:
##  gen    emmean   SE  df lower.CL upper.CL .group
##  FMA7     5.51 1.86 231    1.835     9.18  A    
##  CNCH13   6.02 1.86 231    2.350     9.70  A    
##  FSV1     6.90 1.86 231    3.223    10.57  A    
##  FBO1     7.11 1.86 231    3.431    10.78  A    
##  CNCH12   9.38 1.86 231    5.706    13.05  A    
##  FCHI8    9.42 1.86 231    5.747    13.10  A    
##  FEAR5   10.33 1.86 231    6.653    14.00  A    
##  FGI4    12.58 1.86 231    8.909    16.26  A    
## 
## Results are given on the ( (not the response) scale. 
## Confidence level used: 0.95 
## Note: contrasts are still on the ( scale. Consider using
##       regrid() if you want contrasts of back-transformed estimates. 
## P value adjustment: tukey method for varying family sizes 
## 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.
# Modelo 1
modelo <- lmer(log(total_alt_co2) ~ gen +
                 (1|mun) +
                 (1|mun:gen),
               data = datos)
anova(modelo)
## Type III Analysis of Variance Table with Satterthwaite's method
##     Sum Sq Mean Sq NumDF  DenDF F value  Pr(>F)  
## gen 3.4467 0.49239     7 60.046  2.1305 0.05376 .
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
ranova(modelo)
## ANOVA-like table for random-effects: Single term deletions
## 
## Model:
## log(total_alt_co2) ~ gen + (1 | mun) + (1 | mun:gen)
##               npar  logLik    AIC    LRT Df Pr(>Chisq)    
## <none>          11 -246.08 514.15                         
## (1 | mun)       10 -282.23 584.47 72.311  1     <2e-16 ***
## (1 | mun:gen)   10 -247.32 514.65  2.495  1     0.1142    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# Modelo 2
modelo_blup <- lmer(total_alt_co2 ~ 1 +
                 (1|gen) +
                 (1|mun) +
                 (1|gen:mun),
               data = datos)
ranova(modelo_blup)
## boundary (singular) fit: see help('isSingular')
## ANOVA-like table for random-effects: Single term deletions
## 
## Model:
## total_alt_co2 ~ (1 | gen) + (1 | mun) + (1 | gen:mun)
##               npar  logLik    AIC    LRT Df Pr(>Chisq)    
## <none>           5 -868.94 1747.9                         
## (1 | gen)        4 -869.68 1747.3  1.481  1     0.2236    
## (1 | mun)        4 -918.36 1844.7 98.842  1     <2e-16 ***
## (1 | gen:mun)    4 -869.41 1746.8  0.951  1     0.3296    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## Extraer Blups

blups <- ranef(modelo_blup)

#Blups Gen

blups$gen
##        (Intercept)
## CNCH12  -0.1694569
## CNCH13   0.4764206
## FBO1    -0.1065272
## FCHI8   -0.2339906
## FEAR5    0.7287737
## FGI4     0.1120320
## FMA7    -0.5378970
## FSV1    -0.2693545
#Valor predicho  
fixef(modelo_blup)[1] + blups$gen
##        (Intercept)
## CNCH12    7.884810
## CNCH13    8.530687
## FBO1      7.947739
## FCHI8     7.820276
## FEAR5     8.783040
## FGI4      8.166298
## FMA7      7.516369
## FSV1      7.784912
#Blups Parcela

blups$mun
##                  (Intercept)
## Chi              -4.41892159
## Gig              -2.79369920
## HtC              -2.02702250
## Jam               2.08288392
## PtR               0.09230342
## RiN              -1.43784455
## SnV              -4.59246726
## Tam              11.62564759
## ViG               1.12575054
## Yac               0.34336964
fixef(modelo_blup)[1] + blups$mun
##                  (Intercept)
## Chi                 3.635345
## Gig                 5.260567
## HtC                 6.027244
## Jam                10.137150
## PtR                 8.146570
## RiN                 6.616422
## SnV                 3.461799
## Tam                19.679914
## ViG                 9.180017
## Yac                 8.397636
#Blups interacción

blups$`gen:mun`
##                         (Intercept)
## CNCH12:Chi              -0.06694718
## CNCH12:Gig              -0.40453386
## CNCH12:HtC               0.01525047
## CNCH12:Jam               0.11031706
## CNCH12:PtR               0.08875768
## CNCH12:RiN               0.17116812
## CNCH12:SnV              -0.03790032
## CNCH12:Tam               0.10141905
## CNCH12:ViG              -0.51786496
## CNCH12:Yac               0.20482212
## CNCH13:Chi               0.10487825
## CNCH13:Gig               0.02623882
## CNCH13:HtC              -0.14985371
## CNCH13:Jam               0.40729129
## CNCH13:PtR              -0.07267641
## CNCH13:RiN               0.01724079
## CNCH13:SnV               0.01577760
## CNCH13:Tam               0.62722609
## CNCH13:ViG               0.47385541
## CNCH13:Yac              -0.50670156
## FBO1:Chi                 0.14530635
## FBO1:Gig                 0.07892530
## FBO1:HtC                 0.04833654
## FBO1:Jam                -0.34017507
## FBO1:PtR                 0.24284593
## FBO1:RiN                 0.22316960
## FBO1:SnV                -0.11085945
## FBO1:Tam                 0.24949254
## FBO1:ViG                -0.53713433
## FBO1:Yac                -0.21082317
## FCHI8:Chi               -0.24616605
## FCHI8:Gig                0.44559858
## FCHI8:HtC               -0.11656607
## FCHI8:RiN               -0.19192088
## FCHI8:SnV               -0.10328525
## FCHI8:Tam                0.08904147
## FCHI8:ViG               -0.56360713
## FCHI8:Yac                0.22362169
## FEAR5:Chi                0.01595156
## FEAR5:Gig                0.07111673
## FEAR5:HtC               -0.06535562
## FEAR5:Jam                0.27527591
## FEAR5:PtR                0.34630500
## FEAR5:RiN               -0.20348355
## FEAR5:SnV                0.24179310
## FEAR5:Tam               -0.66585670
## FEAR5:ViG                1.21373287
## FEAR5:Yac                0.21343719
## FGI4:Chi                -0.10135450
## FGI4:Gig                -0.11600859
## FGI4:HtC                -0.03519500
## FGI4:Jam                -0.06395385
## FGI4:PtR                -0.26029386
## FGI4:RiN                -0.34580894
## FGI4:SnV                -0.20305570
## FGI4:Tam                 0.75386493
## FGI4:ViG                -0.13067887
## FGI4:Yac                 0.72429922
## FMA7:Chi                 0.03609846
## FMA7:Gig                 0.01590914
## FMA7:HtC                 0.09073559
## FMA7:Jam                -0.31839218
## FMA7:PtR                -0.24081988
## FMA7:RiN                 0.54910817
## FMA7:SnV                 0.17284611
## FMA7:Tam                -0.99762355
## FMA7:ViG                 0.04521536
## FMA7:Yac                -0.41807241
## FSV1:Chi                -0.03704516
## FSV1:Gig                -0.21162176
## FSV1:HtC                 0.14417172
## FSV1:PtR                -0.10100030
## FSV1:RiN                -0.26804599
## FSV1:SnV                -0.13045700
## FSV1:Tam                 0.23516918
## FSV1:ViG                 0.05451130
## FSV1:Yac                -0.21898349
fixef(modelo_blup)[1] + blups$`gen:mun`
##                         (Intercept)
## CNCH12:Chi                 7.987319
## CNCH12:Gig                 7.649733
## CNCH12:HtC                 8.069517
## CNCH12:Jam                 8.164583
## CNCH12:PtR                 8.143024
## CNCH12:RiN                 8.225435
## CNCH12:SnV                 8.016366
## CNCH12:Tam                 8.155685
## CNCH12:ViG                 7.536401
## CNCH12:Yac                 8.259089
## CNCH13:Chi                 8.159145
## CNCH13:Gig                 8.080505
## CNCH13:HtC                 7.904413
## CNCH13:Jam                 8.461558
## CNCH13:PtR                 7.981590
## CNCH13:RiN                 8.071507
## CNCH13:SnV                 8.070044
## CNCH13:Tam                 8.681493
## CNCH13:ViG                 8.528122
## CNCH13:Yac                 7.547565
## FBO1:Chi                   8.199573
## FBO1:Gig                   8.133192
## FBO1:HtC                   8.102603
## FBO1:Jam                   7.714091
## FBO1:PtR                   8.297112
## FBO1:RiN                   8.277436
## FBO1:SnV                   7.943407
## FBO1:Tam                   8.303759
## FBO1:ViG                   7.517132
## FBO1:Yac                   7.843443
## FCHI8:Chi                  7.808100
## FCHI8:Gig                  8.499865
## FCHI8:HtC                  7.937700
## FCHI8:RiN                  7.862346
## FCHI8:SnV                  7.950981
## FCHI8:Tam                  8.143308
## FCHI8:ViG                  7.490659
## FCHI8:Yac                  8.277888
## FEAR5:Chi                  8.070218
## FEAR5:Gig                  8.125383
## FEAR5:HtC                  7.988911
## FEAR5:Jam                  8.329542
## FEAR5:PtR                  8.400571
## FEAR5:RiN                  7.850783
## FEAR5:SnV                  8.296060
## FEAR5:Tam                  7.388410
## FEAR5:ViG                  9.267999
## FEAR5:Yac                  8.267704
## FGI4:Chi                   7.952912
## FGI4:Gig                   7.938258
## FGI4:HtC                   8.019071
## FGI4:Jam                   7.990313
## FGI4:PtR                   7.793973
## FGI4:RiN                   7.708457
## FGI4:SnV                   7.851211
## FGI4:Tam                   8.808131
## FGI4:ViG                   7.923588
## FGI4:Yac                   8.778566
## FMA7:Chi                   8.090365
## FMA7:Gig                   8.070176
## FMA7:HtC                   8.145002
## FMA7:Jam                   7.735874
## FMA7:PtR                   7.813447
## FMA7:RiN                   8.603375
## FMA7:SnV                   8.227113
## FMA7:Tam                   7.056643
## FMA7:ViG                   8.099482
## FMA7:Yac                   7.636194
## FSV1:Chi                   8.017221
## FSV1:Gig                   7.842645
## FSV1:HtC                   8.198438
## FSV1:PtR                   7.953266
## FSV1:RiN                   7.786220
## FSV1:SnV                   7.923809
## FSV1:Tam                   8.289436
## FSV1:ViG                   8.108778
## FSV1:Yac                   7.835283
#Tabla blup_gen

blup_gen <- ranef(modelo_blup)$gen %>%
  tibble::rownames_to_column("gen") %>%
  rename(BLUP = `(Intercept)`)
blup_gen
##      gen       BLUP
## 1 CNCH12 -0.1694569
## 2 CNCH13  0.4764206
## 3   FBO1 -0.1065272
## 4  FCHI8 -0.2339906
## 5  FEAR5  0.7287737
## 6   FGI4  0.1120320
## 7   FMA7 -0.5378970
## 8   FSV1 -0.2693545
#Tabla blup_mun
blup_mun <- ranef(modelo_blup)$mun %>%
  tibble::rownames_to_column("mun") %>%
  rename(BLUP = `(Intercept)`)
blup_mun
##                 mun        BLUP
## 1               Chi -4.41892159
## 2               Gig -2.79369920
## 3               HtC -2.02702250
## 4               Jam  2.08288392
## 5               PtR  0.09230342
## 6  RiN              -1.43784455
## 7               SnV -4.59246726
## 8               Tam 11.62564759
## 9               ViG  1.12575054
## 10              Yac  0.34336964
#Tabla blup_gen_mun
blup_gen_mun <- ranef(modelo_blup)$`gen:mun` %>%
  tibble::rownames_to_column("gen:mun") %>%
  rename(BLUP = `(Intercept)`)
blup_gen_mun
##                    gen:mun        BLUP
## 1               CNCH12:Chi -0.06694718
## 2               CNCH12:Gig -0.40453386
## 3               CNCH12:HtC  0.01525047
## 4               CNCH12:Jam  0.11031706
## 5               CNCH12:PtR  0.08875768
## 6  CNCH12:RiN               0.17116812
## 7               CNCH12:SnV -0.03790032
## 8               CNCH12:Tam  0.10141905
## 9               CNCH12:ViG -0.51786496
## 10              CNCH12:Yac  0.20482212
## 11              CNCH13:Chi  0.10487825
## 12              CNCH13:Gig  0.02623882
## 13              CNCH13:HtC -0.14985371
## 14              CNCH13:Jam  0.40729129
## 15              CNCH13:PtR -0.07267641
## 16 CNCH13:RiN               0.01724079
## 17              CNCH13:SnV  0.01577760
## 18              CNCH13:Tam  0.62722609
## 19              CNCH13:ViG  0.47385541
## 20              CNCH13:Yac -0.50670156
## 21                FBO1:Chi  0.14530635
## 22                FBO1:Gig  0.07892530
## 23                FBO1:HtC  0.04833654
## 24                FBO1:Jam -0.34017507
## 25                FBO1:PtR  0.24284593
## 26   FBO1:RiN               0.22316960
## 27                FBO1:SnV -0.11085945
## 28                FBO1:Tam  0.24949254
## 29                FBO1:ViG -0.53713433
## 30                FBO1:Yac -0.21082317
## 31               FCHI8:Chi -0.24616605
## 32               FCHI8:Gig  0.44559858
## 33               FCHI8:HtC -0.11656607
## 34  FCHI8:RiN              -0.19192088
## 35               FCHI8:SnV -0.10328525
## 36               FCHI8:Tam  0.08904147
## 37               FCHI8:ViG -0.56360713
## 38               FCHI8:Yac  0.22362169
## 39               FEAR5:Chi  0.01595156
## 40               FEAR5:Gig  0.07111673
## 41               FEAR5:HtC -0.06535562
## 42               FEAR5:Jam  0.27527591
## 43               FEAR5:PtR  0.34630500
## 44  FEAR5:RiN              -0.20348355
## 45               FEAR5:SnV  0.24179310
## 46               FEAR5:Tam -0.66585670
## 47               FEAR5:ViG  1.21373287
## 48               FEAR5:Yac  0.21343719
## 49                FGI4:Chi -0.10135450
## 50                FGI4:Gig -0.11600859
## 51                FGI4:HtC -0.03519500
## 52                FGI4:Jam -0.06395385
## 53                FGI4:PtR -0.26029386
## 54   FGI4:RiN              -0.34580894
## 55                FGI4:SnV -0.20305570
## 56                FGI4:Tam  0.75386493
## 57                FGI4:ViG -0.13067887
## 58                FGI4:Yac  0.72429922
## 59                FMA7:Chi  0.03609846
## 60                FMA7:Gig  0.01590914
## 61                FMA7:HtC  0.09073559
## 62                FMA7:Jam -0.31839218
## 63                FMA7:PtR -0.24081988
## 64   FMA7:RiN               0.54910817
## 65                FMA7:SnV  0.17284611
## 66                FMA7:Tam -0.99762355
## 67                FMA7:ViG  0.04521536
## 68                FMA7:Yac -0.41807241
## 69                FSV1:Chi -0.03704516
## 70                FSV1:Gig -0.21162176
## 71                FSV1:HtC  0.14417172
## 72                FSV1:PtR -0.10100030
## 73   FSV1:RiN              -0.26804599
## 74                FSV1:SnV -0.13045700
## 75                FSV1:Tam  0.23516918
## 76                FSV1:ViG  0.05451130
## 77                FSV1:Yac -0.21898349
#Predichos completos
datos$pred <- predict(modelo_blup)
datos$pred
##   [1]  7.909298  7.909298  7.909298  7.909298  7.441667  7.441667  7.441667
##   [8]  7.441667  9.339847  9.339847  9.339847  9.339847  8.387267  8.387267
##  [15]  8.387267  8.387267  9.233967  9.233967  9.233967  9.233967  8.433001
##  [22]  8.433001  8.433001  8.433001  8.367355  8.367355  8.367355  8.367355
##  [29]  8.080286  8.080286  8.080286  8.080286  7.776215  7.776215  7.776215
##  [36]  7.776215  7.367853  7.367853  7.367853  7.367853  9.221649  9.221649
##  [43]  9.221649  9.221649  7.998308  7.998308  7.998308  7.998308  8.065871
##  [50]  8.065871  8.065871  8.065871  8.550314  8.550314  8.550314  8.550314
##  [57]  8.282889  8.282889  8.282889  8.282889  3.061988  3.061988  3.061988
##  [64]  3.061988  3.096748  3.096748  3.096748  3.096748  4.432366  4.432366
##  [71]  4.432366  4.432366  3.124523  3.124523  3.124523  3.124523  3.370775
##  [78]  3.370775  3.370775  3.370775  3.254442  3.254442  3.254442  3.254442
##  [85]  3.953997  3.953997  3.953997  3.953997  3.244413  3.244413  3.244413
##  [92]  3.244413  3.328945  3.328945  3.328945  3.328945  3.133546  3.133546
##  [99]  3.133546  3.133546  4.380070  4.380070  4.380070  4.380070  3.155188
## [106]  3.155188  3.155188  3.155188  3.646022  3.646022  3.646022  3.646022
## [113]  3.398941  3.398941  3.398941  3.398941  4.216644  4.216644  4.216644
## [120]  4.216644  3.674124  3.674124  3.674124  3.674124  9.280861  9.280861
## [127]  9.280861  9.280861 11.141200 11.141200 11.141200 11.141200 10.185229
## [134] 10.185229 10.185229 10.185229 10.078010 10.078010 10.078010 10.078010
## [141] 11.020862 11.020862 11.020862 11.020862  9.690448  9.690448  9.690448
## [148]  9.690448  6.079021  6.079021  6.079021  6.079021  6.627633  6.627633
## [155]  6.627633  6.627633  7.141712  7.141712  7.141712  7.141712  6.190510
## [162]  6.190510  6.190510  6.190510  6.382645  6.382645  6.382645  6.382645
## [169]  6.618133  6.618133  6.618133  6.618133  7.110083  7.110083  7.110083
## [176]  7.110083  6.733064  6.733064  6.733064  6.733064  8.965174  8.965174
## [183]  8.965174  8.965174  8.687335  8.687335  8.687335  8.687335 11.122524
## [190] 11.122524 11.122524 11.122524  8.382419  8.382419  8.382419  8.382419
## [197]  9.161370  9.161370  9.161370  9.161370  8.492695  8.492695  8.492695
## [204]  8.492695 10.130293 10.130293 10.130293 10.130293  8.536355  8.536355
## [211]  8.536355  8.536355  4.779591  4.779591  4.779591  4.779591  4.738579
## [218]  4.738579  4.738579  4.738579  6.060458  6.060458  6.060458  6.060458
## [225]  5.472175  5.472175  5.472175  5.472175  5.256591  5.256591  5.256591
## [232]  5.256591  4.686576  4.686576  4.686576  4.686576  5.763227  5.763227
## [239]  5.763227  5.763227  5.232965  5.232965  5.232965  5.232965  5.902061
## [246]  5.902061  5.902061  5.902061  5.580083  5.580083  5.580083  5.580083
## [253]  6.690662  6.690662  6.690662  6.690662  5.676687  5.676687  5.676687
## [260]  5.676687  6.104081  6.104081  6.104081  6.104081  5.873037  5.873037
## [267]  5.873037  5.873037  6.353811  6.353811  6.353811  6.353811  5.969053
## [274]  5.969053  5.969053  5.969053 19.645729 19.645729 19.645729 19.645729
## [281] 18.144393 18.144393 18.144393 18.144393 19.742831 19.742831 19.742831
## [288] 19.742831 19.534965 19.534965 19.534965 19.534965 20.545811 20.545811
## [295] 20.545811 20.545811 19.611876 19.611876 19.611876 19.611876 20.783561
## [302] 20.783561 20.783561 20.783561 19.822879 19.822879 19.822879 19.822879
#Visualizar Blups gen
ggplot(blup_gen, aes(x=reorder(gen, BLUP), y=BLUP)) +
  geom_point(size=3) +
  geom_hline(yintercept=0, linetype="dashed") +
  labs(x = "Genotipo") +
  coord_flip()

#Visualizar Blups mun
ggplot(blup_mun, aes(x=reorder(mun, BLUP), y=BLUP)) +
  geom_point(size=3) +
  geom_hline(yintercept=0, linetype="dashed") +
  labs(x = "Municipio") +
  coord_flip()

#Visualizar Blups gen:mun
ggplot(blup_gen_mun, aes(x=reorder(`gen:mun`, BLUP), y=BLUP)) +
  geom_point(size=3) +
  geom_hline(yintercept=0, linetype="dashed") +
  labs(x = "Gen * Mun") +
  coord_flip()

##Componentes de varianza-heredabilidades
vc <- as.data.frame(VarCorr(modelo_blup))
vc
##        grp        var1 var2       vcov     sdcor
## 1  gen:mun (Intercept) <NA>  0.7520752 0.8672227
## 2      mun (Intercept) <NA> 22.2628612 4.7183537
## 3      gen (Intercept) <NA>  0.3798505 0.6163201
## 4 Residual        <NA> <NA> 13.9092197 3.7295066
VarCorr(modelo_blup)
##  Groups   Name        Std.Dev.
##  gen:mun  (Intercept) 0.86722 
##  mun      (Intercept) 4.71835 
##  gen      (Intercept) 0.61632 
##  Residual             3.72951
varG  <- vc$vcov[vc$grp=="gen"]
varGE <- vc$vcov[vc$grp=="gen:mun"]
varE  <- vc$vcov[vc$grp=="Residual"]

e <- 10
r <- 4
# Heredabilidad genotipos y plasticidad
#H2 genotipos
H2g <- varG / (varG + varGE/e + varE/(r*e))
H2g
## [1] 0.4731639
#H2 plasticidad
H2ge <- varGE / (varG + varGE/e + varE/(r*e))
H2ge
## [1] 0.9368285
###ranking genotipos predichos

blup_gen <- ranef(modelo_blup)$gen
blup_gen
##        (Intercept)
## CNCH12  -0.1694569
## CNCH13   0.4764206
## FBO1    -0.1065272
## FCHI8   -0.2339906
## FEAR5    0.7287737
## FGI4     0.1120320
## FMA7    -0.5378970
## FSV1    -0.2693545
##Predicho de carbono por genotipo

media <- fixef(modelo_blup)[1]
blup_gen$pred <- media + blup_gen[,1]


# Ranking predichos (publicar)
blup_gen[order(-blup_gen$pred),]
##        (Intercept)     pred
## FEAR5    0.7287737 8.783040
## CNCH13   0.4764206 8.530687
## FGI4     0.1120320 8.166298
## FBO1    -0.1065272 7.947739
## CNCH12  -0.1694569 7.884810
## FCHI8   -0.2339906 7.820276
## FSV1    -0.2693545 7.784912
## FMA7    -0.5378970 7.516369
# Visualización ranking predichos
blup_gen$gen <- rownames(blup_gen)

ggplot(blup_gen, aes(x=reorder(gen,pred), y=pred))+
  geom_point(size=3)+
  coord_flip()+
  ylab("Carbono predicho (BLUP)")+
  xlab("Genotipo")

### Análisis G×E (estabilidad)
## matriz genotipo × parcela.
mat <- datos %>%
  group_by(gen,mun) %>%
  summarise(total_alt_co2=mean(total_alt_co2)) %>%
  pivot_wider(names_from=mun,
              values_from=total_alt_co2)
## `summarise()` has grouped output by 'gen'. You can override using the `.groups`
## argument.
##Convertir a matriz
mat2 <- as.matrix(mat[,-1])
rownames(mat2) <- mat$gen

  
### Estabilidad con Metan
modelo_metan <- gge(datos, mun, gen, total_alt_co2)
## Warning: Data imputation used to fill the GxE matrix
modelo_metan
## $total_alt_co2
## $coordgen
##            [,1]       [,2]       [,3]      [,4]       [,5]       [,6]
## [1,]  2.1067993 -0.4316305 -0.8991511 -2.869853 -5.3937292  4.5395296
## [2,] -1.8258440  3.0237550  6.1435565  0.925107  0.8593636  2.1883804
## [3,]  2.3649214 -1.0746937  1.9935227  3.497847 -3.7023381 -5.0810449
## [4,]  2.4741465 -0.2102677 -2.7112722  5.254716  3.2164134  3.3644028
## [5,] -6.8541186  0.9542592 -3.1009723  1.088511 -1.5743752 -0.6457962
## [6,]  2.1375879  4.0995615 -3.2472484 -2.600966  1.3785677 -2.9191886
## [7,] -1.0635388 -6.6535967  0.2381104 -1.727789  2.0017584 -0.5176899
## [8,]  0.6600463  0.2926128  1.5834543 -3.567573  3.2143394 -0.9285931
##            [,7]      [,8]
## [1,]  0.3965949 -3.012507
## [2,] -2.6311488 -3.012507
## [3,]  1.0223277 -3.012507
## [4,]  0.8562701 -3.012507
## [5,]  1.3929182 -3.012507
## [6,] -3.7972261 -3.012507
## [7,] -3.2875390 -3.012507
## [8,]  6.0478029 -3.012507
## 
## $coordenv
##             [,1]        [,2]        [,3]         [,4]        [,5]        [,6]
##  [1,] -1.4046269  0.47277276  1.28610684  0.105591744 -0.95074434 -0.91251731
##  [2,] -1.0853811  0.41312523 -0.42473955  3.441728893  1.36942674 -0.16025363
##  [3,] -0.4213545 -0.08534389  0.06754809 -0.641005782 -0.27445834 -0.64374200
##  [4,] -2.7855938  3.16970526  0.76307512  0.002887331 -0.38759110  2.07036281
##  [5,] -2.0268953  0.95710150 -0.22415785  1.641285344 -2.38217786 -0.25825735
##  [6,] -0.5707601 -2.92975648  1.60705159  0.189851356 -1.72991164  0.06445634
##  [7,] -2.7251879 -0.30293292 -0.00551218  0.301159567 -0.52012715  0.33234247
##  [8,]  4.0450485  7.82340163  2.52598069  0.088594497 -0.09847215 -0.42944444
##  [9,] -9.4860923  2.51836719  0.42848361 -0.806552936  0.79242786 -0.66015906
## [10,]  0.4325271  3.67988711 -5.09940174 -0.304624835 -0.83757110 -0.15240267
##              [,7]          [,8]
##  [1,] -0.30397731 -2.662008e-16
##  [2,] -0.47521054  1.582132e-16
##  [3,]  0.53193629  6.862466e-16
##  [4,]  0.08838995  1.267581e-16
##  [5,]  1.27866955 -4.196268e-17
##  [6,] -1.63052038  2.158538e-16
##  [7,] -0.44080956 -1.337652e-16
##  [8,] -0.34788407  2.890675e-17
##  [9,] -0.18230864  1.813083e-18
## [10,] -0.77403515  3.222832e-17
## 
## $eigenvalues
## [1] 1.137912e+01 1.005630e+01 6.133701e+00 3.979859e+00 3.644429e+00
## [6] 2.526645e+00 2.418738e+00 8.068586e-16
## 
## $totalvar
## [1] 309.59
## 
## $varexpl
## [1] 41.82 32.67 12.15  5.12  4.29  2.06  1.89  0.00
## 
## $labelgen
## [1] "CNCH12" "CNCH13" "FBO1"   "FCHI8"  "FEAR5"  "FGI4"   "FMA7"   "FSV1"  
## 
## $labelenv
##  [1] "Chi"              "Gig"              "HtC"              "Jam"             
##  [5] "PtR"              "RiN............." "SnV"              "Tam"             
##  [9] "ViG"              "Yac"             
## 
## $labelaxes
## [1] "PC1" "PC2" "PC3" "PC4" "PC5" "PC6" "PC7" "PC8"
## 
## $ge_mat
##               Chi        Gig         HtC        Jam         PtR
## CNCH12 -0.4410066 -2.3780575 -0.03555883  0.4216642  0.35108775
## CNCH13  1.1711508  0.6903191 -0.31816336  2.7376100  0.08912237
## FBO1    0.8155550  0.4036597  0.21343421 -2.0487997  1.28055029
## FCHI8  -1.5133979  2.3382251 -0.84137777 -0.4480429 -0.40136661
## FEAR5   0.9234145  1.1950482  0.40937431  2.2475597  2.69766497
## FGI4   -0.3530111 -0.4740140 -0.03775573 -0.2768791 -1.33035428
## FMA7   -0.2299578 -0.3820886  0.02050027 -2.3576709 -1.87076914
## FSV1   -0.3727468 -1.3930920  0.58954690 -0.2754412 -0.81593536
##        RiN.............        SnV          Tam         ViG        Yac
## CNCH12        0.8272707 -0.2735371  0.124812277 -3.10846229  0.9742296
## CNCH13        0.6075204  0.6742043  3.727625379  3.11446727 -2.3812271
## FBO1          1.1826367 -0.6209013  1.020450102 -3.15389605 -1.3002691
## FCHI8        -1.2791352 -0.7057704 -0.009328154 -3.43023228  1.0154174
## FEAR5        -0.3813949  2.1975812 -3.291819364  7.52760523  1.9209080
## FGI4         -1.7985196 -0.9208182  4.075404659 -0.64958850  4.1770569
## FMA7          2.5842193  0.5431793 -6.424218592 -0.31035630 -2.8971286
## FSV1         -1.7425973 -0.8939377  0.777073694  0.01046292 -1.5089870
## 
## $centering
## [1] "environment"
## 
## $scaling
## [1] "none"
## 
## $svp
## [1] "environment"
## 
## $d
## [1] 0.1173619
## 
## $grand_mean
## [1] 8.049886
## 
## $mean_gen
##   CNCH12   CNCH13     FBO1    FCHI8    FEAR5     FGI4     FMA7     FSV1 
## 7.696131 9.061149 7.829128 7.522386 9.594481 8.291039 6.917457 7.487321 
## 
## $mean_env
##              Chi              Gig              HtC              Jam 
##         3.530409         5.194226         5.979109        10.166410 
##              PtR RiN.............              SnV              Tam 
##         8.125164         6.582278         3.352743        19.955986 
##              ViG              Yac 
##         9.206750         8.405790 
## 
## $scale_val
##              Chi              Gig              HtC              Jam 
##        0.9016426        1.4881178        0.4428740        1.8060730 
##              PtR RiN.............              SnV              Tam 
##        1.4709024        1.5667639        1.0812983        3.4696974 
##              ViG              Yac 
##        3.7466029        2.4245537 
## 
## attr(,"class")
## [1] "gge"
## 
## attr(,"class")
## [1] "gge"
#Grafica metan
plot(modelo_metan)
## Warning: The `size` argument of `element_rect()` is deprecated as of ggplot2 3.4.0.
## ℹ Please use the `linewidth` argument instead.
## ℹ The deprecated feature was likely used in the metan package.
##   Please report the issue at <https://github.com/nepem-ufsc/metan/issues>.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## ℹ The deprecated feature was likely used in the metan package.
##   Please report the issue at <https://github.com/nepem-ufsc/metan/issues>.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.

### Selección ideotípica
##Integración de variables
##Blup gen
blup_gen <- ranef(modelo_blup)$gen
media <- fixef(modelo_blup)[1]

blup_gen$BLUP_C <- media + blup_gen[,1]
blup_gen$gen <- rownames(blup_gen)
blup_gen <- blup_gen[,c("gen","BLUP_C")]
blup_gen
##           gen   BLUP_C
## CNCH12 CNCH12 7.884810
## CNCH13 CNCH13 8.530687
## FBO1     FBO1 7.947739
## FCHI8   FCHI8 7.820276
## FEAR5   FEAR5 8.783040
## FGI4     FGI4 8.166298
## FMA7     FMA7 7.516369
## FSV1     FSV1 7.784912
##Plasticidad usando Fisher environments (joint regression)
#índice (creando valores de x para definir env = promedio de tasas en c/parcela)
indice_env <- datos %>%
  group_by(mun) %>%
  summarise(env = mean(total_alt_co2))

datos <- left_join(datos, indice_env, by="mun")

#visualización Normas de reacción joint regression env
ggplot(datos, aes(x = env, y = total_alt_co2,
                   color = gen)) +
  geom_smooth(method = "lm", se = FALSE) +
  labs(x = "Ambiente (local)", 
       y = expression(t.CO[2][eq]/ha.año)) +
  theme_bw()
## `geom_smooth()` using formula = 'y ~ x'

#visualización Normas de reacción clima local
ggplot(datos, aes(x = E, y = total_alt_co2,
                  color = gen)) +
  geom_smooth(method = "lm", se = FALSE) +
  labs(x = "Ambiente (Estrés)", 
       y = expression(t.CO[2][eq]/ha.año)) +
  theme_bw()
## `geom_smooth()` using formula = 'y ~ x'

## plasticidad joint
# modelo factores fijos
mod_plas_lm <- lm(total_alt_co2 ~ gen*env, 
                data=datos)
emtrends(mod_plas_lm, "gen", var = "env")
##  gen    env.trend    SE  df lower.CL upper.CL
##  CNCH12     1.039 0.128 292    0.787    1.291
##  CNCH13     1.205 0.128 292    0.953    1.457
##  FBO1       0.997 0.128 292    0.744    1.249
##  FCHI8      1.011 0.130 292    0.755    1.267
##  FEAR5      0.790 0.128 292    0.538    1.042
##  FGI4       1.283 0.128 292    1.031    1.535
##  FMA7       0.573 0.128 292    0.321    0.825
##  FSV1       1.093 0.130 292    0.837    1.348
## 
## Confidence level used: 0.95
# modelo blup  factores aleatorios
modelo_plasticidad <- lmer(total_alt_co2 ~ env +
                             (env|gen) +
                             (1|mun),
                           data=datos)
## boundary (singular) fit: see help('isSingular')
pend <- ranef(modelo_plasticidad)$gen
pend$gen <- rownames(pend)

plasticidad <- pend[,c("gen","env")]
colnames(plasticidad)[2] <- "Pendiente"

#plasticidad Estrés
# modelo factores fijos
mod_plas2_lm <- lm(total_alt_co2 ~ gen*E, 
                  data=datos)
emtrends(mod_plas2_lm, "gen", var = "E")
##  gen    E.trend   SE  df lower.CL upper.CL
##  CNCH12    26.3 15.6 292    -4.43     57.1
##  CNCH13    48.3 15.6 292    17.52     79.1
##  FBO1      38.9 15.6 292     8.11     69.7
##  FCHI8     39.0 16.5 292     6.44     71.5
##  FEAR5     17.2 15.6 292   -13.62     47.9
##  FGI4      35.3 15.6 292     4.52     66.1
##  FMA7      27.9 15.6 292    -2.88     58.7
##  FSV1      46.0 15.8 292    14.80     77.2
## 
## Confidence level used: 0.95
#Modelo factores aleatorios

modelo_plasticidad2 <- lmer(total_alt_co2 ~ E +
                             (E|gen) +
                             (1|mun),
                           data=datos)
## boundary (singular) fit: see help('isSingular')
## Warning: Model failed to converge with 1 negative eigenvalue: -1.3e+00
pend2 <- ranef(modelo_plasticidad2)$gen
pend2$gen <- rownames(pend)

plasticidad2 <- pend2[,c("gen","E")]
colnames(plasticidad2)[2] <- "Pendiente2"

##Tabla selección MGIDI 1

tabla_sel <- blup_gen %>%
  left_join(plasticidad, by="gen")

mgidi_mod <- mgidi(tabla_sel,
                   ideotype = c("h, h"))
## 
## -------------------------------------------------------------------------------
## Principal Component Analysis
## -------------------------------------------------------------------------------
## # A tibble: 2 × 4
##   PC    Eigenvalues `Variance (%)` `Cum. variance (%)`
##   <chr>       <dbl>          <dbl>               <dbl>
## 1 PC1          1.38           68.8                68.8
## 2 PC2          0.62           31.2               100  
## -------------------------------------------------------------------------------
## Factor Analysis - factorial loadings after rotation-
## -------------------------------------------------------------------------------
## # A tibble: 2 × 4
##   VAR         FA1 Communality Uniquenesses
##   <chr>     <dbl>       <dbl>        <dbl>
## 1 BLUP_C     0.83        0.69         0.31
## 2 Pendiente  0.83        0.69         0.31
## -------------------------------------------------------------------------------
## Comunalit Mean: 0.6881142 
## -------------------------------------------------------------------------------
## Selection differential 
## -------------------------------------------------------------------------------
## # A tibble: 2 × 8
##   VAR       Factor       Xo    Xs    SD  SDperc sense     goal
##   <chr>     <chr>     <dbl> <dbl> <dbl>   <dbl> <chr>    <dbl>
## 1 BLUP_C    FA1    8.05e+ 0 8.53  0.476 5.92e 0 increase   100
## 2 Pendiente FA1    1.18e-14 0.159 0.159 1.34e15 increase   100
## ------------------------------------------------------------------------------
## Selected genotypes
## -------------------------------------------------------------------------------
## CNCH13
## -------------------------------------------------------------------------------
#ranking MGIDI 1
mgidi_mod$MGIDI
## # A tibble: 8 × 2
##   Genotype MGIDI
##   <chr>    <dbl>
## 1 CNCH13   0.493
## 2 FGI4     0.888
## 3 FEAR5    1.14 
## 4 CNCH12   1.97 
## 5 FBO1     1.97 
## 6 FSV1     1.98 
## 7 FCHI8    2.14 
## 8 FMA7     3.76
#Gráfico Selección 1
plot(mgidi_mod)

##Tabla selección MGIDI 2 estrés

tabla_sel2 <- blup_gen %>%
  left_join(plasticidad, by="gen") %>%
  left_join(plasticidad2, by="gen")

mgidi_mod2<-mgidi(tabla_sel2,
                  ideotype = c("h, h, l"))
## 
## -------------------------------------------------------------------------------
## Principal Component Analysis
## -------------------------------------------------------------------------------
## # A tibble: 3 × 4
##   PC    Eigenvalues `Variance (%)` `Cum. variance (%)`
##   <chr>       <dbl>          <dbl>               <dbl>
## 1 PC1           2.2          73.3                 73.3
## 2 PC2           0.8          26.7                 99.9
## 3 PC3           0             0.06               100  
## -------------------------------------------------------------------------------
## Factor Analysis - factorial loadings after rotation-
## -------------------------------------------------------------------------------
## # A tibble: 3 × 4
##   VAR          FA1 Communality Uniquenesses
##   <chr>      <dbl>       <dbl>        <dbl>
## 1 BLUP_C      0.98        0.95         0.05
## 2 Pendiente   0.56        0.32         0.68
## 3 Pendiente2  0.96        0.93         0.07
## -------------------------------------------------------------------------------
## Comunalit Mean: 0.7327794 
## -------------------------------------------------------------------------------
## Selection differential 
## -------------------------------------------------------------------------------
## # A tibble: 3 × 8
##   VAR        Factor        Xo     Xs     SD   SDperc sense     goal
##   <chr>      <chr>      <dbl>  <dbl>  <dbl>    <dbl> <chr>    <dbl>
## 1 BLUP_C     FA1     8.05e+ 0  8.78   0.729  9.05e 0 increase   100
## 2 Pendiente  FA1     1.18e-14 -0.103 -0.103 -8.72e14 increase     0
## 3 Pendiente2 FA1    -1.56e-15 -2.12  -2.12  -1.36e17 decrease   100
## ------------------------------------------------------------------------------
## Selected genotypes
## -------------------------------------------------------------------------------
## FEAR5
## -------------------------------------------------------------------------------
#ranking MGIDI 1
mgidi_mod2$MGIDI
## # A tibble: 8 × 2
##   Genotype MGIDI
##   <chr>    <dbl>
## 1 FEAR5    0.485
## 2 CNCH13   0.699
## 3 FGI4     1.36 
## 4 FBO1     2.15 
## 5 CNCH12   2.20 
## 6 FCHI8    2.40 
## 7 FSV1     2.42 
## 8 FMA7     3.51
#Gráfico Selección 1
plot(mgidi_mod2)