Description Usage Arguments Value Author(s) See Also Examples
This function order the letters in the compact letter
display to the highest estimate receive the letter a
. This
is a convetion in most software for analysis of experiments.
1 | ordered_cld(let, means = let)
|
let |
Character vector with the letters returned by
|
means |
Numeric vector with the corresponding estimates in which
the highest value will have the letter |
A character vector with the letters rearranged.
Walmes Zeviani, walmes@ufpr.r.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | # Toy data.
set.seed(4321)
td <- data.frame(trt = rep(sample(1:8), each = 5))
td$y <- rnorm(nrow(td), mean = sort(td$trt), sd = 2)
plot(y ~ trt, data = td)
# Fit the model.
td$trt <- factor(td$trt)
m0 <- lm(y ~ trt, data = td)
anova(m0)
summary(m0)
library(multcomp)
library(doBy)
X <- LE_matrix(m0, effect = "trt")
rownames(X) <- levels(td$trt)
Xc <- apc(X)
g <- summary(glht(m0, linfct = Xc),
test = adjusted(type = "fdr"))
res <- data.frame(trt = levels(td$trt),
mean = X %*% coef(m0))
let <- cld2(g)
res$cld2 <- let$mcletters$Letters
res[order(res$mean, decreasing = TRUE), ]
res$let2 <- ordered_cld(res$cld2, res$mean)
res[order(res$mean, decreasing = TRUE), ]
## Not run:
library(latticeExtra)
library(grid)
ci <- as.data.frame(
confint(glht(m0, linfct = X),
calpha = univariate_calpha())$confint)
ci <- cbind(res, ci)
segplot(reorder(trt, Estimate) ~ lwr + upr,
centers = Estimate,
data = ci,
draw = FALSE,
cld = ci$let2,
par.settings = list(layout.widths = list(right.padding = 7))) +
layer(panel.text(x = centers,
y = z,
labels = sprintf("%0.2f %s",
centers,
cld),
pos = 3))
ocld <- with(ci[order(ci$Estimate), ],
ordered_cld(cld2, Estimate))
x <- attr(ocld, "ind")
index <- which(x, arr.ind = TRUE)
trellis.focus("panel", column = 1, row = 1, clip.off = TRUE)
xcor <- 1.03 + (index[, 2] - 1)/50
grid.segments(x0 = unit(xcor, "npc"),
x1 = unit(xcor, "npc"),
y0 = unit(index[, 1] + 0.5, units = "native"),
y1 = unit(index[, 1] - 0.5, units = "native"),
gp = gpar(lwd = 2, col = "blue"))
trellis.unfocus()
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.