warp.lm <- lm(breaks ~ wool*tension, data = warpbreaks)
warp.emm <- emmeans(warp.lm, ~ tension | wool)
contrast(warp.emm, "poly")
contrast(warp.emm, "trt.vs.ctrl", ref = "M")
if (FALSE) {
## Same when enhanced labeling is used:
contrast(warp.emm, "trt.vs.ctrl",
enhance.levels = "tension", ref = "tensionM")}
# Comparisons with grand mean
contrast(warp.emm, "eff")
# Comparisons with a weighted grand mean
contrast(warp.emm, "eff", wts = c(2, 5, 3))
# Compare only low and high tensions
# Note pairs(emm, ...) calls contrast(emm, "pairwise", ...)
pairs(warp.emm, exclude = 2)
# (same results using exclude = "M" or include = c("L","H") or include = c(1,3))
# Same contrasts as above but with normalized contrast coefficients
contrast(warp.emm, "nrmlz", family = "pairwise", include = c(1, 3))
### Setting up a custom contrast function
revhelmert.emmc <- function(levs, ...) {
M <- as.data.frame(contr.helmert(levs)[rev(seq_along(levs)), ])
names(M) <- paste(rev(levs)[-1],"vs later")
attr(M, "desc") <- "reverse Helmert contrasts"
M
}
contrast(warp.emm, "revhelmert")
if (FALSE) {
# See what is used for polynomial contrasts with 6 levels
emmeans:::poly.emmc(1:6)
}
Run the code above in your browser using DataLab