The LSDlabels
function is used for calculating the LSD
values for the pairwise comparisons from the ASReml-R
model.
LSDlabels <- function(P, alpha) {
a <- P
diag(a) <- 1
b <- which(a > alpha, arr.ind = TRUE)
top <- data.frame(N1 = b[, 1], N2 = b[, 2])
g3 <- igraph::simplify(igraph::graph.data.frame(top[order(top[[1]]), ], directed = FALSE))
cliq <- igraph::maximal.cliques(g3)
nn <- length(cliq)
temp1 <- rep("", nrow(a))
assignment <- c(letters, LETTERS, paste(letters, '.', sep = ''), paste(LETTERS, '.', sep = ''))
cliq2 <- list()
for (j in 1:nn) {
cliq2[[j]] <- colnames(a)[cliq[[j]]]
}
for (ind in 1:nrow(a)) {
tt <- which(sapply(1:length(cliq2), function(x) colnames(a)[ind] %in% cliq2[[x]]) == TRUE)
temp1[ind] <- paste0(assignment[tt], collapse = "")
}
return(temp1)
}
We fit the ASReml model and calculate the pairwise differences.
# Load data
data(oats)
# Fit the ASReml model
oats.asr <- asreml(yield ~ Variety * Nitrogen, random = ~ Blocks / Wplots, data = oats)
# Perform ASReml tests
mod.asrt <- as.asrtests(oats.asr, NULL, NULL)
# Predict and calculate pairwise differences
diffs <- predictPlus(classify = "Variety*Nitrogen",
asreml.obj = oats.asr,
wald.tab = mod.asrt$wald.tab,
pairwise = TRUE)
##
##
## #### Predictions for yield from Variety:Nitrogen
##
##
## Notes:
## - The predictions are obtained by averaging across the hypertable
## calculated from model terms constructed solely from factors in
## the averaging and classify sets.
## - Use 'average' to move ignored factors into the averaging set.
## - The ignored set: Blocks,Wplots
##
## Variety Nitrogen predicted.value standard.error upper.Confidence.limit
## 1 Golden_rain 0_cwt 80.00000 9.106977 98.34239
## 2 Golden_rain 0.2_cwt 98.50000 9.106977 116.84239
## 3 Golden_rain 0.4_cwt 114.66667 9.106977 133.00906
## 4 Golden_rain 0.6_cwt 124.83333 9.106977 143.17573
## 5 Marvellous 0_cwt 86.66667 9.106977 105.00906
## 6 Marvellous 0.2_cwt 108.50000 9.106977 126.84239
## 7 Marvellous 0.4_cwt 117.16667 9.106977 135.50906
## 8 Marvellous 0.6_cwt 126.83333 9.106977 145.17573
## 9 Victory 0_cwt 71.50000 9.106977 89.84239
## 10 Victory 0.2_cwt 89.66667 9.106977 108.00906
## 11 Victory 0.4_cwt 110.83333 9.106977 129.17573
## 12 Victory 0.6_cwt 118.50000 9.106977 136.84239
## lower.Confidence.limit est.status
## 1 61.65761 Estimable
## 2 80.15761 Estimable
## 3 96.32427 Estimable
## 4 106.49094 Estimable
## 5 68.32427 Estimable
## 6 90.15761 Estimable
## 7 98.82427 Estimable
## 8 108.49094 Estimable
## 9 53.15761 Estimable
## 10 71.32427 Estimable
## 11 92.49094 Estimable
## 12 100.15761 Estimable
##
##
## LSD values
##
## minimum LSD = 15.47426
##
## mean LSD = 18.54066
##
## maximum LSD = 19.56707
##
## (sed range / mean sed = 0.221 )
##
##
##
## Variance matrix of the predicted values
##
## NULL
##
##
## All pairwise differences between predicted values
##
## Golden_rain,0_cwt Golden_rain,0.2_cwt Golden_rain,0.4_cwt
## Golden_rain,0_cwt 0.000 -18.500 -34.667
## Golden_rain,0.2_cwt 18.500 0.000 -16.167
## Golden_rain,0.4_cwt 34.667 16.167 0.000
## Golden_rain,0.6_cwt 44.833 26.333 10.167
## Marvellous,0_cwt 6.667 -11.833 -28.000
## Marvellous,0.2_cwt 28.500 10.000 -6.167
## Marvellous,0.4_cwt 37.167 18.667 2.500
## Marvellous,0.6_cwt 46.833 28.333 12.167
## Victory,0_cwt -8.500 -27.000 -43.167
## Victory,0.2_cwt 9.667 -8.833 -25.000
## Victory,0.4_cwt 30.833 12.333 -3.833
## Victory,0.6_cwt 38.500 20.000 3.833
## Golden_rain,0.6_cwt Marvellous,0_cwt Marvellous,0.2_cwt
## Golden_rain,0_cwt -44.833 -6.667 -28.500
## Golden_rain,0.2_cwt -26.333 11.833 -10.000
## Golden_rain,0.4_cwt -10.167 28.000 6.167
## Golden_rain,0.6_cwt 0.000 38.167 16.333
## Marvellous,0_cwt -38.167 0.000 -21.833
## Marvellous,0.2_cwt -16.333 21.833 0.000
## Marvellous,0.4_cwt -7.667 30.500 8.667
## Marvellous,0.6_cwt 2.000 40.167 18.333
## Victory,0_cwt -53.333 -15.167 -37.000
## Victory,0.2_cwt -35.167 3.000 -18.833
## Victory,0.4_cwt -14.000 24.167 2.333
## Victory,0.6_cwt -6.333 31.833 10.000
## Marvellous,0.4_cwt Marvellous,0.6_cwt Victory,0_cwt
## Golden_rain,0_cwt -37.167 -46.833 8.50
## Golden_rain,0.2_cwt -18.667 -28.333 27.00
## Golden_rain,0.4_cwt -2.500 -12.167 43.17
## Golden_rain,0.6_cwt 7.667 -2.000 53.33
## Marvellous,0_cwt -30.500 -40.167 15.17
## Marvellous,0.2_cwt -8.667 -18.333 37.00
## Marvellous,0.4_cwt 0.000 -9.667 45.67
## Marvellous,0.6_cwt 9.667 0.000 55.33
## Victory,0_cwt -45.667 -55.333 0.00
## Victory,0.2_cwt -27.500 -37.167 18.17
## Victory,0.4_cwt -6.333 -16.000 39.33
## Victory,0.6_cwt 1.333 -8.333 47.00
## Victory,0.2_cwt Victory,0.4_cwt Victory,0.6_cwt
## Golden_rain,0_cwt -9.667 -30.833 -38.500
## Golden_rain,0.2_cwt 8.833 -12.333 -20.000
## Golden_rain,0.4_cwt 25.000 3.833 -3.833
## Golden_rain,0.6_cwt 35.167 14.000 6.333
## Marvellous,0_cwt -3.000 -24.167 -31.833
## Marvellous,0.2_cwt 18.833 -2.333 -10.000
## Marvellous,0.4_cwt 27.500 6.333 -1.333
## Marvellous,0.6_cwt 37.167 16.000 8.333
## Victory,0_cwt -18.167 -39.333 -47.000
## Victory,0.2_cwt 0.000 -21.167 -28.833
## Victory,0.4_cwt 21.167 0.000 -7.667
## Victory,0.6_cwt 28.833 7.667 0.000
##
##
## p values for all pairwise differences between predicted values
##
## Golden_rain,0_cwt Golden_rain,0.2_cwt Golden_rain,0.4_cwt
## Golden_rain,0_cwt 0.020 0.000
## Golden_rain,0.2_cwt 0.020 0.041
## Golden_rain,0.4_cwt 0.000 0.041
## Golden_rain,0.6_cwt 0.000 0.001 0.192
## Marvellous,0_cwt 0.496 0.230 0.006
## Marvellous,0.2_cwt 0.005 0.309 0.529
## Marvellous,0.4_cwt 0.000 0.061 0.798
## Marvellous,0.6_cwt 0.000 0.006 0.217
## Victory,0_cwt 0.386 0.008 0.000
## Victory,0.2_cwt 0.325 0.368 0.013
## Victory,0.4_cwt 0.003 0.211 0.695
## Victory,0.6_cwt 0.000 0.045 0.695
## Golden_rain,0.6_cwt Marvellous,0_cwt Marvellous,0.2_cwt
## Golden_rain,0_cwt 0.000 0.496 0.005
## Golden_rain,0.2_cwt 0.001 0.230 0.309
## Golden_rain,0.4_cwt 0.192 0.006 0.529
## Golden_rain,0.6_cwt 0.000 0.100
## Marvellous,0_cwt 0.000 0.007
## Marvellous,0.2_cwt 0.100 0.007
## Marvellous,0.4_cwt 0.434 0.000 0.265
## Marvellous,0.6_cwt 0.838 0.000 0.021
## Victory,0_cwt 0.000 0.125 0.000
## Victory,0.2_cwt 0.001 0.759 0.059
## Victory,0.4_cwt 0.156 0.017 0.811
## Victory,0.6_cwt 0.518 0.002 0.309
## Marvellous,0.4_cwt Marvellous,0.6_cwt Victory,0_cwt
## Golden_rain,0_cwt 0.000 0.000 0.386
## Golden_rain,0.2_cwt 0.061 0.006 0.008
## Golden_rain,0.4_cwt 0.798 0.217 0.000
## Golden_rain,0.6_cwt 0.434 0.838 0.000
## Marvellous,0_cwt 0.000 0.000 0.125
## Marvellous,0.2_cwt 0.265 0.021 0.000
## Marvellous,0.4_cwt 0.215 0.000
## Marvellous,0.6_cwt 0.215 0.000
## Victory,0_cwt 0.000 0.000
## Victory,0.2_cwt 0.007 0.000 0.022
## Victory,0.4_cwt 0.518 0.107 0.000
## Victory,0.6_cwt 0.891 0.396 0.000
## Victory,0.2_cwt Victory,0.4_cwt Victory,0.6_cwt
## Golden_rain,0_cwt 0.325 0.003 0.000
## Golden_rain,0.2_cwt 0.368 0.211 0.045
## Golden_rain,0.4_cwt 0.013 0.695 0.695
## Golden_rain,0.6_cwt 0.001 0.156 0.518
## Marvellous,0_cwt 0.759 0.017 0.002
## Marvellous,0.2_cwt 0.059 0.811 0.309
## Marvellous,0.4_cwt 0.007 0.518 0.891
## Marvellous,0.6_cwt 0.000 0.107 0.396
## Victory,0_cwt 0.022 0.000 0.000
## Victory,0.2_cwt 0.008 0.000
## Victory,0.4_cwt 0.008 0.324
## Victory,0.6_cwt 0.000 0.324
##
##
## Standard errors of differences between predicted values
##
## Golden_rain,0_cwt Golden_rain,0.2_cwt Golden_rain,0.4_cwt
## Golden_rain,0_cwt 7.683 7.683
## Golden_rain,0.2_cwt 7.683 7.683
## Golden_rain,0.4_cwt 7.683 7.683
## Golden_rain,0.6_cwt 7.683 7.683 7.683
## Marvellous,0_cwt 9.715 9.715 9.715
## Marvellous,0.2_cwt 9.715 9.715 9.715
## Marvellous,0.4_cwt 9.715 9.715 9.715
## Marvellous,0.6_cwt 9.715 9.715 9.715
## Victory,0_cwt 9.715 9.715 9.715
## Victory,0.2_cwt 9.715 9.715 9.715
## Victory,0.4_cwt 9.715 9.715 9.715
## Victory,0.6_cwt 9.715 9.715 9.715
## Golden_rain,0.6_cwt Marvellous,0_cwt Marvellous,0.2_cwt
## Golden_rain,0_cwt 7.683 9.715 9.715
## Golden_rain,0.2_cwt 7.683 9.715 9.715
## Golden_rain,0.4_cwt 7.683 9.715 9.715
## Golden_rain,0.6_cwt 9.715 9.715
## Marvellous,0_cwt 9.715 7.683
## Marvellous,0.2_cwt 9.715 7.683
## Marvellous,0.4_cwt 9.715 7.683 7.683
## Marvellous,0.6_cwt 9.715 7.683 7.683
## Victory,0_cwt 9.715 9.715 9.715
## Victory,0.2_cwt 9.715 9.715 9.715
## Victory,0.4_cwt 9.715 9.715 9.715
## Victory,0.6_cwt 9.715 9.715 9.715
## Marvellous,0.4_cwt Marvellous,0.6_cwt Victory,0_cwt
## Golden_rain,0_cwt 9.715 9.715 9.715
## Golden_rain,0.2_cwt 9.715 9.715 9.715
## Golden_rain,0.4_cwt 9.715 9.715 9.715
## Golden_rain,0.6_cwt 9.715 9.715 9.715
## Marvellous,0_cwt 7.683 7.683 9.715
## Marvellous,0.2_cwt 7.683 7.683 9.715
## Marvellous,0.4_cwt 7.683 9.715
## Marvellous,0.6_cwt 7.683 9.715
## Victory,0_cwt 9.715 9.715
## Victory,0.2_cwt 9.715 9.715 7.683
## Victory,0.4_cwt 9.715 9.715 7.683
## Victory,0.6_cwt 9.715 9.715 7.683
## Victory,0.2_cwt Victory,0.4_cwt Victory,0.6_cwt
## Golden_rain,0_cwt 9.715 9.715 9.715
## Golden_rain,0.2_cwt 9.715 9.715 9.715
## Golden_rain,0.4_cwt 9.715 9.715 9.715
## Golden_rain,0.6_cwt 9.715 9.715 9.715
## Marvellous,0_cwt 9.715 9.715 9.715
## Marvellous,0.2_cwt 9.715 9.715 9.715
## Marvellous,0.4_cwt 9.715 9.715 9.715
## Marvellous,0.6_cwt 9.715 9.715 9.715
## Victory,0_cwt 7.683 7.683 7.683
## Victory,0.2_cwt 7.683 7.683
## Victory,0.4_cwt 7.683 7.683
## Victory,0.6_cwt 7.683 7.683
# Calculate LSD at p = 0.05 level
diffs$predictions$LSD <- LSDlabels(diffs$p.differences, 0.05)
We use ggplot2
to visualize the predicted values with
LSD labels.
g1 <- ggplot(data = diffs$predictions, aes(Variety, predicted.value, fill = Nitrogen)) +
geom_bar(stat = "identity", position = position_dodge()) +
geom_text(aes(Variety, predicted.value, label = round(predicted.value, 2)),
vjust = -0.5, size = 5, position = position_dodge(0.9)) +
geom_text(aes(label = LSD), vjust = 1.6, size = 5, position = position_dodge(0.9)) +
ylim(0, 135) +
scale_fill_brewer(palette = "Paired") +
ggtitle("Using LSDlabels function for LSD") +
theme_bw() +
theme(text = element_text(size = 15), legend.position = "bottom")
g1
agricolae
PackageWe demonstrate an equivalent method using the agricolae
package.
pred <- predictPlus.asreml(oats.asr,
classify = "Variety*Nitrogen",
wald.tab = as.data.frame(wald(oats.asr)),
pairwise = TRUE)
##
##
## #### Predictions for yield from Variety:Nitrogen
##
##
## Notes:
## - The predictions are obtained by averaging across the hypertable
## calculated from model terms constructed solely from factors in
## the averaging and classify sets.
## - Use 'average' to move ignored factors into the averaging set.
## - The ignored set: Blocks,Wplots
##
## Variety Nitrogen predicted.value standard.error upper.Confidence.limit
## 1 Golden_rain 0_cwt 80.00000 9.106977 98.21667
## 2 Golden_rain 0.2_cwt 98.50000 9.106977 116.71667
## 3 Golden_rain 0.4_cwt 114.66667 9.106977 132.88333
## 4 Golden_rain 0.6_cwt 124.83333 9.106977 143.05000
## 5 Marvellous 0_cwt 86.66667 9.106977 104.88333
## 6 Marvellous 0.2_cwt 108.50000 9.106977 126.71667
## 7 Marvellous 0.4_cwt 117.16667 9.106977 135.38333
## 8 Marvellous 0.6_cwt 126.83333 9.106977 145.05000
## 9 Victory 0_cwt 71.50000 9.106977 89.71667
## 10 Victory 0.2_cwt 89.66667 9.106977 107.88333
## 11 Victory 0.4_cwt 110.83333 9.106977 129.05000
## 12 Victory 0.6_cwt 118.50000 9.106977 136.71667
## lower.Confidence.limit est.status
## 1 61.78333 Estimable
## 2 80.28333 Estimable
## 3 96.45000 Estimable
## 4 106.61667 Estimable
## 5 68.45000 Estimable
## 6 90.28333 Estimable
## 7 98.95000 Estimable
## 8 108.61667 Estimable
## 9 53.28333 Estimable
## 10 71.45000 Estimable
## 11 92.61667 Estimable
## 12 100.28333 Estimable
##
##
## LSD values
##
## minimum LSD = 15.3682
##
## mean LSD = 18.41358
##
## maximum LSD = 19.43294
##
## (sed range / mean sed = 0.221 )
##
##
##
## Variance matrix of the predicted values
##
## NULL
##
##
## All pairwise differences between predicted values
##
## Golden_rain,0_cwt Golden_rain,0.2_cwt Golden_rain,0.4_cwt
## Golden_rain,0_cwt 0.000 -18.500 -34.667
## Golden_rain,0.2_cwt 18.500 0.000 -16.167
## Golden_rain,0.4_cwt 34.667 16.167 0.000
## Golden_rain,0.6_cwt 44.833 26.333 10.167
## Marvellous,0_cwt 6.667 -11.833 -28.000
## Marvellous,0.2_cwt 28.500 10.000 -6.167
## Marvellous,0.4_cwt 37.167 18.667 2.500
## Marvellous,0.6_cwt 46.833 28.333 12.167
## Victory,0_cwt -8.500 -27.000 -43.167
## Victory,0.2_cwt 9.667 -8.833 -25.000
## Victory,0.4_cwt 30.833 12.333 -3.833
## Victory,0.6_cwt 38.500 20.000 3.833
## Golden_rain,0.6_cwt Marvellous,0_cwt Marvellous,0.2_cwt
## Golden_rain,0_cwt -44.833 -6.667 -28.500
## Golden_rain,0.2_cwt -26.333 11.833 -10.000
## Golden_rain,0.4_cwt -10.167 28.000 6.167
## Golden_rain,0.6_cwt 0.000 38.167 16.333
## Marvellous,0_cwt -38.167 0.000 -21.833
## Marvellous,0.2_cwt -16.333 21.833 0.000
## Marvellous,0.4_cwt -7.667 30.500 8.667
## Marvellous,0.6_cwt 2.000 40.167 18.333
## Victory,0_cwt -53.333 -15.167 -37.000
## Victory,0.2_cwt -35.167 3.000 -18.833
## Victory,0.4_cwt -14.000 24.167 2.333
## Victory,0.6_cwt -6.333 31.833 10.000
## Marvellous,0.4_cwt Marvellous,0.6_cwt Victory,0_cwt
## Golden_rain,0_cwt -37.167 -46.833 8.50
## Golden_rain,0.2_cwt -18.667 -28.333 27.00
## Golden_rain,0.4_cwt -2.500 -12.167 43.17
## Golden_rain,0.6_cwt 7.667 -2.000 53.33
## Marvellous,0_cwt -30.500 -40.167 15.17
## Marvellous,0.2_cwt -8.667 -18.333 37.00
## Marvellous,0.4_cwt 0.000 -9.667 45.67
## Marvellous,0.6_cwt 9.667 0.000 55.33
## Victory,0_cwt -45.667 -55.333 0.00
## Victory,0.2_cwt -27.500 -37.167 18.17
## Victory,0.4_cwt -6.333 -16.000 39.33
## Victory,0.6_cwt 1.333 -8.333 47.00
## Victory,0.2_cwt Victory,0.4_cwt Victory,0.6_cwt
## Golden_rain,0_cwt -9.667 -30.833 -38.500
## Golden_rain,0.2_cwt 8.833 -12.333 -20.000
## Golden_rain,0.4_cwt 25.000 3.833 -3.833
## Golden_rain,0.6_cwt 35.167 14.000 6.333
## Marvellous,0_cwt -3.000 -24.167 -31.833
## Marvellous,0.2_cwt 18.833 -2.333 -10.000
## Marvellous,0.4_cwt 27.500 6.333 -1.333
## Marvellous,0.6_cwt 37.167 16.000 8.333
## Victory,0_cwt -18.167 -39.333 -47.000
## Victory,0.2_cwt 0.000 -21.167 -28.833
## Victory,0.4_cwt 21.167 0.000 -7.667
## Victory,0.6_cwt 28.833 7.667 0.000
##
##
## p values for all pairwise differences between predicted values
##
## Golden_rain,0_cwt Golden_rain,0.2_cwt Golden_rain,0.4_cwt
## Golden_rain,0_cwt 0.019 0.000
## Golden_rain,0.2_cwt 0.019 0.040
## Golden_rain,0.4_cwt 0.000 0.040
## Golden_rain,0.6_cwt 0.000 0.001 0.191
## Marvellous,0_cwt 0.495 0.228 0.005
## Marvellous,0.2_cwt 0.005 0.307 0.528
## Marvellous,0.4_cwt 0.000 0.059 0.798
## Marvellous,0.6_cwt 0.000 0.005 0.215
## Victory,0_cwt 0.385 0.007 0.000
## Victory,0.2_cwt 0.324 0.367 0.013
## Victory,0.4_cwt 0.002 0.209 0.695
## Victory,0.6_cwt 0.000 0.044 0.695
## Golden_rain,0.6_cwt Marvellous,0_cwt Marvellous,0.2_cwt
## Golden_rain,0_cwt 0.000 0.495 0.005
## Golden_rain,0.2_cwt 0.001 0.228 0.307
## Golden_rain,0.4_cwt 0.191 0.005 0.528
## Golden_rain,0.6_cwt 0.000 0.098
## Marvellous,0_cwt 0.000 0.006
## Marvellous,0.2_cwt 0.098 0.006
## Marvellous,0.4_cwt 0.433 0.000 0.264
## Marvellous,0.6_cwt 0.838 0.000 0.020
## Victory,0_cwt 0.000 0.124 0.000
## Victory,0.2_cwt 0.001 0.759 0.057
## Victory,0.4_cwt 0.155 0.016 0.811
## Victory,0.6_cwt 0.517 0.002 0.307
## Marvellous,0.4_cwt Marvellous,0.6_cwt Victory,0_cwt
## Golden_rain,0_cwt 0.000 0.000 0.385
## Golden_rain,0.2_cwt 0.059 0.005 0.007
## Golden_rain,0.4_cwt 0.798 0.215 0.000
## Golden_rain,0.6_cwt 0.433 0.838 0.000
## Marvellous,0_cwt 0.000 0.000 0.124
## Marvellous,0.2_cwt 0.264 0.020 0.000
## Marvellous,0.4_cwt 0.213 0.000
## Marvellous,0.6_cwt 0.213 0.000
## Victory,0_cwt 0.000 0.000
## Victory,0.2_cwt 0.006 0.000 0.021
## Victory,0.4_cwt 0.517 0.105 0.000
## Victory,0.6_cwt 0.891 0.394 0.000
## Victory,0.2_cwt Victory,0.4_cwt Victory,0.6_cwt
## Golden_rain,0_cwt 0.324 0.002 0.000
## Golden_rain,0.2_cwt 0.367 0.209 0.044
## Golden_rain,0.4_cwt 0.013 0.695 0.695
## Golden_rain,0.6_cwt 0.001 0.155 0.517
## Marvellous,0_cwt 0.759 0.016 0.002
## Marvellous,0.2_cwt 0.057 0.811 0.307
## Marvellous,0.4_cwt 0.006 0.517 0.891
## Marvellous,0.6_cwt 0.000 0.105 0.394
## Victory,0_cwt 0.021 0.000 0.000
## Victory,0.2_cwt 0.008 0.000
## Victory,0.4_cwt 0.008 0.322
## Victory,0.6_cwt 0.000 0.322
##
##
## Standard errors of differences between predicted values
##
## Golden_rain,0_cwt Golden_rain,0.2_cwt Golden_rain,0.4_cwt
## Golden_rain,0_cwt 7.683 7.683
## Golden_rain,0.2_cwt 7.683 7.683
## Golden_rain,0.4_cwt 7.683 7.683
## Golden_rain,0.6_cwt 7.683 7.683 7.683
## Marvellous,0_cwt 9.715 9.715 9.715
## Marvellous,0.2_cwt 9.715 9.715 9.715
## Marvellous,0.4_cwt 9.715 9.715 9.715
## Marvellous,0.6_cwt 9.715 9.715 9.715
## Victory,0_cwt 9.715 9.715 9.715
## Victory,0.2_cwt 9.715 9.715 9.715
## Victory,0.4_cwt 9.715 9.715 9.715
## Victory,0.6_cwt 9.715 9.715 9.715
## Golden_rain,0.6_cwt Marvellous,0_cwt Marvellous,0.2_cwt
## Golden_rain,0_cwt 7.683 9.715 9.715
## Golden_rain,0.2_cwt 7.683 9.715 9.715
## Golden_rain,0.4_cwt 7.683 9.715 9.715
## Golden_rain,0.6_cwt 9.715 9.715
## Marvellous,0_cwt 9.715 7.683
## Marvellous,0.2_cwt 9.715 7.683
## Marvellous,0.4_cwt 9.715 7.683 7.683
## Marvellous,0.6_cwt 9.715 7.683 7.683
## Victory,0_cwt 9.715 9.715 9.715
## Victory,0.2_cwt 9.715 9.715 9.715
## Victory,0.4_cwt 9.715 9.715 9.715
## Victory,0.6_cwt 9.715 9.715 9.715
## Marvellous,0.4_cwt Marvellous,0.6_cwt Victory,0_cwt
## Golden_rain,0_cwt 9.715 9.715 9.715
## Golden_rain,0.2_cwt 9.715 9.715 9.715
## Golden_rain,0.4_cwt 9.715 9.715 9.715
## Golden_rain,0.6_cwt 9.715 9.715 9.715
## Marvellous,0_cwt 7.683 7.683 9.715
## Marvellous,0.2_cwt 7.683 7.683 9.715
## Marvellous,0.4_cwt 7.683 9.715
## Marvellous,0.6_cwt 7.683 9.715
## Victory,0_cwt 9.715 9.715
## Victory,0.2_cwt 9.715 9.715 7.683
## Victory,0.4_cwt 9.715 9.715 7.683
## Victory,0.6_cwt 9.715 9.715 7.683
## Victory,0.2_cwt Victory,0.4_cwt Victory,0.6_cwt
## Golden_rain,0_cwt 9.715 9.715 9.715
## Golden_rain,0.2_cwt 9.715 9.715 9.715
## Golden_rain,0.4_cwt 9.715 9.715 9.715
## Golden_rain,0.6_cwt 9.715 9.715 9.715
## Marvellous,0_cwt 9.715 9.715 9.715
## Marvellous,0.2_cwt 9.715 9.715 9.715
## Marvellous,0.4_cwt 9.715 9.715 9.715
## Marvellous,0.6_cwt 9.715 9.715 9.715
## Victory,0_cwt 7.683 7.683 7.683
## Victory,0.2_cwt 7.683 7.683
## Victory,0.4_cwt 7.683 7.683
## Victory,0.6_cwt 7.683 7.683
# Prepare data for agricolae
std.error <- pred$predictions$standard.error
prob.matrix <- ifelse(is.na(pred$p.differences), 1, pred$p.differences)
treatments <- colnames(prob.matrix)
means <- pred$predictions$predicted.value
alpha <- 0.05
# Calculate LSD means table using agricolae
lsdmeantab <- orderPvalue(treatments, means, alpha, prob.matrix, console = TRUE)
lsdmeantab$Treatment <- rownames(lsdmeantab)
# Split Treatment column into Variety and Nitrogen
lsdmeantab <- lsdmeantab %>%
separate(Treatment, into = c("Variety", "Nitrogen"), sep = ",")
# Plot the results using ggplot2
g2 <- ggplot(data = lsdmeantab, aes(Variety, means, fill = Nitrogen)) +
geom_bar(stat = "identity", position = position_dodge()) +
geom_text(aes(Variety, means, label = round(means, 2)),
vjust = -0.5, size = 5, position = position_dodge(0.9)) +
geom_text(aes(label = groups), vjust = 1.6, size = 5, position = position_dodge(0.9)) +
ylim(0, 135) +
scale_fill_brewer(palette = "Paired") +
ggtitle("Using agricolae for LSD") +
theme_bw() +
theme(text = element_text(size = 15), legend.position = "bottom")
g2
This document demonstrates two equivalent methods for generating
plots with LSD labels of ASReml-R
models. The first method
uses the LSDlabels
function, while the second method
utilises the agricolae
package. Both methods produce same
results, allowing users to choose the approach that best suits their
needs.
grid.arrange(g1, g2, ncol = 2)