setwd("G:/Mi unidad/Agrosavia/FeCa/Fenoma/Análisis/MorfoA")
datos<-read.table("morfo.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(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(GR) ~ gen * mun,
              data = datos)
anova(modelo)
## Analysis of Variance Table
## 
## Response: log(GR)
##            Df Sum Sq  Mean Sq F value  Pr(>F)    
## gen         7 2.0912 0.298737 21.4269 < 2e-16 ***
## mun         9 2.4208 0.268983 19.2928 < 2e-16 ***
## gen:mun    60 2.4055 0.040092  2.8756 1.1e-10 ***
## Residuals 539 7.5148 0.013942                    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#Modelo bruto
modelo <- lm ((GR) ~ gen * mun,
              data = datos)
anova(modelo)
## Analysis of Variance Table
## 
## Response: (GR)
##            Df  Sum Sq   Mean Sq F value    Pr(>F)    
## gen         7 0.09616 0.0137369 14.5827 < 2.2e-16 ***
## mun         9 0.10382 0.0115359 12.2462 < 2.2e-16 ***
## gen:mun    60 0.13611 0.0022686  2.4082 1.153e-07 ***
## Residuals 539 0.50774 0.0009420                      
## ---
## 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  0.226 0.00343 539    0.220    0.233
##  CNCH13  0.201 0.00343 539    0.194    0.208
##  FBO1    0.226 0.00343 539    0.219    0.233
##  FCHI8  nonEst      NA  NA       NA       NA
##  FEAR5   0.208 0.00343 539    0.201    0.214
##  FGI4    0.213 0.00343 539    0.206    0.220
##  FMA7    0.239 0.00343 539    0.232    0.246
##  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  0.02525 0.00485 539   5.203  <.0001
##  CNCH12 - FBO1    0.00040 0.00485 539   0.082  1.0000
##  CNCH12 - FCHI8    nonEst      NA  NA      NA      NA
##  CNCH12 - FEAR5   0.01864 0.00485 539   3.841  0.0019
##  CNCH12 - FGI4    0.01330 0.00485 539   2.741  0.0691
##  CNCH12 - FMA7   -0.01264 0.00485 539  -2.604  0.0980
##  CNCH12 - FSV1     nonEst      NA  NA      NA      NA
##  CNCH13 - FBO1   -0.02485 0.00485 539  -5.121  <.0001
##  CNCH13 - FCHI8    nonEst      NA  NA      NA      NA
##  CNCH13 - FEAR5  -0.00661 0.00485 539  -1.363  0.7494
##  CNCH13 - FGI4   -0.01195 0.00485 539  -2.462  0.1373
##  CNCH13 - FMA7   -0.03789 0.00485 539  -7.807  <.0001
##  CNCH13 - FSV1     nonEst      NA  NA      NA      NA
##  FBO1 - FCHI8      nonEst      NA  NA      NA      NA
##  FBO1 - FEAR5     0.01824 0.00485 539   3.758  0.0026
##  FBO1 - FGI4      0.01290 0.00485 539   2.658  0.0856
##  FBO1 - FMA7     -0.01304 0.00485 539  -2.687  0.0796
##  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    -0.00534 0.00485 539  -1.100  0.8814
##  FEAR5 - FMA7    -0.03127 0.00485 539  -6.445  <.0001
##  FEAR5 - FSV1      nonEst      NA  NA      NA      NA
##  FGI4 - FMA7     -0.02594 0.00485 539  -5.345  <.0001
##  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
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  0.230 0.00384 539    0.222    0.237
##  Gig  0.210 0.00384 539    0.203    0.218
##  HtC  0.216 0.00384 539    0.208    0.223
##  Jam nonEst      NA  NA       NA       NA
##  PtR nonEst      NA  NA       NA       NA
##  RiN  0.202 0.00384 539    0.195    0.210
##  SnV  0.219 0.00384 539    0.212    0.227
##  Tam  0.199 0.00384 539    0.192    0.207
##  ViG  0.208 0.00384 539    0.200    0.215
##  Yac  0.239 0.00384 539    0.232    0.247
## 
## 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  0.01941 0.00543 539   3.577  0.0090
##  Chi - HtC  0.01386 0.00543 539   2.554  0.1753
##  Chi - Jam   nonEst      NA  NA      NA      NA
##  Chi - PtR   nonEst      NA  NA      NA      NA
##  Chi - RiN  0.02753 0.00543 539   5.074  <.0001
##  Chi - SnV  0.01064 0.00543 539   1.961  0.5093
##  Chi - Tam  0.03048 0.00543 539   5.619  <.0001
##  Chi - ViG  0.02177 0.00543 539   4.012  0.0018
##  Chi - Yac -0.00972 0.00543 539  -1.791  0.6263
##  Gig - HtC -0.00555 0.00543 539  -1.022  0.9710
##  Gig - Jam   nonEst      NA  NA      NA      NA
##  Gig - PtR   nonEst      NA  NA      NA      NA
##  Gig - RiN  0.00813 0.00543 539   1.498  0.8087
##  Gig - SnV -0.00877 0.00543 539  -1.616  0.7408
##  Gig - Tam  0.01108 0.00543 539   2.042  0.4546
##  Gig - ViG  0.00236 0.00543 539   0.435  0.9999
##  Gig - Yac -0.02913 0.00543 539  -5.368  <.0001
##  HtC - Jam   nonEst      NA  NA      NA      NA
##  HtC - PtR   nonEst      NA  NA      NA      NA
##  HtC - RiN  0.01367 0.00543 539   2.520  0.1892
##  HtC - SnV -0.00322 0.00543 539  -0.593  0.9990
##  HtC - Tam  0.01663 0.00543 539   3.064  0.0470
##  HtC - ViG  0.00791 0.00543 539   1.457  0.8297
##  HtC - Yac -0.02358 0.00543 539  -4.346  0.0004
##  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 -0.01689 0.00543 539  -3.113  0.0407
##  RiN - Tam  0.00295 0.00543 539   0.544  0.9994
##  RiN - ViG -0.00577 0.00543 539  -1.063  0.9641
##  RiN - Yac -0.03725 0.00543 539  -6.866  <.0001
##  SnV - Tam  0.01984 0.00543 539   3.657  0.0068
##  SnV - ViG  0.01112 0.00543 539   2.050  0.4488
##  SnV - Yac -0.02036 0.00543 539  -3.752  0.0048
##  Tam - ViG -0.00872 0.00543 539  -1.607  0.7461
##  Tam - Yac -0.04020 0.00543 539  -7.410  <.0001
##  ViG - Yac -0.03148 0.00543 539  -5.803  <.0001
## 
## 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
#Interacción
gm<-emmeans(modelo, pairwise ~ gen|mun)
gm
## $emmeans
## mun = Chi:
##  gen    emmean     SE  df lower.CL upper.CL
##  CNCH12  0.230 0.0109 539    0.209    0.251
##  CNCH13  0.224 0.0109 539    0.202    0.245
##  FBO1    0.243 0.0109 539    0.222    0.265
##  FCHI8   0.230 0.0109 539    0.209    0.251
##  FEAR5   0.206 0.0109 539    0.185    0.228
##  FGI4    0.228 0.0109 539    0.207    0.249
##  FMA7    0.263 0.0109 539    0.241    0.284
##  FSV1    0.214 0.0109 539    0.193    0.235
## 
## mun = Gig:
##  gen    emmean     SE  df lower.CL upper.CL
##  CNCH12  0.216 0.0109 539    0.195    0.238
##  CNCH13  0.202 0.0109 539    0.180    0.223
##  FBO1    0.202 0.0109 539    0.181    0.223
##  FCHI8   0.201 0.0109 539    0.180    0.222
##  FEAR5   0.199 0.0109 539    0.178    0.221
##  FGI4    0.203 0.0109 539    0.182    0.225
##  FMA7    0.239 0.0109 539    0.217    0.260
##  FSV1    0.220 0.0109 539    0.199    0.241
## 
## mun = HtC:
##  gen    emmean     SE  df lower.CL upper.CL
##  CNCH12  0.226 0.0109 539    0.204    0.247
##  CNCH13  0.210 0.0109 539    0.189    0.231
##  FBO1    0.235 0.0109 539    0.214    0.257
##  FCHI8   0.206 0.0109 539    0.185    0.228
##  FEAR5   0.202 0.0109 539    0.181    0.223
##  FGI4    0.222 0.0109 539    0.200    0.243
##  FMA7    0.231 0.0109 539    0.209    0.252
##  FSV1    0.196 0.0109 539    0.174    0.217
## 
## mun = Jam:
##  gen    emmean     SE  df lower.CL upper.CL
##  CNCH12  0.268 0.0109 539    0.246    0.289
##  CNCH13  0.235 0.0109 539    0.213    0.256
##  FBO1    0.248 0.0109 539    0.227    0.270
##  FCHI8  nonEst     NA  NA       NA       NA
##  FEAR5   0.233 0.0109 539    0.212    0.254
##  FGI4    0.223 0.0109 539    0.202    0.244
##  FMA7    0.219 0.0109 539    0.198    0.240
##  FSV1   nonEst     NA  NA       NA       NA
## 
## mun = PtR:
##  gen    emmean     SE  df lower.CL upper.CL
##  CNCH12  0.228 0.0109 539    0.207    0.250
##  CNCH13  0.208 0.0109 539    0.187    0.230
##  FBO1    0.214 0.0109 539    0.192    0.235
##  FCHI8  nonEst     NA  NA       NA       NA
##  FEAR5   0.193 0.0109 539    0.172    0.214
##  FGI4    0.197 0.0109 539    0.175    0.218
##  FMA7    0.249 0.0109 539    0.227    0.270
##  FSV1    0.186 0.0109 539    0.165    0.208
## 
## mun = RiN:
##  gen    emmean     SE  df lower.CL upper.CL
##  CNCH12  0.214 0.0109 539    0.192    0.235
##  CNCH13  0.189 0.0109 539    0.168    0.211
##  FBO1    0.217 0.0109 539    0.196    0.239
##  FCHI8   0.171 0.0109 539    0.150    0.193
##  FEAR5   0.198 0.0109 539    0.176    0.219
##  FGI4    0.228 0.0109 539    0.206    0.249
##  FMA7    0.207 0.0109 539    0.186    0.229
##  FSV1    0.193 0.0109 539    0.172    0.214
## 
## mun = SnV:
##  gen    emmean     SE  df lower.CL upper.CL
##  CNCH12  0.220 0.0109 539    0.198    0.241
##  CNCH13  0.204 0.0109 539    0.183    0.226
##  FBO1    0.240 0.0109 539    0.219    0.261
##  FCHI8   0.215 0.0109 539    0.193    0.236
##  FEAR5   0.214 0.0109 539    0.193    0.235
##  FGI4    0.207 0.0109 539    0.186    0.229
##  FMA7    0.258 0.0109 539    0.236    0.279
##  FSV1    0.195 0.0109 539    0.173    0.216
## 
## mun = Tam:
##  gen    emmean     SE  df lower.CL upper.CL
##  CNCH12  0.208 0.0109 539    0.187    0.229
##  CNCH13  0.156 0.0109 539    0.135    0.178
##  FBO1    0.207 0.0109 539    0.186    0.228
##  FCHI8   0.270 0.0109 539    0.248    0.291
##  FEAR5   0.191 0.0109 539    0.169    0.212
##  FGI4    0.169 0.0109 539    0.148    0.190
##  FMA7    0.219 0.0109 539    0.197    0.240
##  FSV1    0.174 0.0109 539    0.153    0.196
## 
## mun = ViG:
##  gen    emmean     SE  df lower.CL upper.CL
##  CNCH12  0.215 0.0109 539    0.193    0.236
##  CNCH13  0.189 0.0109 539    0.168    0.210
##  FBO1    0.218 0.0109 539    0.197    0.239
##  FCHI8   0.213 0.0109 539    0.192    0.235
##  FEAR5   0.192 0.0109 539    0.170    0.213
##  FGI4    0.210 0.0109 539    0.189    0.232
##  FMA7    0.228 0.0109 539    0.207    0.250
##  FSV1    0.198 0.0109 539    0.177    0.220
## 
## mun = Yac:
##  gen    emmean     SE  df lower.CL upper.CL
##  CNCH12  0.239 0.0109 539    0.218    0.260
##  CNCH13  0.193 0.0109 539    0.172    0.215
##  FBO1    0.234 0.0109 539    0.212    0.255
##  FCHI8   0.235 0.0109 539    0.214    0.257
##  FEAR5   0.249 0.0109 539    0.228    0.271
##  FGI4    0.243 0.0109 539    0.222    0.265
##  FMA7    0.278 0.0109 539    0.257    0.299
##  FSV1    0.244 0.0109 539    0.222    0.265
## 
## 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  0.006375 0.0153 539   0.415  0.9999
##  CNCH12 - FBO1   -0.013125 0.0153 539  -0.855  0.9897
##  CNCH12 - FCHI8   0.000125 0.0153 539   0.008  1.0000
##  CNCH12 - FEAR5   0.023875 0.0153 539   1.556  0.7764
##  CNCH12 - FGI4    0.002250 0.0153 539   0.147  1.0000
##  CNCH12 - FMA7   -0.032375 0.0153 539  -2.110  0.4099
##  CNCH12 - FSV1    0.016125 0.0153 539   1.051  0.9662
##  CNCH13 - FBO1   -0.019500 0.0153 539  -1.271  0.9093
##  CNCH13 - FCHI8  -0.006250 0.0153 539  -0.407  0.9999
##  CNCH13 - FEAR5   0.017500 0.0153 539   1.140  0.9476
##  CNCH13 - FGI4   -0.004125 0.0153 539  -0.269  1.0000
##  CNCH13 - FMA7   -0.038750 0.0153 539  -2.525  0.1871
##  CNCH13 - FSV1    0.009750 0.0153 539   0.635  0.9984
##  FBO1 - FCHI8     0.013250 0.0153 539   0.863  0.9891
##  FBO1 - FEAR5     0.037000 0.0153 539   2.411  0.2380
##  FBO1 - FGI4      0.015375 0.0153 539   1.002  0.9741
##  FBO1 - FMA7     -0.019250 0.0153 539  -1.254  0.9149
##  FBO1 - FSV1      0.029250 0.0153 539   1.906  0.5473
##  FCHI8 - FEAR5    0.023750 0.0153 539   1.548  0.7810
##  FCHI8 - FGI4     0.002125 0.0153 539   0.138  1.0000
##  FCHI8 - FMA7    -0.032500 0.0153 539  -2.118  0.4047
##  FCHI8 - FSV1     0.016000 0.0153 539   1.043  0.9677
##  FEAR5 - FGI4    -0.021625 0.0153 539  -1.409  0.8530
##  FEAR5 - FMA7    -0.056250 0.0153 539  -3.665  0.0066
##  FEAR5 - FSV1    -0.007750 0.0153 539  -0.505  0.9996
##  FGI4 - FMA7     -0.034625 0.0153 539  -2.256  0.3201
##  FGI4 - FSV1      0.013875 0.0153 539   0.904  0.9856
##  FMA7 - FSV1      0.048500 0.0153 539   3.160  0.0353
## 
## mun = Gig:
##  contrast         estimate     SE  df t.ratio p.value
##  CNCH12 - CNCH13  0.014500 0.0153 539   0.945  0.9814
##  CNCH12 - FBO1    0.014125 0.0153 539   0.920  0.9841
##  CNCH12 - FCHI8   0.015250 0.0153 539   0.994  0.9753
##  CNCH12 - FEAR5   0.016875 0.0153 539   1.100  0.9568
##  CNCH12 - FGI4    0.012875 0.0153 539   0.839  0.9908
##  CNCH12 - FMA7   -0.022500 0.0153 539  -1.466  0.8251
##  CNCH12 - FSV1   -0.003625 0.0153 539  -0.236  1.0000
##  CNCH13 - FBO1   -0.000375 0.0153 539  -0.024  1.0000
##  CNCH13 - FCHI8   0.000750 0.0153 539   0.049  1.0000
##  CNCH13 - FEAR5   0.002375 0.0153 539   0.155  1.0000
##  CNCH13 - FGI4   -0.001625 0.0153 539  -0.106  1.0000
##  CNCH13 - FMA7   -0.037000 0.0153 539  -2.411  0.2380
##  CNCH13 - FSV1   -0.018125 0.0153 539  -1.181  0.9371
##  FBO1 - FCHI8     0.001125 0.0153 539   0.073  1.0000
##  FBO1 - FEAR5     0.002750 0.0153 539   0.179  1.0000
##  FBO1 - FGI4     -0.001250 0.0153 539  -0.081  1.0000
##  FBO1 - FMA7     -0.036625 0.0153 539  -2.387  0.2500
##  FBO1 - FSV1     -0.017750 0.0153 539  -1.157  0.9436
##  FCHI8 - FEAR5    0.001625 0.0153 539   0.106  1.0000
##  FCHI8 - FGI4    -0.002375 0.0153 539  -0.155  1.0000
##  FCHI8 - FMA7    -0.037750 0.0153 539  -2.460  0.2152
##  FCHI8 - FSV1    -0.018875 0.0153 539  -1.230  0.9228
##  FEAR5 - FGI4    -0.004000 0.0153 539  -0.261  1.0000
##  FEAR5 - FMA7    -0.039375 0.0153 539  -2.566  0.1709
##  FEAR5 - FSV1    -0.020500 0.0153 539  -1.336  0.8848
##  FGI4 - FMA7     -0.035375 0.0153 539  -2.305  0.2926
##  FGI4 - FSV1     -0.016500 0.0153 539  -1.075  0.9617
##  FMA7 - FSV1      0.018875 0.0153 539   1.230  0.9228
## 
## mun = HtC:
##  contrast         estimate     SE  df t.ratio p.value
##  CNCH12 - CNCH13  0.015625 0.0153 539   1.018  0.9716
##  CNCH12 - FBO1   -0.009750 0.0153 539  -0.635  0.9984
##  CNCH12 - FCHI8   0.019375 0.0153 539   1.263  0.9121
##  CNCH12 - FEAR5   0.023500 0.0153 539   1.531  0.7902
##  CNCH12 - FGI4    0.004125 0.0153 539   0.269  1.0000
##  CNCH12 - FMA7   -0.004875 0.0153 539  -0.318  1.0000
##  CNCH12 - FSV1    0.030125 0.0153 539   1.963  0.5080
##  CNCH13 - FBO1   -0.025375 0.0153 539  -1.654  0.7172
##  CNCH13 - FCHI8   0.003750 0.0153 539   0.244  1.0000
##  CNCH13 - FEAR5   0.007875 0.0153 539   0.513  0.9996
##  CNCH13 - FGI4   -0.011500 0.0153 539  -0.749  0.9954
##  CNCH13 - FMA7   -0.020500 0.0153 539  -1.336  0.8848
##  CNCH13 - FSV1    0.014500 0.0153 539   0.945  0.9814
##  FBO1 - FCHI8     0.029125 0.0153 539   1.898  0.5530
##  FBO1 - FEAR5     0.033250 0.0153 539   2.167  0.3738
##  FBO1 - FGI4      0.013875 0.0153 539   0.904  0.9856
##  FBO1 - FMA7      0.004875 0.0153 539   0.318  1.0000
##  FBO1 - FSV1      0.039875 0.0153 539   2.598  0.1587
##  FCHI8 - FEAR5    0.004125 0.0153 539   0.269  1.0000
##  FCHI8 - FGI4    -0.015250 0.0153 539  -0.994  0.9753
##  FCHI8 - FMA7    -0.024250 0.0153 539  -1.580  0.7621
##  FCHI8 - FSV1     0.010750 0.0153 539   0.701  0.9970
##  FEAR5 - FGI4    -0.019375 0.0153 539  -1.263  0.9121
##  FEAR5 - FMA7    -0.028375 0.0153 539  -1.849  0.5867
##  FEAR5 - FSV1     0.006625 0.0153 539   0.432  0.9999
##  FGI4 - FMA7     -0.009000 0.0153 539  -0.586  0.9990
##  FGI4 - FSV1      0.026000 0.0153 539   1.694  0.6911
##  FMA7 - FSV1      0.035000 0.0153 539   2.281  0.3062
## 
## mun = Jam:
##  contrast         estimate     SE  df t.ratio p.value
##  CNCH12 - CNCH13  0.033000 0.0153 539   2.150  0.2632
##  CNCH12 - FBO1    0.019125 0.0153 539   1.246  0.8137
##  CNCH12 - FCHI8     nonEst     NA  NA      NA      NA
##  CNCH12 - FEAR5   0.034750 0.0153 539   2.264  0.2106
##  CNCH12 - FGI4    0.044625 0.0153 539   2.908  0.0437
##  CNCH12 - FMA7    0.048625 0.0153 539   3.169  0.0200
##  CNCH12 - FSV1      nonEst     NA  NA      NA      NA
##  CNCH13 - FBO1   -0.013875 0.0153 539  -0.904  0.9454
##  CNCH13 - FCHI8     nonEst     NA  NA      NA      NA
##  CNCH13 - FEAR5   0.001750 0.0153 539   0.114  1.0000
##  CNCH13 - FGI4    0.011625 0.0153 539   0.758  0.9743
##  CNCH13 - FMA7    0.015625 0.0153 539   1.018  0.9118
##  CNCH13 - FSV1      nonEst     NA  NA      NA      NA
##  FBO1 - FCHI8       nonEst     NA  NA      NA      NA
##  FBO1 - FEAR5     0.015625 0.0153 539   1.018  0.9118
##  FBO1 - FGI4      0.025500 0.0153 539   1.662  0.5579
##  FBO1 - FMA7      0.029500 0.0153 539   1.922  0.3895
##  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     0.009875 0.0153 539   0.643  0.9876
##  FEAR5 - FMA7     0.013875 0.0153 539   0.904  0.9454
##  FEAR5 - FSV1       nonEst     NA  NA      NA      NA
##  FGI4 - FMA7      0.004000 0.0153 539   0.261  0.9998
##  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.020125 0.0153 539   1.311  0.8466
##  CNCH12 - FBO1    0.014625 0.0153 539   0.953  0.9635
##  CNCH12 - FCHI8     nonEst     NA  NA      NA      NA
##  CNCH12 - FEAR5   0.035250 0.0153 539   2.297  0.2473
##  CNCH12 - FGI4    0.031625 0.0153 539   2.061  0.3778
##  CNCH12 - FMA7   -0.020375 0.0153 539  -1.328  0.8388
##  CNCH12 - FSV1    0.041875 0.0153 539   2.729  0.0932
##  CNCH13 - FBO1   -0.005500 0.0153 539  -0.358  0.9998
##  CNCH13 - FCHI8     nonEst     NA  NA      NA      NA
##  CNCH13 - FEAR5   0.015125 0.0153 539   0.986  0.9570
##  CNCH13 - FGI4    0.011500 0.0153 539   0.749  0.9893
##  CNCH13 - FMA7   -0.040500 0.0153 539  -2.639  0.1165
##  CNCH13 - FSV1    0.021750 0.0153 539   1.417  0.7924
##  FBO1 - FCHI8       nonEst     NA  NA      NA      NA
##  FBO1 - FEAR5     0.020625 0.0153 539   1.344  0.8308
##  FBO1 - FGI4      0.017000 0.0153 539   1.108  0.9257
##  FBO1 - FMA7     -0.035000 0.0153 539  -2.281  0.2553
##  FBO1 - FSV1      0.027250 0.0153 539   1.776  0.5651
##  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    -0.003625 0.0153 539  -0.236  1.0000
##  FEAR5 - FMA7    -0.055625 0.0153 539  -3.625  0.0058
##  FEAR5 - FSV1     0.006625 0.0153 539   0.432  0.9995
##  FGI4 - FMA7     -0.052000 0.0153 539  -3.388  0.0132
##  FGI4 - FSV1      0.010250 0.0153 539   0.668  0.9942
##  FMA7 - FSV1      0.062250 0.0153 539   4.056  0.0011
## 
## mun = RiN:
##  contrast         estimate     SE  df t.ratio p.value
##  CNCH12 - CNCH13  0.024375 0.0153 539   1.588  0.7573
##  CNCH12 - FBO1   -0.003750 0.0153 539  -0.244  1.0000
##  CNCH12 - FCHI8   0.042500 0.0153 539   2.769  0.1050
##  CNCH12 - FEAR5   0.016250 0.0153 539   1.059  0.9648
##  CNCH12 - FGI4   -0.013750 0.0153 539  -0.896  0.9864
##  CNCH12 - FMA7    0.006250 0.0153 539   0.407  0.9999
##  CNCH12 - FSV1    0.020625 0.0153 539   1.344  0.8815
##  CNCH13 - FBO1   -0.028125 0.0153 539  -1.833  0.5979
##  CNCH13 - FCHI8   0.018125 0.0153 539   1.181  0.9371
##  CNCH13 - FEAR5  -0.008125 0.0153 539  -0.529  0.9995
##  CNCH13 - FGI4   -0.038125 0.0153 539  -2.484  0.2043
##  CNCH13 - FMA7   -0.018125 0.0153 539  -1.181  0.9371
##  CNCH13 - FSV1   -0.003750 0.0153 539  -0.244  1.0000
##  FBO1 - FCHI8     0.046250 0.0153 539   3.014  0.0544
##  FBO1 - FEAR5     0.020000 0.0153 539   1.303  0.8975
##  FBO1 - FGI4     -0.010000 0.0153 539  -0.652  0.9981
##  FBO1 - FMA7      0.010000 0.0153 539   0.652  0.9981
##  FBO1 - FSV1      0.024375 0.0153 539   1.588  0.7573
##  FCHI8 - FEAR5   -0.026250 0.0153 539  -1.711  0.6804
##  FCHI8 - FGI4    -0.056250 0.0153 539  -3.665  0.0066
##  FCHI8 - FMA7    -0.036250 0.0153 539  -2.362  0.2623
##  FCHI8 - FSV1    -0.021875 0.0153 539  -1.425  0.8453
##  FEAR5 - FGI4    -0.030000 0.0153 539  -1.955  0.5136
##  FEAR5 - FMA7    -0.010000 0.0153 539  -0.652  0.9981
##  FEAR5 - FSV1     0.004375 0.0153 539   0.285  1.0000
##  FGI4 - FMA7      0.020000 0.0153 539   1.303  0.8975
##  FGI4 - FSV1      0.034375 0.0153 539   2.240  0.3295
##  FMA7 - FSV1      0.014375 0.0153 539   0.937  0.9823
## 
## mun = SnV:
##  contrast         estimate     SE  df t.ratio p.value
##  CNCH12 - CNCH13  0.015375 0.0153 539   1.002  0.9741
##  CNCH12 - FBO1   -0.020375 0.0153 539  -1.328  0.8881
##  CNCH12 - FCHI8   0.005125 0.0153 539   0.334  1.0000
##  CNCH12 - FEAR5   0.005750 0.0153 539   0.375  1.0000
##  CNCH12 - FGI4    0.012250 0.0153 539   0.798  0.9932
##  CNCH12 - FMA7   -0.037875 0.0153 539  -2.468  0.2115
##  CNCH12 - FSV1    0.025125 0.0153 539   1.637  0.7274
##  CNCH13 - FBO1   -0.035750 0.0153 539  -2.330  0.2794
##  CNCH13 - FCHI8  -0.010250 0.0153 539  -0.668  0.9978
##  CNCH13 - FEAR5  -0.009625 0.0153 539  -0.627  0.9985
##  CNCH13 - FGI4   -0.003125 0.0153 539  -0.204  1.0000
##  CNCH13 - FMA7   -0.053250 0.0153 539  -3.470  0.0130
##  CNCH13 - FSV1    0.009750 0.0153 539   0.635  0.9984
##  FBO1 - FCHI8     0.025500 0.0153 539   1.662  0.7120
##  FBO1 - FEAR5     0.026125 0.0153 539   1.702  0.6858
##  FBO1 - FGI4      0.032625 0.0153 539   2.126  0.3995
##  FBO1 - FMA7     -0.017500 0.0153 539  -1.140  0.9476
##  FBO1 - FSV1      0.045500 0.0153 539   2.965  0.0624
##  FCHI8 - FEAR5    0.000625 0.0153 539   0.041  1.0000
##  FCHI8 - FGI4     0.007125 0.0153 539   0.464  0.9998
##  FCHI8 - FMA7    -0.043000 0.0153 539  -2.802  0.0966
##  FCHI8 - FSV1     0.020000 0.0153 539   1.303  0.8975
##  FEAR5 - FGI4     0.006500 0.0153 539   0.424  0.9999
##  FEAR5 - FMA7    -0.043625 0.0153 539  -2.843  0.0869
##  FEAR5 - FSV1     0.019375 0.0153 539   1.263  0.9121
##  FGI4 - FMA7     -0.050125 0.0153 539  -3.266  0.0254
##  FGI4 - FSV1      0.012875 0.0153 539   0.839  0.9908
##  FMA7 - FSV1      0.063000 0.0153 539   4.105  0.0012
## 
## mun = Tam:
##  contrast         estimate     SE  df t.ratio p.value
##  CNCH12 - CNCH13  0.051500 0.0153 539   3.356  0.0191
##  CNCH12 - FBO1    0.000875 0.0153 539   0.057  1.0000
##  CNCH12 - FCHI8  -0.061500 0.0153 539  -4.008  0.0018
##  CNCH12 - FEAR5   0.017250 0.0153 539   1.124  0.9514
##  CNCH12 - FGI4    0.038875 0.0153 539   2.533  0.1838
##  CNCH12 - FMA7   -0.010625 0.0153 539  -0.692  0.9972
##  CNCH12 - FSV1    0.033750 0.0153 539   2.199  0.3538
##  CNCH13 - FBO1   -0.050625 0.0153 539  -3.299  0.0229
##  CNCH13 - FCHI8  -0.113000 0.0153 539  -7.363  <.0001
##  CNCH13 - FEAR5  -0.034250 0.0153 539  -2.232  0.3343
##  CNCH13 - FGI4   -0.012625 0.0153 539  -0.823  0.9918
##  CNCH13 - FMA7   -0.062125 0.0153 539  -4.048  0.0015
##  CNCH13 - FSV1   -0.017750 0.0153 539  -1.157  0.9436
##  FBO1 - FCHI8    -0.062375 0.0153 539  -4.065  0.0014
##  FBO1 - FEAR5     0.016375 0.0153 539   1.067  0.9633
##  FBO1 - FGI4      0.038000 0.0153 539   2.476  0.2079
##  FBO1 - FMA7     -0.011500 0.0153 539  -0.749  0.9954
##  FBO1 - FSV1      0.032875 0.0153 539   2.142  0.3891
##  FCHI8 - FEAR5    0.078750 0.0153 539   5.132  <.0001
##  FCHI8 - FGI4     0.100375 0.0153 539   6.541  <.0001
##  FCHI8 - FMA7     0.050875 0.0153 539   3.315  0.0217
##  FCHI8 - FSV1     0.095250 0.0153 539   6.207  <.0001
##  FEAR5 - FGI4     0.021625 0.0153 539   1.409  0.8530
##  FEAR5 - FMA7    -0.027875 0.0153 539  -1.816  0.6091
##  FEAR5 - FSV1     0.016500 0.0153 539   1.075  0.9617
##  FGI4 - FMA7     -0.049500 0.0153 539  -3.226  0.0289
##  FGI4 - FSV1     -0.005125 0.0153 539  -0.334  1.0000
##  FMA7 - FSV1      0.044375 0.0153 539   2.892  0.0763
## 
## mun = ViG:
##  contrast         estimate     SE  df t.ratio p.value
##  CNCH12 - CNCH13  0.025750 0.0153 539   1.678  0.7016
##  CNCH12 - FBO1   -0.003375 0.0153 539  -0.220  1.0000
##  CNCH12 - FCHI8   0.001250 0.0153 539   0.081  1.0000
##  CNCH12 - FEAR5   0.023000 0.0153 539   1.499  0.8081
##  CNCH12 - FGI4    0.004250 0.0153 539   0.277  1.0000
##  CNCH12 - FMA7   -0.013750 0.0153 539  -0.896  0.9864
##  CNCH12 - FSV1    0.016250 0.0153 539   1.059  0.9648
##  CNCH13 - FBO1   -0.029125 0.0153 539  -1.898  0.5530
##  CNCH13 - FCHI8  -0.024500 0.0153 539  -1.597  0.7524
##  CNCH13 - FEAR5  -0.002750 0.0153 539  -0.179  1.0000
##  CNCH13 - FGI4   -0.021500 0.0153 539  -1.401  0.8567
##  CNCH13 - FMA7   -0.039500 0.0153 539  -2.574  0.1678
##  CNCH13 - FSV1   -0.009500 0.0153 539  -0.619  0.9986
##  FBO1 - FCHI8     0.004625 0.0153 539   0.301  1.0000
##  FBO1 - FEAR5     0.026375 0.0153 539   1.719  0.6751
##  FBO1 - FGI4      0.007625 0.0153 539   0.497  0.9997
##  FBO1 - FMA7     -0.010375 0.0153 539  -0.676  0.9976
##  FBO1 - FSV1      0.019625 0.0153 539   1.279  0.9065
##  FCHI8 - FEAR5    0.021750 0.0153 539   1.417  0.8492
##  FCHI8 - FGI4     0.003000 0.0153 539   0.195  1.0000
##  FCHI8 - FMA7    -0.015000 0.0153 539  -0.977  0.9775
##  FCHI8 - FSV1     0.015000 0.0153 539   0.977  0.9775
##  FEAR5 - FGI4    -0.018750 0.0153 539  -1.222  0.9253
##  FEAR5 - FMA7    -0.036750 0.0153 539  -2.395  0.2460
##  FEAR5 - FSV1    -0.006750 0.0153 539  -0.440  0.9999
##  FGI4 - FMA7     -0.018000 0.0153 539  -1.173  0.9393
##  FGI4 - FSV1      0.012000 0.0153 539   0.782  0.9940
##  FMA7 - FSV1      0.030000 0.0153 539   1.955  0.5136
## 
## mun = Yac:
##  contrast         estimate     SE  df t.ratio p.value
##  CNCH12 - CNCH13  0.045875 0.0153 539   2.989  0.0583
##  CNCH12 - FBO1    0.005625 0.0153 539   0.367  1.0000
##  CNCH12 - FCHI8   0.003625 0.0153 539   0.236  1.0000
##  CNCH12 - FEAR5  -0.010125 0.0153 539  -0.660  0.9979
##  CNCH12 - FGI4   -0.004125 0.0153 539  -0.269  1.0000
##  CNCH12 - FMA7   -0.038875 0.0153 539  -2.533  0.1838
##  CNCH12 - FSV1   -0.004500 0.0153 539  -0.293  1.0000
##  CNCH13 - FBO1   -0.040250 0.0153 539  -2.623  0.1500
##  CNCH13 - FCHI8  -0.042250 0.0153 539  -2.753  0.1094
##  CNCH13 - FEAR5  -0.056000 0.0153 539  -3.649  0.0070
##  CNCH13 - FGI4   -0.050000 0.0153 539  -3.258  0.0261
##  CNCH13 - FMA7   -0.084750 0.0153 539  -5.523  <.0001
##  CNCH13 - FSV1   -0.050375 0.0153 539  -3.283  0.0241
##  FBO1 - FCHI8    -0.002000 0.0153 539  -0.130  1.0000
##  FBO1 - FEAR5    -0.015750 0.0153 539  -1.026  0.9704
##  FBO1 - FGI4     -0.009750 0.0153 539  -0.635  0.9984
##  FBO1 - FMA7     -0.044500 0.0153 539  -2.900  0.0746
##  FBO1 - FSV1     -0.010125 0.0153 539  -0.660  0.9979
##  FCHI8 - FEAR5   -0.013750 0.0153 539  -0.896  0.9864
##  FCHI8 - FGI4    -0.007750 0.0153 539  -0.505  0.9996
##  FCHI8 - FMA7    -0.042500 0.0153 539  -2.769  0.1050
##  FCHI8 - FSV1    -0.008125 0.0153 539  -0.529  0.9995
##  FEAR5 - FGI4     0.006000 0.0153 539   0.391  0.9999
##  FEAR5 - FMA7    -0.028750 0.0153 539  -1.873  0.5698
##  FEAR5 - FSV1     0.005625 0.0153 539   0.367  1.0000
##  FGI4 - FMA7     -0.034750 0.0153 539  -2.264  0.3154
##  FGI4 - FSV1     -0.000375 0.0153 539  -0.024  1.0000
##  FMA7 - FSV1      0.034375 0.0153 539   2.240  0.3295
## 
## 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
# Modelo 1
modelo <- lmer(log(GR) ~ 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 0.69935 0.099907     7 60.084  7.1658 3.178e-06 ***
## ---
## 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(GR) ~ gen + (1 | mun) + (1 | mun:gen)
##               npar logLik     AIC    LRT Df Pr(>Chisq)    
## <none>          11 373.84 -725.69                         
## (1 | mun)       10 363.22 -706.44 21.241  1  4.050e-06 ***
## (1 | mun:gen)   10 353.96 -687.93 39.760  1  2.872e-10 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# Modelo 2
modelo_blup <- lmer(GR ~ 1 +
                      (1|gen) +
                      (1|mun) +
                      (1|gen:mun),
                    data = datos)
ranova(modelo_blup)
## ANOVA-like table for random-effects: Single term deletions
## 
## Model:
## GR ~ (1 | gen) + (1 | mun) + (1 | gen:mun)
##               npar logLik     AIC    LRT Df Pr(>Chisq)    
## <none>           5 1219.8 -2429.5                         
## (1 | gen)        4 1212.1 -2416.2 15.396  1  8.715e-05 ***
## (1 | mun)        4 1212.3 -2416.6 14.997  1  0.0001077 ***
## (1 | gen:mun)    4 1206.6 -2405.3 26.274  1  2.963e-07 ***
## ---
## 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.007773787
## CNCH13 -0.013251623
## FBO1    0.007440711
## FCHI8   0.001543602
## FEAR5  -0.007745464
## FGI4   -0.003300983
## FMA7    0.018296901
## FSV1   -0.010756932
#Valor predicho  
fixef(modelo_blup)[1] + blups$gen
##        (Intercept)
## CNCH12   0.2247630
## CNCH13   0.2037376
## FBO1     0.2244300
## FCHI8    0.2185328
## FEAR5    0.2092438
## FGI4     0.2136883
## FMA7     0.2352861
## FSV1     0.2062323
#Blups Parcela

blups$mun
##       (Intercept)
## Chi  0.0103495174
## Gig -0.0054284164
## HtC -0.0009186205
## Jam  0.0146021326
## PtR -0.0047378460
## RiN -0.0120343146
## SnV  0.0016983315
## Tam -0.0144353045
## ViG -0.0073466676
## Yac  0.0182511880
fixef(modelo_blup)[1] + blups$mun
##     (Intercept)
## Chi   0.2273388
## Gig   0.2115608
## HtC   0.2160706
## Jam   0.2315914
## PtR   0.2122514
## RiN   0.2049549
## SnV   0.2186876
## Tam   0.2025539
## ViG   0.2096426
## Yac   0.2352404
#Blups interacción

blups$`gen:mun`
##              (Intercept)
## CNCH12:Chi -0.0029142266
## CNCH12:Gig -0.0018023414
## CNCH12:HtC  0.0010404000
## CNCH12:Jam  0.0165122382
## CNCH12:PtR  0.0048788020
## CNCH12:RiN  0.0005967371
## CNCH12:SnV -0.0039214521
## CNCH12:Tam -0.0013600913
## CNCH12:ViG -0.0016309946
## CNCH12:Yac -0.0022724722
## CNCH13:Chi  0.0056460161
## CNCH13:Gig  0.0020104594
## CNCH13:HtC  0.0041958627
## CNCH13:Jam  0.0095154791
## CNCH13:PtR  0.0054049123
## CNCH13:RiN -0.0013604299
## CNCH13:SnV -0.0006199143
## CNCH13:Tam -0.0191664104
## CNCH13:ViG -0.0043915748
## CNCH13:Yac -0.0167921008
## FBO1:Chi    0.0049493343
## FBO1:Gig   -0.0098609702
## FBO1:HtC    0.0069319466
## FBO1:Jam    0.0055321068
## FBO1:PtR   -0.0034719770
## FBO1:RiN    0.0029824805
## FBO1:SnV    0.0081782877
## FBO1:Tam   -0.0016767379
## FBO1:ViG    0.0005356361
## FBO1:Yac   -0.0053645463
## FCHI8:Chi   0.0006530362
## FCHI8:Gig  -0.0070726242
## FCHI8:HtC  -0.0066401226
## FCHI8:RiN  -0.0205957354
## FCHI8:SnV  -0.0032756920
## FCHI8:Tam   0.0382146924
## FCHI8:ViG   0.0012789302
## FCHI8:Yac  -0.0007502612
## FEAR5:Chi  -0.0077964953
## FEAR5:Gig  -0.0025945063
## FEAR5:HtC  -0.0036227560
## FEAR5:Jam   0.0052757012
## FEAR5:PtR  -0.0066498853
## FEAR5:RiN   0.0001697601
## FEAR5:SnV   0.0017867265
## FEAR5:Tam  -0.0023713689
## FEAR5:ViG  -0.0060020003
## FEAR5:Yac   0.0127114775
## FGI4:Chi    0.0022420916
## FGI4:Gig   -0.0028542164
## FGI4:HtC    0.0051011547
## FGI4:Jam   -0.0030911789
## FGI4:PtR   -0.0071287081
## FGI4:RiN    0.0151018640
## FGI4:SnV   -0.0046081393
## FGI4:Tam   -0.0176037803
## FGI4:ViG    0.0023567226
## FGI4:Yac    0.0066087620
## FMA7:Chi    0.0098538422
## FMA7:Gig    0.0051957596
## FMA7:HtC   -0.0022597960
## FMA7:Jam   -0.0180480366
## FMA7:PtR    0.0106352644
## FMA7:RiN   -0.0092038023
## FMA7:SnV    0.0120602697
## FMA7:Tam   -0.0013005591
## FMA7:ViG    0.0002544768
## FMA7:Yac    0.0142935502
## FSV1:Chi   -0.0015085638
## FSV1:Gig    0.0111432571
## FSV1:HtC   -0.0057341447
## FSV1:PtR   -0.0087612740
## FSV1:RiN   -0.0006269524
## FSV1:SnV   -0.0077744941
## FSV1:Tam   -0.0102527254
## FSV1:ViG   -0.0002983693
## FSV1:Yac    0.0111843894
fixef(modelo_blup)[1] + blups$`gen:mun`
##            (Intercept)
## CNCH12:Chi   0.2140750
## CNCH12:Gig   0.2151869
## CNCH12:HtC   0.2180296
## CNCH12:Jam   0.2335015
## CNCH12:PtR   0.2218680
## CNCH12:RiN   0.2175860
## CNCH12:SnV   0.2130678
## CNCH12:Tam   0.2156292
## CNCH12:ViG   0.2153582
## CNCH12:Yac   0.2147168
## CNCH13:Chi   0.2226353
## CNCH13:Gig   0.2189997
## CNCH13:HtC   0.2211851
## CNCH13:Jam   0.2265047
## CNCH13:PtR   0.2223942
## CNCH13:RiN   0.2156288
## CNCH13:SnV   0.2163693
## CNCH13:Tam   0.1978228
## CNCH13:ViG   0.2125977
## CNCH13:Yac   0.2001971
## FBO1:Chi     0.2219386
## FBO1:Gig     0.2071283
## FBO1:HtC     0.2239212
## FBO1:Jam     0.2225213
## FBO1:PtR     0.2135173
## FBO1:RiN     0.2199717
## FBO1:SnV     0.2251675
## FBO1:Tam     0.2153125
## FBO1:ViG     0.2175249
## FBO1:Yac     0.2116247
## FCHI8:Chi    0.2176423
## FCHI8:Gig    0.2099166
## FCHI8:HtC    0.2103491
## FCHI8:RiN    0.1963935
## FCHI8:SnV    0.2137136
## FCHI8:Tam    0.2552039
## FCHI8:ViG    0.2182682
## FCHI8:Yac    0.2162390
## FEAR5:Chi    0.2091927
## FEAR5:Gig    0.2143947
## FEAR5:HtC    0.2133665
## FEAR5:Jam    0.2222649
## FEAR5:PtR    0.2103394
## FEAR5:RiN    0.2171590
## FEAR5:SnV    0.2187760
## FEAR5:Tam    0.2146179
## FEAR5:ViG    0.2109872
## FEAR5:Yac    0.2297007
## FGI4:Chi     0.2192313
## FGI4:Gig     0.2141350
## FGI4:HtC     0.2220904
## FGI4:Jam     0.2138981
## FGI4:PtR     0.2098605
## FGI4:RiN     0.2320911
## FGI4:SnV     0.2123811
## FGI4:Tam     0.1993855
## FGI4:ViG     0.2193460
## FGI4:Yac     0.2235980
## FMA7:Chi     0.2268431
## FMA7:Gig     0.2221850
## FMA7:HtC     0.2147294
## FMA7:Jam     0.1989412
## FMA7:PtR     0.2276245
## FMA7:RiN     0.2077854
## FMA7:SnV     0.2290495
## FMA7:Tam     0.2156887
## FMA7:ViG     0.2172437
## FMA7:Yac     0.2312828
## FSV1:Chi     0.2154807
## FSV1:Gig     0.2281325
## FSV1:HtC     0.2112551
## FSV1:PtR     0.2082280
## FSV1:RiN     0.2163623
## FSV1:SnV     0.2092147
## FSV1:Tam     0.2067365
## FSV1:ViG     0.2166909
## FSV1:Yac     0.2281736
#Tabla blup_gen

blup_gen <- ranef(modelo_blup)$gen %>%
  tibble::rownames_to_column("gen") %>%
  rename(BLUP = `(Intercept)`)
blup_gen
##      gen         BLUP
## 1 CNCH12  0.007773787
## 2 CNCH13 -0.013251623
## 3   FBO1  0.007440711
## 4  FCHI8  0.001543602
## 5  FEAR5 -0.007745464
## 6   FGI4 -0.003300983
## 7   FMA7  0.018296901
## 8   FSV1 -0.010756932
#Tabla blup_mun
blup_mun <- ranef(modelo_blup)$mun %>%
  tibble::rownames_to_column("mun") %>%
  rename(BLUP = `(Intercept)`)
blup_mun
##    mun          BLUP
## 1  Chi  0.0103495174
## 2  Gig -0.0054284164
## 3  HtC -0.0009186205
## 4  Jam  0.0146021326
## 5  PtR -0.0047378460
## 6  RiN -0.0120343146
## 7  SnV  0.0016983315
## 8  Tam -0.0144353045
## 9  ViG -0.0073466676
## 10 Yac  0.0182511880
#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.0029142266
## 2  CNCH12:Gig -0.0018023414
## 3  CNCH12:HtC  0.0010404000
## 4  CNCH12:Jam  0.0165122382
## 5  CNCH12:PtR  0.0048788020
## 6  CNCH12:RiN  0.0005967371
## 7  CNCH12:SnV -0.0039214521
## 8  CNCH12:Tam -0.0013600913
## 9  CNCH12:ViG -0.0016309946
## 10 CNCH12:Yac -0.0022724722
## 11 CNCH13:Chi  0.0056460161
## 12 CNCH13:Gig  0.0020104594
## 13 CNCH13:HtC  0.0041958627
## 14 CNCH13:Jam  0.0095154791
## 15 CNCH13:PtR  0.0054049123
## 16 CNCH13:RiN -0.0013604299
## 17 CNCH13:SnV -0.0006199143
## 18 CNCH13:Tam -0.0191664104
## 19 CNCH13:ViG -0.0043915748
## 20 CNCH13:Yac -0.0167921008
## 21   FBO1:Chi  0.0049493343
## 22   FBO1:Gig -0.0098609702
## 23   FBO1:HtC  0.0069319466
## 24   FBO1:Jam  0.0055321068
## 25   FBO1:PtR -0.0034719770
## 26   FBO1:RiN  0.0029824805
## 27   FBO1:SnV  0.0081782877
## 28   FBO1:Tam -0.0016767379
## 29   FBO1:ViG  0.0005356361
## 30   FBO1:Yac -0.0053645463
## 31  FCHI8:Chi  0.0006530362
## 32  FCHI8:Gig -0.0070726242
## 33  FCHI8:HtC -0.0066401226
## 34  FCHI8:RiN -0.0205957354
## 35  FCHI8:SnV -0.0032756920
## 36  FCHI8:Tam  0.0382146924
## 37  FCHI8:ViG  0.0012789302
## 38  FCHI8:Yac -0.0007502612
## 39  FEAR5:Chi -0.0077964953
## 40  FEAR5:Gig -0.0025945063
## 41  FEAR5:HtC -0.0036227560
## 42  FEAR5:Jam  0.0052757012
## 43  FEAR5:PtR -0.0066498853
## 44  FEAR5:RiN  0.0001697601
## 45  FEAR5:SnV  0.0017867265
## 46  FEAR5:Tam -0.0023713689
## 47  FEAR5:ViG -0.0060020003
## 48  FEAR5:Yac  0.0127114775
## 49   FGI4:Chi  0.0022420916
## 50   FGI4:Gig -0.0028542164
## 51   FGI4:HtC  0.0051011547
## 52   FGI4:Jam -0.0030911789
## 53   FGI4:PtR -0.0071287081
## 54   FGI4:RiN  0.0151018640
## 55   FGI4:SnV -0.0046081393
## 56   FGI4:Tam -0.0176037803
## 57   FGI4:ViG  0.0023567226
## 58   FGI4:Yac  0.0066087620
## 59   FMA7:Chi  0.0098538422
## 60   FMA7:Gig  0.0051957596
## 61   FMA7:HtC -0.0022597960
## 62   FMA7:Jam -0.0180480366
## 63   FMA7:PtR  0.0106352644
## 64   FMA7:RiN -0.0092038023
## 65   FMA7:SnV  0.0120602697
## 66   FMA7:Tam -0.0013005591
## 67   FMA7:ViG  0.0002544768
## 68   FMA7:Yac  0.0142935502
## 69   FSV1:Chi -0.0015085638
## 70   FSV1:Gig  0.0111432571
## 71   FSV1:HtC -0.0057341447
## 72   FSV1:PtR -0.0087612740
## 73   FSV1:RiN -0.0006269524
## 74   FSV1:SnV -0.0077744941
## 75   FSV1:Tam -0.0102527254
## 76   FSV1:ViG -0.0002983693
## 77   FSV1:Yac  0.0111843894
#Predichos completos
datos$pred <- predict(modelo_blup)
datos$pred
##   [1] 0.1935710 0.1935710 0.1935710 0.1935710 0.1935710 0.1935710 0.1935710
##   [8] 0.1935710 0.1859028 0.1859028 0.1859028 0.1859028 0.1859028 0.1859028
##  [15] 0.1859028 0.1859028 0.1973792 0.1973792 0.1973792 0.1973792 0.1973792
##  [22] 0.1973792 0.1973792 0.1973792 0.2153781 0.2153781 0.2153781 0.2153781
##  [29] 0.2153781 0.2153781 0.2153781 0.2153781 0.1903429 0.1903429 0.1903429
##  [36] 0.1903429 0.1903429 0.1903429 0.1903429 0.1903429 0.2167558 0.2167558
##  [43] 0.2167558 0.2167558 0.2167558 0.2167558 0.2167558 0.2167558 0.2140480
##  [50] 0.2140480 0.2140480 0.2140480 0.2140480 0.2140480 0.2140480 0.2140480
##  [57] 0.2133255 0.2133255 0.2133255 0.2133255 0.2133255 0.2133255 0.2133255
##  [64] 0.2133255 0.2001561 0.2001561 0.2001561 0.2001561 0.2001561 0.2001561
##  [71] 0.2001561 0.2001561 0.2048160 0.2048160 0.2048160 0.2048160 0.2048160
##  [78] 0.2048160 0.2048160 0.2048160 0.2107785 0.2107785 0.2107785 0.2107785
##  [85] 0.2107785 0.2107785 0.2107785 0.2107785 0.2169555 0.2169555 0.2169555
##  [92] 0.2169555 0.2169555 0.2169555 0.2169555 0.2169555 0.2127288 0.2127288
##  [99] 0.2127288 0.2127288 0.2127288 0.2127288 0.2127288 0.2127288 0.2490447
## [106] 0.2490447 0.2490447 0.2490447 0.2490447 0.2490447 0.2490447 0.2490447
## [113] 0.2343066 0.2343066 0.2343066 0.2343066 0.2343066 0.2343066 0.2343066
## [120] 0.2343066 0.2225399 0.2225399 0.2225399 0.2225399 0.2225399 0.2225399
## [127] 0.2225399 0.2225399 0.2150733 0.2150733 0.2150733 0.2150733 0.2150733
## [134] 0.2150733 0.2150733 0.2150733 0.2554895 0.2554895 0.2554895 0.2554895
## [141] 0.2554895 0.2554895 0.2554895 0.2554895 0.2117968 0.2117968 0.2117968
## [148] 0.2117968 0.2117968 0.2117968 0.2117968 0.2117968 0.2295354 0.2295354
## [155] 0.2295354 0.2295354 0.2295354 0.2295354 0.2295354 0.2295354 0.2262799
## [162] 0.2262799 0.2262799 0.2262799 0.2262799 0.2262799 0.2262799 0.2262799
## [169] 0.2321983 0.2321983 0.2321983 0.2321983 0.2321983 0.2321983 0.2321983
## [176] 0.2321983 0.2197332 0.2197332 0.2197332 0.2197332 0.2197332 0.2197332
## [183] 0.2197332 0.2197332 0.2397288 0.2397288 0.2397288 0.2397288 0.2397288
## [190] 0.2397288 0.2397288 0.2397288 0.2356679 0.2356679 0.2356679 0.2356679
## [197] 0.2356679 0.2356679 0.2356679 0.2356679 0.2051967 0.2051967 0.2051967
## [204] 0.2051967 0.2051967 0.2051967 0.2051967 0.2051967 0.2385482 0.2385482
## [211] 0.2385482 0.2385482 0.2385482 0.2385482 0.2385482 0.2385482 0.2360338
## [218] 0.2360338 0.2360338 0.2360338 0.2360338 0.2360338 0.2360338 0.2360338
## [225] 0.2402064 0.2402064 0.2402064 0.2402064 0.2402064 0.2402064 0.2402064
## [232] 0.2402064 0.2678309 0.2678309 0.2678309 0.2678309 0.2678309 0.2678309
## [239] 0.2678309 0.2678309 0.2373166 0.2373166 0.2373166 0.2373166 0.2373166
## [246] 0.2373166 0.2373166 0.2373166 0.2407417 0.2407417 0.2407417 0.2407417
## [253] 0.2407417 0.2407417 0.2407417 0.2407417 0.1927332 0.1927332 0.1927332
## [260] 0.1927332 0.1927332 0.1927332 0.1927332 0.1927332 0.2411836 0.2411836
## [267] 0.2411836 0.2411836 0.2411836 0.2411836 0.2411836 0.2411836 0.1978560
## [274] 0.1978560 0.1978560 0.1978560 0.1978560 0.1978560 0.1978560 0.1978560
## [281] 0.2018217 0.2018217 0.2018217 0.2018217 0.2018217 0.2018217 0.2018217
## [288] 0.2018217 0.2249040 0.2249040 0.2249040 0.2249040 0.2249040 0.2249040
## [295] 0.2249040 0.2249040 0.2044047 0.2044047 0.2044047 0.2044047 0.2044047
## [302] 0.2044047 0.2044047 0.2044047 0.2162201 0.2162201 0.2162201 0.2162201
## [309] 0.2162201 0.2162201 0.2162201 0.2162201 0.1985873 0.1985873 0.1985873
## [316] 0.1985873 0.1985873 0.1985873 0.1985873 0.1985873 0.2281940 0.2281940
## [323] 0.2281940 0.2281940 0.2281940 0.2281940 0.2281940 0.2281940 0.1958951
## [330] 0.1958951 0.1958951 0.1958951 0.1958951 0.1958951 0.1958951 0.1958951
## [337] 0.2124651 0.2124651 0.2124651 0.2124651 0.2124651 0.2124651 0.2124651
## [344] 0.2124651 0.2086983 0.2086983 0.2086983 0.2086983 0.2086983 0.2086983
## [351] 0.2086983 0.2086983 0.2157854 0.2157854 0.2157854 0.2157854 0.2157854
## [358] 0.2157854 0.2157854 0.2157854 0.1919994 0.1919994 0.1919994 0.1919994
## [365] 0.1919994 0.1919994 0.1919994 0.1919994 0.2176189 0.2176189 0.2176189
## [372] 0.2176189 0.2176189 0.2176189 0.2176189 0.2176189 0.2119472 0.2119472
## [379] 0.2119472 0.2119472 0.2119472 0.2119472 0.2119472 0.2119472 0.2350535
## [386] 0.2350535 0.2350535 0.2350535 0.2350535 0.2350535 0.2350535 0.2350535
## [393] 0.2012209 0.2012209 0.2012209 0.2012209 0.2012209 0.2012209 0.2012209
## [400] 0.2012209 0.2060318 0.2060318 0.2060318 0.2060318 0.2060318 0.2060318
## [407] 0.2060318 0.2060318 0.2054056 0.2054056 0.2054056 0.2054056 0.2054056
## [414] 0.2054056 0.2054056 0.2054056 0.2175323 0.2175323 0.2175323 0.2175323
## [421] 0.2175323 0.2175323 0.2175323 0.2175323 0.2003197 0.2003197 0.2003197
## [428] 0.2003197 0.2003197 0.2003197 0.2003197 0.2003197 0.2091406 0.2091406
## [435] 0.2091406 0.2091406 0.2091406 0.2091406 0.2091406 0.2091406 0.1815443
## [442] 0.1815443 0.1815443 0.1815443 0.1815443 0.1815443 0.1815443 0.1815443
## [449] 0.2195503 0.2195503 0.2195503 0.2195503 0.2195503 0.2195503 0.2195503
## [456] 0.2195503 0.1924371 0.1924371 0.1924371 0.1924371 0.1924371 0.1924371
## [463] 0.1924371 0.1924371 0.2423122 0.2423122 0.2423122 0.2423122 0.2423122
## [470] 0.2423122 0.2423122 0.2423122 0.1816492 0.1816492 0.1816492 0.1816492
## [477] 0.1816492 0.1816492 0.1816492 0.1816492 0.2089676 0.2089676 0.2089676
## [484] 0.2089676 0.2089676 0.2089676 0.2089676 0.2089676 0.1701359 0.1701359
## [491] 0.1701359 0.1701359 0.1701359 0.1701359 0.1701359 0.1701359 0.2083179
## [498] 0.2083179 0.2083179 0.2083179 0.2083179 0.2083179 0.2083179 0.2083179
## [505] 0.1995795 0.1995795 0.1995795 0.1995795 0.1995795 0.1995795 0.1995795
## [512] 0.1995795 0.2321077 0.2321077 0.2321077 0.2321077 0.2321077 0.2321077
## [519] 0.2321077 0.2321077 0.2047024 0.2047024 0.2047024 0.2047024 0.2047024
## [526] 0.2047024 0.2047024 0.2047024 0.2109741 0.2109741 0.2109741 0.2109741
## [533] 0.2109741 0.2109741 0.2109741 0.2109741 0.2178708 0.2178708 0.2178708
## [540] 0.2178708 0.2178708 0.2178708 0.2178708 0.2178708 0.2248848 0.2248848
## [547] 0.2248848 0.2248848 0.2248848 0.2248848 0.2248848 0.2248848 0.2070149
## [554] 0.2070149 0.2070149 0.2070149 0.2070149 0.2070149 0.2070149 0.2070149
## [561] 0.2304433 0.2304433 0.2304433 0.2304433 0.2304433 0.2304433 0.2304433
## [568] 0.2304433 0.2278552 0.2278552 0.2278552 0.2278552 0.2278552 0.2278552
## [575] 0.2278552 0.2278552 0.2251992 0.2251992 0.2251992 0.2251992 0.2251992
## [582] 0.2251992 0.2251992 0.2251992 0.2291216 0.2291216 0.2291216 0.2291216
## [589] 0.2291216 0.2291216 0.2291216 0.2291216 0.2318402 0.2318402 0.2318402
## [596] 0.2318402 0.2318402 0.2318402 0.2318402 0.2318402 0.2445642 0.2445642
## [603] 0.2445642 0.2445642 0.2445642 0.2445642 0.2445642 0.2445642 0.2558774
## [610] 0.2558774 0.2558774 0.2558774 0.2558774 0.2558774 0.2558774 0.2558774
#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.0001655084 0.01286501
## 2      mun (Intercept) <NA> 0.0001539710 0.01240850
## 3      gen (Intercept) <NA> 0.0001409755 0.01187331
## 4 Residual        <NA> <NA> 0.0009420051 0.03069210
VarCorr(modelo_blup)
##  Groups   Name        Std.Dev.
##  gen:mun  (Intercept) 0.012865
##  mun      (Intercept) 0.012409
##  gen      (Intercept) 0.011873
##  Residual             0.030692
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.7785413
#H2 plasticidad
H2ge <- varGE / (varG + varGE/e + varE/(r*e))
H2ge
## [1] 0.9140248
###ranking genotipos predichos

blup_gen <- ranef(modelo_blup)$gen
blup_gen
##         (Intercept)
## CNCH12  0.007773787
## CNCH13 -0.013251623
## FBO1    0.007440711
## FCHI8   0.001543602
## FEAR5  -0.007745464
## FGI4   -0.003300983
## FMA7    0.018296901
## FSV1   -0.010756932
##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
## FMA7    0.018296901 0.2352861
## CNCH12  0.007773787 0.2247630
## FBO1    0.007440711 0.2244300
## FCHI8   0.001543602 0.2185328
## FGI4   -0.003300983 0.2136883
## FEAR5  -0.007745464 0.2092438
## FSV1   -0.010756932 0.2062323
## CNCH13 -0.013251623 0.2037376
# 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(GR=mean(GR)) %>%
  pivot_wider(names_from=mun,
              values_from=GR)
## `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, GR)
## Warning: Data imputation used to fill the GxE matrix
modelo_metan
## $GR
## $coordgen
##             [,1]         [,2]          [,3]         [,4]         [,5]
## [1,]  0.01026163 -0.003841048  0.0277233050 -0.021008733 -0.048427585
## [2,] -0.03188598 -0.001407567  0.0289091500  0.043631449  0.002631111
## [3,]  0.01226632 -0.010745713  0.0279273520 -0.017231092  0.028234156
## [4,]  0.02170155  0.053840815 -0.0009048515  0.004480703  0.014601073
## [5,] -0.01472987  0.009663826 -0.0199496412 -0.019709760 -0.005745227
## [6,] -0.01501613 -0.022897324 -0.0083380004 -0.023512818  0.028035471
## [7,]  0.04122251 -0.028133113 -0.0218861380  0.028780386 -0.003173510
## [8,] -0.02382003  0.003520124 -0.0334811760  0.004569865 -0.016155490
##              [,6]         [,7]       [,8]
## [1,] -0.012283749 -0.008359541 0.02359179
## [2,]  0.005995792 -0.009746542 0.02359179
## [3,]  0.012993116  0.039840148 0.02359179
## [4,] -0.014398501 -0.009209370 0.02359179
## [5,]  0.050739519 -0.013844806 0.02359179
## [6,] -0.028505069 -0.030419295 0.02359179
## [7,]  0.006815633 -0.006434387 0.02359179
## [8,] -0.021356742  0.038173794 0.02359179
## 
## $coordenv
##              [,1]         [,2]          [,3]         [,4]         [,5]
##  [1,] 0.036951620 -0.019265939  7.624159e-03  0.013138207  0.008749405
##  [2,] 0.018600903 -0.017045231 -1.453165e-02  0.012616309 -0.015789535
##  [3,] 0.022838797 -0.022506179  1.863177e-02 -0.005601145  0.006621782
##  [4,] 0.006490071  0.007207738  3.336060e-02 -0.016879027 -0.018332678
##  [5,] 0.044363585 -0.014673131  1.418723e-02  0.017061290 -0.011427385
##  [6,] 0.002509301 -0.039906511  7.124408e-03 -0.023913799  0.003792854
##  [7,] 0.045818759 -0.021015222  5.369693e-03  0.004971279  0.006523497
##  [8,] 0.075617793  0.055431540 -4.773848e-05 -0.008253945  0.003874172
##  [9,] 0.032847351 -0.009535922  1.324612e-03 -0.004683841  0.003614218
## [10,] 0.038954718 -0.017153244 -4.073112e-02 -0.016156124 -0.007059176
##                [,6]          [,7]          [,8]
##  [1,] -0.0067157281  0.0024174353  2.815588e-17
##  [2,] -0.0069563771  0.0050640400  3.891516e-19
##  [3,] -0.0012922325 -0.0001702132  1.842745e-17
##  [4,]  0.0025227722  0.0033027838  6.524451e-18
##  [5,]  0.0008494113 -0.0078613338 -7.175962e-18
##  [6,] -0.0045567879 -0.0024283193 -3.766340e-18
##  [7,]  0.0164625444  0.0038697472 -1.513337e-17
##  [8,] -0.0026911801 -0.0005192360  3.542684e-18
##  [9,] -0.0104550688  0.0020360562 -3.790385e-17
## [10,]  0.0040321809 -0.0013129079  1.251444e-17
## 
## $eigenvalues
## [1] 1.210925e-01 8.323154e-02 6.058893e-02 4.343749e-02 3.116452e-02
## [6] 2.295293e-02 1.145587e-02 5.545815e-17
## 
## $totalvar
## [1] 0.03
## 
## $varexpl
## [1] 48.88 23.09 12.24  6.29  3.24  1.76  0.44  0.00
## 
## $labelgen
## [1] "CNCH12" "CNCH13" "FBO1"   "FCHI8"  "FEAR5"  "FGI4"   "FMA7"   "FSV1"  
## 
## $labelenv
##  [1] "Chi" "Gig" "HtC" "Jam" "PtR" "RiN" "SnV" "Tam" "ViG" "Yac"
## 
## $labelaxes
## [1] "PC1" "PC2" "PC3" "PC4" "PC5" "PC6" "PC7" "PC8"
## 
## $ge_mat
##                Chi        Gig          HtC           Jam          PtR
## CNCH12  0.00040625  0.0059375  0.009765625  0.0321844849  0.017311676
## CNCH13 -0.00596875 -0.0085625 -0.005859375 -0.0008155151 -0.002813324
## FBO1    0.01353125 -0.0081875  0.019515625  0.0130594849  0.002686676
## FCHI8   0.00028125 -0.0093125 -0.009609375  0.0013290039  0.001943270
## FEAR5  -0.02346875 -0.0109375 -0.013734375 -0.0025655151 -0.017938324
## FGI4   -0.00184375 -0.0069375  0.005640625 -0.0124405151 -0.014313324
## FMA7    0.03278125  0.0284375  0.014640625 -0.0164405151  0.037686676
## FSV1   -0.01571875  0.0095625 -0.020359375 -0.0143109134 -0.024563324
##               RiN          SnV          Tam          ViG        Yac
## CNCH12  0.0115625  0.000671875  0.008765625  0.006671875 -0.0003125
## CNCH13 -0.0128125 -0.014703125 -0.042734375 -0.019078125 -0.0461875
## FBO1    0.0153125  0.021046875  0.007890625  0.010046875 -0.0059375
## FCHI8  -0.0309375 -0.004453125  0.070265625  0.005421875 -0.0039375
## FEAR5  -0.0046875 -0.005078125 -0.008484375 -0.016328125  0.0098125
## FGI4    0.0253125 -0.011578125 -0.030109375  0.002421875  0.0038125
## FMA7    0.0053125  0.038546875  0.019390625  0.020421875  0.0385625
## FSV1   -0.0090625 -0.024453125 -0.024984375 -0.009578125  0.0041875
## 
## $centering
## [1] "environment"
## 
## $scaling
## [1] "none"
## 
## $svp
## [1] "environment"
## 
## $d
## [1] 14.98629
## 
## $grand_mean
## [1] 0.2170285
## 
## $mean_gen
##    CNCH12    CNCH13      FBO1     FCHI8     FEAR5      FGI4      FMA7      FSV1 
## 0.2263250 0.2010750 0.2259250 0.2191276 0.2076875 0.2130250 0.2389625 0.2041005 
## 
## $mean_env
##       Chi       Gig       HtC       Jam       PtR       RiN       SnV       Tam 
## 0.2297187 0.2103125 0.2158594 0.2354405 0.2110633 0.2021875 0.2190781 0.1992344 
##       ViG       Yac 
## 0.2079531 0.2394375 
## 
## $scale_val
##        Chi        Gig        HtC        Jam        PtR        RiN        SnV 
## 0.01729920 0.01378518 0.01440338 0.01623604 0.02024458 0.01797816 0.02043489 
##        Tam        ViG        Yac 
## 0.03561973 0.01373261 0.02329795 
## 
## 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 0.2247630
## CNCH13 CNCH13 0.2037376
## FBO1     FBO1 0.2244300
## FCHI8   FCHI8 0.2185328
## FEAR5   FEAR5 0.2092438
## FGI4     FGI4 0.2136883
## FMA7     FMA7 0.2352861
## FSV1     FSV1 0.2062323
##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(GR))

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

#visualización Normas de reacción joint regression env
ggplot(datos, aes(x = env, y = GR,
                  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 = GR,
                  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(GR ~ gen*env, 
                  data=datos)
emtrends(mod_plas_lm, "gen", var = "env")
##  gen    env.trend    SE  df lower.CL upper.CL
##  CNCH12     1.028 0.272 600    0.494    1.563
##  CNCH13     1.018 0.272 600    0.484    1.552
##  FBO1       0.913 0.272 600    0.379    1.448
##  FCHI8      0.366 0.318 600   -0.259    0.991
##  FEAR5      1.223 0.272 600    0.689    1.758
##  FGI4       1.006 0.272 600    0.472    1.541
##  FMA7       0.934 0.272 600    0.399    1.468
##  FSV1       1.287 0.316 600    0.667    1.908
## 
## Confidence level used: 0.95
# modelo blup  factores aleatorios
modelo_plasticidad <- lmer(GR ~ 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(GR ~ gen*E, 
                   data=datos)
emtrends(mod_plas2_lm, "gen", var = "E")
##  gen    E.trend     SE  df lower.CL upper.CL
##  CNCH12 -0.1461 0.0659 600   -0.275 -0.01678
##  CNCH13 -0.1595 0.0659 600   -0.289 -0.03015
##  FBO1   -0.1251 0.0659 600   -0.254  0.00423
##  FCHI8   0.0231 0.0696 600   -0.114  0.15985
##  FEAR5  -0.2103 0.0659 600   -0.340 -0.08098
##  FGI4   -0.1932 0.0659 600   -0.323 -0.06386
##  FMA7   -0.2532 0.0659 600   -0.382 -0.12382
##  FSV1   -0.1860 0.0667 600   -0.317 -0.05494
## 
## Confidence level used: 0.95
#Modelo factores aleatorios

modelo_plasticidad2 <- lmer(GR ~ E +
                              (E|gen) +
                              (1|mun),
                            data=datos)

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             2         100.                  100.
## 2 PC2             0           0.03                100 
## -------------------------------------------------------------------------------
## Factor Analysis - factorial loadings after rotation-
## -------------------------------------------------------------------------------
## # A tibble: 2 × 4
##   VAR         FA1 Communality Uniquenesses
##   <chr>     <dbl>       <dbl>        <dbl>
## 1 BLUP_C       -1           1            0
## 2 Pendiente     1           1            0
## -------------------------------------------------------------------------------
## Comunalit Mean: 0.9996821 
## -------------------------------------------------------------------------------
## 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     2.17e- 1  0.219   0.00154  7.11e- 1 increase   100
## 2 Pendiente FA1    -1.16e-13 -0.0197 -0.0197  -1.70e+13 increase     0
## ------------------------------------------------------------------------------
## Selected genotypes
## -------------------------------------------------------------------------------
## FCHI8
## -------------------------------------------------------------------------------
#ranking MGIDI 1
mgidi_mod$MGIDI
## # A tibble: 8 × 2
##   Genotype  MGIDI
##   <chr>     <dbl>
## 1 FCHI8    0.0447
## 2 FBO1     0.457 
## 3 CNCH12   0.482 
## 4 FGI4     0.541 
## 5 FEAR5    0.963 
## 6 FSV1     1.22  
## 7 FMA7     1.46  
## 8 CNCH13   1.46
#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.01          67.0                 67.0
## 2 PC2          0.99          33.0                100. 
## 3 PC3          0              0.01               100  
## -------------------------------------------------------------------------------
## Factor Analysis - factorial loadings after rotation-
## -------------------------------------------------------------------------------
## # A tibble: 3 × 4
##   VAR          FA1 Communality Uniquenesses
##   <chr>      <dbl>       <dbl>        <dbl>
## 1 BLUP_C      1           1            0   
## 2 Pendiente  -1           0.99         0.01
## 3 Pendiente2  0.15        0.02         0.98
## -------------------------------------------------------------------------------
## Comunalit Mean: 0.670433 
## -------------------------------------------------------------------------------
## 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     2.17e- 1  0.219   0.00154  7.11e- 1 increase   100
## 2 Pendiente  FA1    -1.16e-13 -0.0197 -0.0197  -1.70e+13 increase     0
## 3 Pendiente2 FA1    -5.12e-15  0.0695  0.0695   1.36e+15 decrease     0
## ------------------------------------------------------------------------------
## Selected genotypes
## -------------------------------------------------------------------------------
## FCHI8
## -------------------------------------------------------------------------------
#ranking MGIDI 1
mgidi_mod2$MGIDI
## # A tibble: 8 × 2
##   Genotype MGIDI
##   <chr>    <dbl>
## 1 FCHI8    0.305
## 2 FBO1     0.328
## 3 CNCH12   0.372
## 4 FGI4     0.603
## 5 FEAR5    1.01 
## 6 FSV1     1.27 
## 7 FMA7     1.45 
## 8 CNCH13   1.55
#Gráfico Selección 1
plot(mgidi_mod2)