-1

To visualise significant differences with letters there is a plotting function in the multcomp package:

library(multcomp)
tuk <- glht(model, linfct = mcp(effect = "Tukey"))
plot(cld(tuk))

How are the boxes calculated (i.e. upper and lower quartiles and whiskers)? I could not find any information about that in the documentation.

erc
  • 10,113
  • 11
  • 57
  • 88

2 Answers2

1

This is basically just a regular boxplot. For instance with the warpbreaks data:

# load data
data(warpbreaks)
# model 
amod <- aov(breaks ~ tension, data = warpbreaks)
tuk <- glht(amod, linfct = mcp(tension = "Tukey"))
# plot
plot(cld(tuk))

This is pretty much the same as

boxplot(breaks ~ tension, data = warpbreaks)
# OR
boxplot(split(warpbreaks$breaks, warpbreaks$tension))

boxplot uses boxplot.stats, which uses stats.fivenum to calculate the necessary statistics. Notice that this differs slightly from the quantile function with probs=c(0,.25, .5, .75, 1) and na.rm=TRUE. In its simplest form (no NA's, length>0), fivenum looks like this:

fivenum <- function (x) 
{
  x <- sort(x)
  n <- length(x)
  n4 <- floor((n + 3)/2)/2
  d <- c(1, n4, (n + 1)/2, n + 1 - n4, n)
  0.5 * (x[floor(d)] + x[ceiling(d)])
}
shadow
  • 21,823
  • 4
  • 63
  • 77
  • Ah sure, thanks! I was majorly confused because it looked different from my ggplot2 version and couldn't figure out why but now I remember that hinges are calculated differently so it all makes sense ;) – erc Aug 18 '14 at 12:58
0

Have a look at the code:

plot.cld() calls boxplot(), therefore the information you're looking for can be found in ?boxplot.stats.

EDi
  • 13,160
  • 2
  • 48
  • 57
  • Thanks, what I don't get though is how to manually calculate the hinges from my `lmer` output, it's clear that the median in the boxplot is the estimate but how do I calculate quartiles for that? – erc Aug 18 '14 at 11:57