y.lab = "MGIDI index") +
my_theme +
theme(legend.title = element_blank(),
legend.position = "bottom")
library(metan)      # MGIDI index
library(rio)        # data importation
library(broom)      # convert statistical objects into tidy tibbles
library(purrr)      # Manipulate lists
library(tidyverse)  # plots, data manipulation
library(kableExtra) # html tables
library(emmeans)    # pairwise multiple comparison
library(AgroR)     # pairwise multiple comparison
library(factoextra)
# set a theme plot
my_theme <-
theme_bw() +
theme(legend.title = element_blank(),
axis.title = element_text(color = "black"),
axis.text = element_text(color = "black"),
panel.grid.minor = element_blank())
df <-
g_simula(ngen = 5,
nrep = 3,
nvars = 3,
seed = c(3, 20, 40)) %>%
replace_string(GEN, pattern =  "H", replacement = "T")
df <-
g_simula(ngen = 5,
nrep = 3,
nvars = 3,
seed = c(3, 20, 40)) %>%
replace_string(GEN, pattern =  "H", replacement = "T")
df
df <-
g_simula(ngen = 5,
nrep = 3,
nvars = 3,
seed = c(3, 20, 40)) %>%
mean_by(TRAT)
df <-
g_simula(ngen = 5,
nrep = 3,
nvars = 3,
seed = c(3, 20, 40)) %>%
mean_by(GEN)
df
df <-
g_simula(ngen = 5,
nrep = 3,
nvars = 3,
seed = c(3, 20, 40)) %>%
mean_by(GEN) |>
column_to_rownames("GEN")
equal_weigths <- mgidi(df)
equal_weigths <- mgidi(df, verbose = FALSE)
equal_weigths$sc
equal_weigths$scores_ide
df
equal_weigths
df
df <-
g_simula(ngen = 5,
nrep = 3,
nvars = 3,
seed = c(5, 2, 3)) %>%
mean_by(GEN) |>
column_to_rownames("GEN")
equal_weigths <- mgidi(df, verbose = FALSE)
equal_weigths$scores_ide
df <-
g_simula(ngen = 5,
nrep = 3,
nvars = 3,
seed = c(5, 2, 32)) %>%
mean_by(GEN) |>
column_to_rownames("GEN")
equal_weigths <- mgidi(df, verbose = FALSE)
equal_weigths$scores_ide
df
equal_weigths <- mgidi(df, verbose = T)
df
equal_weigths <- mgidi(df, verbose = FALSE)
equal_weigths$scores_ide
equal_weigths$scores_gen
wv2 <- mgidi(df,
weights = c(1, 4, 1),
verbose = FALSE)
wv2
df
wv2 <- mgidi(df,
weights = c(1, 5, 1),
verbose = FALSE)
wv2
wv2 <- mgidi(df,
weights = c(1, 5, 1),
verbose = T)
wv2$MGIDI
df
wv2 <- mgidi(df,
# weights = c(1, 5, 1),
verbose = FALSE)
wv2$MGIDI
wv2 <- mgidi(df,
weights = c(1, 10, 1),
verbose = FALSE)
wv2$MGIDI
wv2 <- mgidi(df,
weights = c(1, 20, 1),
verbose = FALSE)
wv2$MGIDI
wv2 <- mgidi(df,
weights = c(0.2, 1, 0.2),
verbose = FALSE)
wv2$MGIDI
wv2 <- mgidi(df,
weights = c(0.2, 3, 0.2),
verbose = FALSE)
wv2$MGIDI
wv2 <- mgidi(df,
weights = c(0.1, 1, 0.1),
verbose = FALSE)
wv2$MGIDI
equal_weigths$scores_ide
equal_weigths$scores_gen
wv2$scores_ide
wv2$scores_gen
wv2 <- mgidi(df,
weights = c(0.2, 1, 0.2),
verbose = FALSE)
wv2$MGIDI
wv2$scores_ide
wv2$scores_gen
# equal weights
equal_weigths <- mgidi(df, verbose = FALSE)
equal_weigths$MGIDI
equal_weigths$scores_ide
equal_weigths$scores_gen
equal_weigths$MGIDI
df
equal_weigths$scores_ide
equal_weigths$scores_gen
equal_weigths$MGIDI
# higuer weight for V2
wv2 <- mgidi(df,
weights = c(0.2, 1, 0.2),
verbose = FALSE)
wv2$MGIDI
wv2$scores_ide
wv2$scores_gen
df
wv2$scores_ide
wv2$scores_gen
wv2$MGIDI
# higuer weight for V2
wv2 <- mgidi(df,
weights = c(1, 5, 1),
verbose = FALSE)
df
wv2$scores_ide
wv2$scores_gen
wv2$MGIDI
# higuer weight for V2
wv2 <- mgidi(df,
weights = c(1, 10, 1),
verbose = FALSE)
df
wv2$scores_ide
wv2$scores_gen
wv2$MGIDI
# higuer weight for V2
wv2 <- mgidi(df,
weights = c(1, 15, 1),
verbose = FALSE)
df
wv2$scores_ide
wv2$scores_gen
wv2$MGIDI
# higuer weight for V2
wv2 <- mgidi(df,
weights = c(.5, 1, .51),
verbose = FALSE)
df
wv2$scores_ide
wv2$scores_gen
wv2$MGIDI
# higuer weight for V2
wv2 <- mgidi(df,
weights = c(1, 5, 1),
verbose = FALSE)
df
wv2$scores_ide
wv2$scores_gen
wv2$MGIDI
equal_weigths$MGIDI
wv2$MGIDI
# higuer weight for V2
wv2 <- mgidi(df,
weights = c(1, 15, 1),
verbose = FALSE)
df
wv2$scores_ide
wv2$scores_gen
wv2$MGIDI
equal_weigths$scores_ide
wv2$scores_ide
equal_weigths$MGIDI
df
demo(awsimage)
install.packages(ImageMagick)
install.packages("ImageMagick")
library(metan)      # MGIDI index
library(rio)        # data importation
library(broom)      # convert statistical objects into tidy tibbles
library(purrr)      # Manipulate lists
library(tidyverse)  # plots, data manipulation
library(kableExtra) # html tables
library(emmeans)    # pairwise multiple comparison
library(AgroR)     # pairwise multiple comparison
library(factoextra)
# set a theme plot
my_theme <-
theme_bw() +
theme(legend.title = element_blank(),
axis.title = element_text(color = "black"),
axis.text = element_text(color = "black"),
panel.grid.minor = element_blank())
man_complex <-
manova(cbind(V1,V2,V3,V4,V5,V6,V7,V8,V9,V10) ~ REP + GEN,
data = df_g)
# Chunk 1: global_options
knitr::opts_chunk$set(cache = TRUE, comment = "##", collapse = TRUE)
# Chunk 2
library(metan)      # MGIDI index
library(rio)        # data importation
library(broom)      # convert statistical objects into tidy tibbles
library(purrr)      # Manipulate lists
library(tidyverse)  # plots, data manipulation
library(kableExtra) # html tables
library(emmeans)    # pairwise multiple comparison
library(AgroR)     # pairwise multiple comparison
library(factoextra)
# set a theme plot
my_theme <-
theme_bw() +
theme(legend.title = element_blank(),
axis.title = element_text(color = "black"),
axis.text = element_text(color = "black"),
panel.grid.minor = element_blank())
# Chunk 3
df <-
g_simula(ngen = 5,
nrep = 3,
nvars = 3,
seed = c(3, 20, 40)) %>%
replace_string(GEN, pattern =  "H", replacement = "T")
# Chunk 4
v1_mod <- aov(V1 ~ REP + GEN, data = df)
v2_mod <- aov(V2 ~ REP + GEN, data = df)
v3_mod <- aov(V3 ~ REP + GEN, data = df)
anovas <-
list(v1 = tidy(v1_mod),
v2 = tidy(v2_mod),
v3 = tidy(v3_mod)) %>%
rbind_fill_id(.id = "Traits")
anovas
v1_means <- emmeans(v1_mod, ~ GEN)
v2_means <- emmeans(v2_mod, ~ GEN)
v3_means <- emmeans(v3_mod, ~ GEN)
# plots
p1 <-
plot(v1_means,
comparisons = TRUE,
CIs = FALSE,
xlab = "Mean",
ylab = "Treatments") +
geom_vline(xintercept = mean(df$V1)) +
my_theme
p2 <-
plot(v2_means,
comparisons = TRUE,
CIs = FALSE,
xlab = "Mean",
ylab = "Treatments") +
geom_vline(xintercept = mean(df$V2)) +
my_theme
p3 <-
plot(v3_means,
comparisons = TRUE,
CIs = FALSE,
xlab = "Mean",
ylab = "Treatments") +
geom_vline(xintercept = mean(df$V2)) +
my_theme
# Chunk 5
man <- manova(cbind(V1, V2, V3) ~ REP + GEN, data = df)
summary(man)
# predict the mean values
# compute a two-way table with genotypes in rows and traits in columns
pred_mat <-
predict(man) %>%
as.data.frame() %>%
mutate(TRAT = df$GEN) %>%
mean_by(TRAT) %>%
column_to_rownames("TRAT")
# higher values for all traits are better
ind <- mgidi(pred_mat,
ideotype = c("h, h, h"), # default
verbose = FALSE,
mineval = 0.5) # retains two factors
p4 <-
plot(ind,
x.lab = "Treatments",
y.lab = "MGIDI index",
radar = FALSE) +
my_theme
ind$sel_dif
# lower values for the first two traits
# higher values for the last
ind2 <- mgidi(pred_mat,
ideotype = c("l, l, h"),
verbose = FALSE,
mineval = 0.5) # retains two factors
p5 <-
plot(ind2,
x.lab = "Treatments",
y.lab = "MGIDI index",
radar = FALSE) +
my_theme
ind2$sel_dif
# lower values for all the traits
ind3 <- mgidi(pred_mat,
ideotype =  c("l, l, l"),
verbose = FALSE,
mineval = 0.5) # retains two factors
p6 <-
plot(ind3,
x.lab = "Treatments",
y.lab = "MGIDI index",
radar = FALSE) +
my_theme
ind3$sel_dif
# Chunk 6
arrange_ggplot((p1 + p2 + p3),
(p4 + p5 + p6),
nrow = 2,
heights = c(0.6, 1),
tag_levels = "a",
guides = "collect")
ggsave("figs/fig1.pdf", width = 10, height = 5)
# Chunk 7
# simulate data
df_g <-
g_simula(ngen = 75,
nrep = 3,
nvars = 10,
seed = 1:10)
# data in a 'long' format
df_ge_long <-
pivot_longer(df_g,
cols = -c(GEN:REP),
names_to = "trait")
# compute an ANOVA for each trait
models_ge <-
df_ge_long %>%
group_by(trait) %>%
doo(~aov(value ~ REP + GEN, data = .))
# obtain an anova table
anovas_ge <- models_ge$data %>% map_dfr(~.x %>% tidy(), .id = "TRAIT")
anovas_ge %>% filter(term == "GEN")
# Chunk 8
# example for V1
model_v1 <- models_ge$data[[1]]
means_v1 <- emmeans(model_v1, ~ GEN)
pairs <- pwpm(means_v1)
# Chunk 9
p7 <-
plot(means_v1, comparisons = TRUE, CIs = FALSE) +
my_theme
p7
# Chunk 10
# shows only 'significant' (P-value < 0.05)
p8 <- pwpp(means_v1) + scale_x_continuous(limits = c(0, 0.05))
p8
# Chunk 11
plot <-
with(df_g,
DBC(GEN, REP, V1))
df_plot <-
mat_g |>
rownames_to_column("TRAT") |>
mutate(selected = ifelse(TRAT %in% ind4$sel_gen, "Yes", "No")) |>
pivot_longer(V1:V10)
man_complex <-
manova(cbind(V1,V2,V3,V4,V5,V6,V7,V8,V9,V10) ~ REP + GEN,
data = df_g)
summary(man_complex)
# generate a two-way table with predicted values in rows and traits in columns
pred_complex <- cbind(df_g[, 1:2], predict(man_complex))
mat_g <-
pred_complex %>%
mean_by(GEN) %>%
column_to_rownames("GEN")
# higher values for all traits are better
ind4 <- mgidi(mat_g,
ideotype = rep("h", 10), # default
verbose = FALSE)
p9 <- plot(ind4)
p9
ind4$sel_dif
# higher values desired for the first 7 traits
# lower values desired for the last 3 traits
ind5 <- mgidi(mat_g,
ideotype = c(rep("h", 7), rep("l", 3)),
verbose = FALSE)
p10 <- plot(ind5)
p10
ind5$sel_dif
# lower values for all the traits
ind6 <- mgidi(mat_g,
ideotype =  rep("l", 10), # default
verbose = FALSE)
p11 <- plot(ind6)
p11
ind6$sel_dif
df_plot <-
mat_g |>
rownames_to_column("TRAT") |>
mutate(selected = ifelse(TRAT %in% ind4$sel_gen, "Yes", "No")) |>
pivot_longer(V1:V10)
df_mean <-
df_plot |>
mean_by(name)
df_mean
df_plot
df_plot <-
mat_g |>
rownames_to_column("TRAT") |>
# mutate(selected = ifelse(TRAT %in% ind4$sel_gen, "Yes", "No")) |>
pivot_longer(V1:V10)
df_plot
ge_plot(TRAT, name, value)
ge_plot(df_plot, TRAT, name, value)
ge_plot
ge_plot(df_plot, name, TRAT, value)
ge_plot(df_plot, name, TRAT, value, values = FALSE)
ge_plot(df_plot, TRAT, name, value, values = FALSE)
ind4$MGIDI
mgidi_cul_ori <-
mgidi(df_ori_cul,                 # a two-way table
ideotype = ideotype_vector, # ideotype vector
weights = weight,           # weigth vector
SI = 50)                    # select two treatments
# compute a two-wat table with means by origin and cultivar
df_ori_cul <-
pred_vals %>%
mean_by(ORI, CUL) %>%
concatenate(ORI, CUL, new_var = TRAT, .after = CUL) %>%
remove_cols(ORI, CUL) %>%
round_cols() %>%
column_to_rownames("TRAT")
# get the predicted values
pred_vals <- cbind(df[,1:4], predict(man_straw))
# compute a two-wat table with means by origin and cultivar
df_ori_cul <-
pred_vals %>%
mean_by(ORI, CUL) %>%
concatenate(ORI, CUL, new_var = TRAT, .after = CUL) %>%
remove_cols(ORI, CUL) %>%
round_cols() %>%
column_to_rownames("TRAT")
# get the predicted values
pred_vals <- cbind(df[,1:4], predict(man_straw))
man_straw <-
manova(
cbind(NNCF,WNCF,AWNCF,WUE,NDBF,NDFF,NDBH,PHYL,TA,NCF,TNF
,WCF, TWF,AWCF,OAWF,FY,TSS,TSS_TA,FIRM,L,CHROMA,H) ~ SUB*ORI*CUL,
data = df)
rm(list = ls())
df <-
import("https://bit.ly/strawberry_data", setclass = "tbl") %>%
metan::as_factor(1:4)
str(df)
man_straw <-
manova(
cbind(NNCF,WNCF,AWNCF,WUE,NDBF,NDFF,NDBH,PHYL,TA,NCF,TNF
,WCF, TWF,AWCF,OAWF,FY,TSS,TSS_TA,FIRM,L,CHROMA,H) ~ SUB*ORI*CUL,
data = df)
tidy(man_straw, intercept =  TRUE)
# get the predicted values
pred_vals <- cbind(df[,1:4], predict(man_straw))
# compute a two-wat table with means by origin and cultivar
df_ori_cul <-
pred_vals %>%
mean_by(ORI, CUL) %>%
concatenate(ORI, CUL, new_var = TRAT, .after = CUL) %>%
remove_cols(ORI, CUL) %>%
round_cols() %>%
column_to_rownames("TRAT")
df_ori_cul
(ideotype_vector <- c(rep("l", 9), rep("h", 13)))
(weight <-  c(rep(1, 9), 4, 1, 4, rep(1, 10)))
mgidi_cul_ori <-
mgidi(df_ori_cul,                 # a two-way table
ideotype = ideotype_vector, # ideotype vector
weights = weight,           # weigth vector
SI = 50)                    # select two treatments
View(mgidi_cul_ori)
View(mgidi_cul_ori[["FA"]])
View(mgidi_cul_ori[["sel_dif"]])
View(mgidi_cul_ori[["FA"]])
View(mgidi_cul_ori[["PCA"]])
View(df_ori_cul)
