df1 = read_excel('parcial.xlsx')
df2 = melt(df1, c('GENOTIPOS', 'LOCALIDADES'), variable.name = 'REP', value.name = 'RTO')
df1
## # A tibble: 50 x 6
## GENOTIPOS LOCALIDADES REP1 REP2 REP3 REP4
## <chr> <chr> <dbl> <dbl> <dbl> <dbl>
## 1 T1 LocA 3.9 4 3.5 4.9
## 2 T1 LocB 3.3 3.5 3.9 4.6
## 3 T1 LocC 3.2 3.2 3.6 4.2
## 4 T1 LocD 3.9 3.8 3.7 4.9
## 5 T1 LocE 3.2 3.6 3.2 4.2
## 6 UN2 LocA 3.5 3.5 3.8 4.6
## 7 UN2 LocB 2.6 3.1 3.2 3.7
## 8 UN2 LocC 5.1 5.1 5.1 6.9
## 9 UN2 LocD 3.5 3.2 3 4
## 10 UN2 LocE 3.2 3.3 3.5 4.2
## # ... with 40 more rows
df2r = df2 %>%
group_by(GENOTIPOS, LOCALIDADES) %>%
summarise(nrep = n(),
mrto = mean(RTO))
## `summarise()` has grouped output by 'GENOTIPOS'. You can override using the
## `.groups` argument.
df2r
## # A tibble: 50 x 4
## # Groups: GENOTIPOS [10]
## GENOTIPOS LOCALIDADES nrep mrto
## <chr> <chr> <int> <dbl>
## 1 T1 LocA 4 4.08
## 2 T1 LocB 4 3.82
## 3 T1 LocC 4 3.55
## 4 T1 LocD 4 4.08
## 5 T1 LocE 4 3.55
## 6 UN10 LocA 4 5.35
## 7 UN10 LocB 4 8.5
## 8 UN10 LocC 4 8.88
## 9 UN10 LocD 4 5.5
## 10 UN10 LocE 4 9.15
## # ... with 40 more rows
df3 = df2r %>%
ungroup() %>%
mutate(mtot = mean(mrto)) %>%
group_by(LOCALIDADES) %>%
mutate(ml = mean(mrto)) %>%
group_by(GENOTIPOS) %>%
mutate(mg = mean(mrto)) %>%
ungroup() %>%
mutate(ei = ml-mtot)
df3
## # A tibble: 50 x 8
## GENOTIPOS LOCALIDADES nrep mrto mtot ml mg ei
## <chr> <chr> <int> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 T1 LocA 4 4.08 5.46 6.55 3.82 1.09
## 2 T1 LocB 4 3.82 5.46 6.52 3.82 1.05
## 3 T1 LocC 4 3.55 5.46 5.84 3.82 0.372
## 4 T1 LocD 4 4.08 5.46 4.17 3.82 -1.29
## 5 T1 LocE 4 3.55 5.46 4.25 3.82 -1.22
## 6 UN10 LocA 4 5.35 5.46 6.55 7.48 1.09
## 7 UN10 LocB 4 8.5 5.46 6.52 7.48 1.05
## 8 UN10 LocC 4 8.88 5.46 5.84 7.48 0.372
## 9 UN10 LocD 4 5.5 5.46 4.17 7.48 -1.29
## 10 UN10 LocE 4 9.15 5.46 4.25 7.48 -1.22
## # ... with 40 more rows
mod1l = lm(RTO ~ GENOTIPOS + LOCALIDADES + LOCALIDADES/REP + LOCALIDADES * GENOTIPOS,
data = df2)
mod1a <- anova(mod1l)
mod1a
## Analysis of Variance Table
##
## Response: RTO
## Df Sum Sq Mean Sq F value Pr(>F)
## GENOTIPOS 9 215.988 23.999 101.084 < 2.2e-16 ***
## LOCALIDADES 4 223.038 55.759 234.863 < 2.2e-16 ***
## LOCALIDADES:REP 15 134.337 8.956 37.722 < 2.2e-16 ***
## GENOTIPOS:LOCALIDADES 36 211.910 5.886 24.794 < 2.2e-16 ***
## Residuals 135 32.051 0.237
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
(MSE = mod1a$`Mean Sq`[5])
## [1] 0.237413
df3r = df3 %>%
group_by(GENOTIPOS) %>%
summarise(nb = sum(ei*(mrto-mean(mrto))),
b = nb/sum(ei**2),
svar = sum((mrto-mean(mrto))**2),
bnb = b*nb,
d = svar - bnb,
s2d = (d/(n()-2)) - (MSE/mean(nrep))) %>%
arrange(desc(b))
df3r
## # A tibble: 10 x 7
## GENOTIPOS nb b svar bnb d s2d
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 UN3 11.0 1.97 22.8 21.6 1.22 0.348
## 2 UN4 10.1 1.81 19.3 18.2 1.16 0.326
## 3 UN5 8.15 1.46 13.5 11.9 1.63 0.484
## 4 UN7 7.98 1.43 14.4 11.4 2.99 0.939
## 5 UN6 6.55 1.18 8.18 7.70 0.481 0.101
## 6 UN9 6.21 1.11 7.14 6.92 0.218 0.0133
## 7 UN8 5.04 0.903 5.20 4.55 0.654 0.159
## 8 UN2 0.810 0.145 3.64 0.118 3.52 1.11
## 9 T1 0.180 0.0324 0.276 0.00584 0.270 0.0306
## 10 UN10 -0.193 -0.0346 14.2 0.00668 14.2 4.68
ggplot(df3)+
aes(ei, mrto, color = GENOTIPOS)+
geom_point(size = 3)+
geom_smooth(formula = 'y~x', method = 'lm', se = FALSE)+
geom_vline(xintercept = 0, linetype='dashed')+
theme_bw()+
theme(legend.position = 'bottom')
Genotipos con \(\beta >= 1\)
df3r |>
select(GENOTIPOS, b, s2d) |>
filter(b>=1)
## # A tibble: 6 x 3
## GENOTIPOS b s2d
## <chr> <dbl> <dbl>
## 1 UN3 1.97 0.348
## 2 UN4 1.81 0.326
## 3 UN5 1.46 0.484
## 4 UN7 1.43 0.939
## 5 UN6 1.18 0.101
## 6 UN9 1.11 0.0133
Genotipos con \(\beta < 1\)
df3r |>
select(GENOTIPOS, b, s2d) |>
filter(b<1)
## # A tibble: 4 x 3
## GENOTIPOS b s2d
## <chr> <dbl> <dbl>
## 1 UN8 0.903 0.159
## 2 UN2 0.145 1.11
## 3 T1 0.0324 0.0306
## 4 UN10 -0.0346 4.68
# writexl::write_xlsx(df3r, 'res_ge.xlsx')