TukeyHSD() requires use of aov(). Since this is a hindrance for beginners, wrappers have been provided to remove this need.

# S3 method for lm
TukeyHSD(x, which, ordered = FALSE, conf.level = 0.95, ...)

# S3 method for formula
TukeyHSD(
  x,
  which,
  ordered = FALSE,
  conf.level = 0.95,
  data = parent.frame(),
  ...
)

Arguments

x

an object, for example of class lm or formula

which, ordered, conf.level, ...

just as in TukeyHSD() from the base package

data

a data frame. NB: This does not come second in the argument list.

Examples

## These should all give the same results
if (require(mosaicData)) {
  model <- lm(age ~ substance, data=HELPrct)
  TukeyHSD(model)
  TukeyHSD( age ~ substance, data=HELPrct)
  TukeyHSD(aov(age ~ substance, data=HELPrct))
}
#>   Tukey multiple comparisons of means
#>     95% family-wise confidence level
#> 
#> Fit: aov(formula = age ~ substance, data = HELPrct)
#> 
#> $substance
#>                      diff       lwr       upr     p adj
#> cocaine-alcohol -3.704319 -5.639202 -1.769436 0.0000255
#> heroin-alcohol  -4.754192 -6.803234 -2.705149 0.0000002
#> heroin-cocaine  -1.049873 -3.167195  1.067450 0.4741712
#>